aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-09-01 17:12:45 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-09-01 17:12:45 -0400
commitd1960ed915e78014592567e16dd1de9545781a27 (patch)
treeb53ed90769f116790a7a07be7bc09347dea06c93
parent769b4c0b9ac61729b94b32999d3713a2dce53627 (diff)
factored out typings
-rw-r--r--src/server/apis/google/GoogleApiServerUtils.ts7
-rw-r--r--src/server/apis/google/GooglePhotosUtils.ts152
-rw-r--r--src/server/apis/google/typings/albums.ts148
3 files changed, 156 insertions, 151 deletions
diff --git a/src/server/apis/google/GoogleApiServerUtils.ts b/src/server/apis/google/GoogleApiServerUtils.ts
index 656984b8a..c6d901577 100644
--- a/src/server/apis/google/GoogleApiServerUtils.ts
+++ b/src/server/apis/google/GoogleApiServerUtils.ts
@@ -5,8 +5,9 @@ import { OAuth2Client, Credentials } from "google-auth-library";
import { Opt } from "../../../new_fields/Doc";
import { GlobalOptions } from "googleapis-common";
import { GaxiosResponse } from "gaxios";
-import { GooglePhotos, CreateAlbum, Action } from "./GooglePhotosUtils";
+import { GooglePhotos } from "./GooglePhotosUtils";
import { Utils } from "../../../Utils";
+import { Album } from "./Typings/albums";
/**
* Server side authentication for Google Api queries.
@@ -67,8 +68,8 @@ export namespace GoogleApiServerUtils {
case Service.Photos:
let token = result.token.access_token;
if (token) {
- let create: CreateAlbum = {
- action: Action.Create,
+ let create: Album.Create = {
+ action: Album.Action.Create,
body: {
album: {
title: "Sam's Bulk Export",
diff --git a/src/server/apis/google/GooglePhotosUtils.ts b/src/server/apis/google/GooglePhotosUtils.ts
index 439a41cb6..d4f16fd5d 100644
--- a/src/server/apis/google/GooglePhotosUtils.ts
+++ b/src/server/apis/google/GooglePhotosUtils.ts
@@ -1,157 +1,13 @@
import request = require('request-promise');
+import { Album } from './Typings/albums';
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) => {
+ export type Query = Album.Query;
+
+ export const ExecuteQuery = async (authToken: string, query: GooglePhotos.Query) => {
let options = {
headers: { 'Content-Type': 'application/json' },
auth: { 'bearer': authToken },
diff --git a/src/server/apis/google/typings/albums.ts b/src/server/apis/google/typings/albums.ts
new file mode 100644
index 000000000..1c9b379fe
--- /dev/null
+++ b/src/server/apis/google/typings/albums.ts
@@ -0,0 +1,148 @@
+export namespace Album {
+
+ export type Query = (AddEnrichment | BatchAddMediaItems | BatchRemoveMediaItems | Create | Get | List | Share | Unshare) & { 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 Create {
+ action: Action.Create;
+ body: {
+ album: Template;
+ };
+ }
+
+ export interface Get {
+ action: Action.Get;
+ albumId: string;
+ }
+
+ export interface List {
+ action: Action.List;
+ parameters: {
+ pageSize: number,
+ pageToken: string,
+ excludeNonAppCreatedData: boolean
+ };
+ }
+
+ export interface Share {
+ action: Action.Share;
+ albumId: string;
+ body: {
+ sharedAlbumOptions: SharedOptions;
+ };
+ }
+
+ export interface Unshare {
+ action: Action.Unshare;
+ albumId: string;
+ }
+
+ export interface Template {
+ title: string;
+ }
+
+ export interface Model {
+ id: string;
+ title: string;
+ productUrl: string;
+ isWriteable: boolean;
+ shareInfo: ShareInfo;
+ mediaItemsCount: string;
+ coverPhotoBaseUrl: string;
+ coverPhotoMediaItemId: string;
+ }
+
+ export interface ShareInfo {
+ sharedAlbumOptions: SharedOptions;
+ shareableUrl: string;
+ shareToken: string;
+ isJoined: boolean;
+ isOwned: boolean;
+ }
+
+ export interface SharedOptions {
+ isCollaborative: boolean;
+ isCommentable: boolean;
+ }
+
+ export enum PositionType {
+ POSITION_TYPE_UNSPECIFIED,
+ FIRST_IN_ALBUM,
+ LAST_IN_ALBUM,
+ AFTER_MEDIA_ITEM,
+ AFTER_ENRICHMENT_ITEM
+ }
+
+ export type Position = 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 }
+ };
+ }
+
+} \ No newline at end of file