aboutsummaryrefslogtreecommitdiff
path: root/src/server/apis
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-09-01 17:02:11 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-09-01 17:02:11 -0400
commit769b4c0b9ac61729b94b32999d3713a2dce53627 (patch)
tree1b2d63af57cd2a35546defac0a268aa28b20977b /src/server/apis
parentb8a6b72938804902a7e4478cde9c50339341f67d (diff)
added typings for google photo album manipulations
Diffstat (limited to 'src/server/apis')
-rw-r--r--src/server/apis/google/GoogleApiServerUtils.ts17
-rw-r--r--src/server/apis/google/GooglePhotosUtils.ts177
2 files changed, 179 insertions, 15 deletions
diff --git a/src/server/apis/google/GoogleApiServerUtils.ts b/src/server/apis/google/GoogleApiServerUtils.ts
index bc9ae2726..656984b8a 100644
--- a/src/server/apis/google/GoogleApiServerUtils.ts
+++ b/src/server/apis/google/GoogleApiServerUtils.ts
@@ -5,7 +5,8 @@ import { OAuth2Client, Credentials } from "google-auth-library";
import { Opt } from "../../../new_fields/Doc";
import { GlobalOptions } from "googleapis-common";
import { GaxiosResponse } from "gaxios";
-import Photos = require("googlephotos");
+import { GooglePhotos, CreateAlbum, Action } from "./GooglePhotosUtils";
+import { Utils } from "../../../Utils";
/**
* Server side authentication for Google Api queries.
@@ -64,8 +65,18 @@ export namespace GoogleApiServerUtils {
routed = google.slides(parameters).presentations;
break;
case Service.Photos:
- const photos = new Photos(result.token.access_token);
- console.log(await photos.albums.list());
+ let token = result.token.access_token;
+ if (token) {
+ let create: CreateAlbum = {
+ action: Action.Create,
+ body: {
+ album: {
+ title: "Sam's Bulk Export",
+ }
+ }
+ };
+ console.log(await GooglePhotos.ExecuteQuery(token, create));
+ }
}
resolve(routed);
});
diff --git a/src/server/apis/google/GooglePhotosUtils.ts b/src/server/apis/google/GooglePhotosUtils.ts
index 7f9ffb6f3..439a41cb6 100644
--- a/src/server/apis/google/GooglePhotosUtils.ts
+++ b/src/server/apis/google/GooglePhotosUtils.ts
@@ -1,12 +1,165 @@
-// import request = require('request-promise');
-// const key = require("../../credentials/auth.json");
-
-// export const PhotosLibraryQuery = async (authToken: any, parameters: any) => {
-// let options = {
-// headers: { 'Content-Type': 'application/json' },
-// json: parameters,
-// auth: { 'bearer': authToken },
-// };
-// const result = await request.post(config.apiEndpoint + '/v1/mediaItems:search', options);
-// return result;
-// }; \ No newline at end of file
+import request = require('request-promise');
+
+const apiEndpoint = "https://photoslibrary.googleapis.com";
+
+export type GooglePhotosQuery = AlbumsQuery;
+
+export type AlbumsQuery = (AddEnrichment | BatchAddMediaItems | BatchRemoveMediaItems | CreateAlbum | GetAlbum | ListAlbum | ShareAlbum | UnshareAlbum) & { body: any };
+
+export enum Action {
+ AddEnrichment,
+ BatchAddMediaItems,
+ BatchRemoveMediaItems,
+ Create,
+ Get,
+ List,
+ Share,
+ Unshare
+}
+
+export interface AddEnrichment {
+ action: Action.AddEnrichment;
+ albumId: string;
+ body: {
+ newEnrichmentItem: NewEnrichmentItem;
+ albumPosition: MediaRelativeAlbumPosition;
+ };
+}
+
+export interface BatchAddMediaItems {
+ action: Action.BatchAddMediaItems;
+ albumId: string;
+ body: {
+ mediaItemIds: string[];
+ };
+}
+
+export interface BatchRemoveMediaItems {
+ action: Action.BatchRemoveMediaItems;
+ albumId: string;
+ body: {
+ mediaItemIds: string[];
+ };
+}
+
+export interface CreateAlbum {
+ action: Action.Create;
+ body: {
+ album: AlbumTemplate;
+ };
+}
+
+export interface GetAlbum {
+ action: Action.Get;
+ albumId: string;
+}
+
+export interface ListAlbum {
+ action: Action.List;
+ parameters: {
+ pageSize: number,
+ pageToken: string,
+ excludeNonAppCreatedData: boolean
+ };
+}
+
+export interface ShareAlbum {
+ action: Action.Share;
+ albumId: string;
+ body: {
+ sharedAlbumOptions: SharedAlbumOptions;
+ };
+}
+
+export interface UnshareAlbum {
+ action: Action.Unshare;
+ albumId: string;
+}
+
+export interface AlbumTemplate {
+ title: string;
+}
+
+export interface Album {
+ id: string;
+ title: string;
+ productUrl: string;
+ isWriteable: boolean;
+ shareInfo: ShareInfo;
+ mediaItemsCount: string;
+ coverPhotoBaseUrl: string;
+ coverPhotoMediaItemId: string;
+}
+
+export interface ShareInfo {
+ sharedAlbumOptions: SharedAlbumOptions;
+ shareableUrl: string;
+ shareToken: string;
+ isJoined: boolean;
+ isOwned: boolean;
+}
+
+export interface SharedAlbumOptions {
+ isCollaborative: boolean;
+ isCommentable: boolean;
+}
+
+export enum PositionType {
+ POSITION_TYPE_UNSPECIFIED,
+ FIRST_IN_ALBUM,
+ LAST_IN_ALBUM,
+ AFTER_MEDIA_ITEM,
+ AFTER_ENRICHMENT_ITEM
+}
+
+export type AlbumPosition = GeneralAlbumPosition | MediaRelativeAlbumPosition | EnrichmentRelativeAlbumPosition;
+
+interface GeneralAlbumPosition {
+ position: PositionType.FIRST_IN_ALBUM | PositionType.LAST_IN_ALBUM | PositionType.POSITION_TYPE_UNSPECIFIED;
+}
+
+interface MediaRelativeAlbumPosition {
+ position: PositionType.AFTER_MEDIA_ITEM;
+ relativeMediaItemId: string;
+}
+
+interface EnrichmentRelativeAlbumPosition {
+ position: PositionType.AFTER_ENRICHMENT_ITEM;
+ relativeEnrichmentItemId: string;
+}
+
+export interface Location {
+ locationName: string;
+ latlng: {
+ latitude: number,
+ longitude: number
+ };
+}
+
+export interface NewEnrichmentItem {
+ textEnrichment: {
+ text: string;
+ };
+ locationEnrichment: {
+ location: Location
+ };
+ mapEnrichment: {
+ origin: { location: Location },
+ destination: { location: Location }
+ };
+}
+
+export namespace GooglePhotos {
+
+ export const ExecuteQuery = async (authToken: string, query: AlbumsQuery) => {
+ let options = {
+ headers: { 'Content-Type': 'application/json' },
+ auth: { 'bearer': authToken },
+ body: query.body,
+ json: true
+ };
+ const result = await request.post(apiEndpoint + '/v1/albums', options);
+ return result;
+ };
+
+}