aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/google_docs/GooglePhotosClientUtils.ts
diff options
context:
space:
mode:
authorSam Wilkins <samwilkins333@gmail.com>2019-09-08 04:16:04 -0400
committerSam Wilkins <samwilkins333@gmail.com>2019-09-08 04:16:04 -0400
commitf18e2265e5d468f1cbf6e82dd5f01d5f5216b851 (patch)
treeb87db39dc7fa524100f712fbb87429c8d04abed3 /src/client/apis/google_docs/GooglePhotosClientUtils.ts
parentc24f5f29dff8dd22f1d4029a2722ee4d1a725aad (diff)
factored out collection creation, sharp() resizers and image management
Diffstat (limited to 'src/client/apis/google_docs/GooglePhotosClientUtils.ts')
-rw-r--r--src/client/apis/google_docs/GooglePhotosClientUtils.ts27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
index bb5d23971..5f5b39b14 100644
--- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts
+++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
@@ -1,16 +1,16 @@
import { PostToServer, Utils } from "../../../Utils";
import { RouteStore } from "../../../server/RouteStore";
import { ImageField } from "../../../new_fields/URLField";
-import { StrCast, Cast } from "../../../new_fields/Types";
+import { Cast } from "../../../new_fields/Types";
import { Doc, Opt } from "../../../new_fields/Doc";
import { Id } from "../../../new_fields/FieldSymbols";
-import requestImageSize = require('../../util/request-image-size');
import Photos = require('googlephotos');
import { RichTextField } from "../../../new_fields/RichTextField";
import { RichTextUtils } from "../../../new_fields/RichTextUtils";
import { EditorState } from "prosemirror-state";
import { FormattedTextBox } from "../../views/nodes/FormattedTextBox";
-import { Docs } from "../../documents/Documents";
+import { Docs, DocumentOptions } from "../../documents/Documents";
+import { type } from "os";
export namespace GooglePhotosClientUtils {
@@ -98,7 +98,7 @@ export namespace GooglePhotosClientUtils {
excluded: [],
date: undefined,
includeArchivedMedia: true,
- type: MediaType.ALL_MEDIA
+ type: MediaType.ALL_MEDIA,
};
export interface SearchResponse {
@@ -106,7 +106,18 @@ export namespace GooglePhotosClientUtils {
nextPageToken: string;
}
- export const Search = async (requested: Opt<Partial<SearchOptions>>) => {
+ export type CollectionConstructor = (data: Array<Doc>, options: DocumentOptions, ...args: any) => Doc;
+ export const CollectionFromSearch = async (provider: CollectionConstructor, requested: Opt<Partial<SearchOptions>>): Promise<Doc> => {
+ let downloads = await Search(requested);
+ return provider(downloads.map((download: any) => {
+ let document = Docs.Create.ImageDocument(Utils.prepend(`/files/${download.fileNames.clean}`));
+ document.fillColumn = true;
+ document.contentSize = download.contentSize;
+ return document;
+ }), { width: 500, height: 500 });
+ };
+
+ export const Search = async (requested: Opt<Partial<SearchOptions>>): Promise<any> => {
const options = requested || DefaultSearchOptions;
const photos = await endpoint();
const filters = new photos.Filters(options.includeArchivedMedia === undefined ? true : options.includeArchivedMedia);
@@ -133,11 +144,7 @@ export namespace GooglePhotosClientUtils {
return new Promise<Doc>(resolve => {
photos.mediaItems.search(filters, options.pageSize || 20).then(async (response: SearchResponse) => {
- response && resolve(Docs.Create.StackingDocument((await PostToServer(RouteStore.googlePhotosMediaDownload, response)).map((download: any) => {
- let document = Docs.Create.ImageDocument(Utils.prepend(`/files/${download.fileName}`));
- document.contentSize = download.contentSize;
- return document;
- }), { width: 500, height: 500 }));
+ response && resolve(await PostToServer(RouteStore.googlePhotosMediaDownload, response));
});
});
};