aboutsummaryrefslogtreecommitdiff
path: root/src/client/apis/google_docs
diff options
context:
space:
mode:
authorAndy Rickert <andrew_rickert@brown.edu>2020-05-12 17:37:54 -0700
committerAndy Rickert <andrew_rickert@brown.edu>2020-05-12 17:37:54 -0700
commit9ad062907d38a7a853ba89fa31433380ae3cd7b3 (patch)
tree707855e1bc6fa8ac3d1f51447815a51eb83b8aa3 /src/client/apis/google_docs
parent1848c78f889470d6c558f709efe1b521402b2793 (diff)
parent4bd011dcc6a3f009fa10932c7c6ca1932b784fde (diff)
merge
Diffstat (limited to 'src/client/apis/google_docs')
-rw-r--r--src/client/apis/google_docs/GoogleApiClientUtils.ts2
-rw-r--r--src/client/apis/google_docs/GooglePhotosClientUtils.ts33
2 files changed, 14 insertions, 21 deletions
diff --git a/src/client/apis/google_docs/GoogleApiClientUtils.ts b/src/client/apis/google_docs/GoogleApiClientUtils.ts
index fa67ddbef..2f3cac8d3 100644
--- a/src/client/apis/google_docs/GoogleApiClientUtils.ts
+++ b/src/client/apis/google_docs/GoogleApiClientUtils.ts
@@ -95,7 +95,7 @@ export namespace GoogleApiClientUtils {
export type ExtractResult = { text: string, paragraphs: DeconstructedParagraph[] };
export const extractText = (document: docs_v1.Schema$Document, removeNewlines = false): ExtractResult => {
const paragraphs = extractParagraphs(document);
- let text = paragraphs.map(paragraph => paragraph.contents.filter(content => !("inlineObjectId" in content)).map(run => run as docs_v1.Schema$TextRun).join("")).join("");
+ let text = paragraphs.map(paragraph => paragraph.contents.filter(content => !("inlineObjectId" in content)).map(run => (run as docs_v1.Schema$TextRun).content).join("")).join("");
text = text.substring(0, text.length - 1);
removeNewlines && text.replace(/\n/g, "");
return { text, paragraphs };
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
index e3f801c46..1e4c120bc 100644
--- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts
+++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts
@@ -76,7 +76,6 @@ export namespace GooglePhotos {
}
export const CollectionToAlbum = async (options: AlbumCreationOptions): Promise<Opt<AlbumCreationResult>> => {
- await GoogleAuthenticationManager.Instance.fetchOrGenerateAccessToken();
const { collection, title, descriptionKey, tag } = options;
const dataDocument = Doc.GetProto(collection);
const images = ((await DocListCastAsync(dataDocument.data)) || []).filter(doc => Cast(doc.data, ImageField));
@@ -154,27 +153,22 @@ export namespace GooglePhotos {
}
const tagMapping = new Map<string, string>();
const images = (await DocListCastAsync(collection.data))!.map(Doc.GetProto);
- images && images.forEach(image => tagMapping.set(image[Id], ContentCategories.NONE));
- const values = Object.values(ContentCategories);
+ images?.forEach(image => tagMapping.set(image[Id], ContentCategories.NONE));
+ const values = Object.values(ContentCategories).filter(value => value !== ContentCategories.NONE);
for (const value of values) {
- if (value !== ContentCategories.NONE) {
- const results = await ContentSearch({ included: [value] });
- if (results.mediaItems) {
- const ids = results.mediaItems.map(item => item.id);
- for (const id of ids) {
- const image = await Cast(idMapping[id], Doc);
- if (image) {
- const key = image[Id];
- const tags = tagMapping.get(key)!;
- if (!tags.includes(value)) {
- tagMapping.set(key, tags + delimiter + value);
- }
- }
- }
+ const searched = (await ContentSearch({ included: [value] }))?.mediaItems?.map(({ id }) => id);
+ console.log("Searching " + value);
+ console.log(searched);
+ searched?.forEach(async id => {
+ const image = await Cast(idMapping[id], Doc);
+ if (image) {
+ const key = image[Id];
+ const tags = tagMapping.get(key);
+ !tags?.includes(value) && tagMapping.set(key, tags + delimiter + value);
}
- }
+ });
}
- images && images.forEach(image => {
+ images?.forEach(image => {
const concatenated = tagMapping.get(image[Id])!;
const tags = concatenated.split(delimiter);
if (tags.length > 1) {
@@ -184,7 +178,6 @@ export namespace GooglePhotos {
image.googlePhotosTags = ContentCategories.NONE;
}
});
-
};
interface DateRange {