diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2019-09-11 16:43:42 -0400 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-09-11 16:43:42 -0400 |
commit | 0de9ddac733feb84f857d7c381e27dd196c7f191 (patch) | |
tree | 8534e3a4473b4e9563a1559eee2d14ff820ad99f /src/client/apis/google_docs/GooglePhotosClientUtils.ts | |
parent | 15c3a0fac7795ed07bd282571c477655d5f24327 (diff) |
remove none tag if others are present
Diffstat (limited to 'src/client/apis/google_docs/GooglePhotosClientUtils.ts')
-rw-r--r-- | src/client/apis/google_docs/GooglePhotosClientUtils.ts | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/src/client/apis/google_docs/GooglePhotosClientUtils.ts b/src/client/apis/google_docs/GooglePhotosClientUtils.ts index a28b183d1..ff254a770 100644 --- a/src/client/apis/google_docs/GooglePhotosClientUtils.ts +++ b/src/client/apis/google_docs/GooglePhotosClientUtils.ts @@ -140,27 +140,32 @@ export namespace GooglePhotos { throw new Error("Appending image metadata requires that the targeted collection have already been mapped to an album!"); } const images = await DocListCastAsync(collection.data); - images && images.forEach(image => image.googlePhotosTags = new List()); + images && images.forEach(image => image.googlePhotosTags = new List([ContentCategories.NONE])); const values = Object.values(ContentCategories); for (let value of values) { - console.log("Searching for ", value); - const results = await Search({ included: [value] }); - if (results.mediaItems) { - console.log(`${results.mediaItems.length} found!`); - const ids = results.mediaItems.map(item => item.id); - for (let id of ids) { - const image = await Cast(idMapping[id], Doc); - if (image) { - const tags = Cast(image.googlePhotosTags, listSpec("string"))!; - if (!tags.includes(value)) { - tags.push(value); - console.log(`${value}: ${id}`); + if (value !== ContentCategories.NONE) { + const results = await Search({ included: [value] }); + if (results.mediaItems) { + const ids = results.mediaItems.map(item => item.id); + for (let id of ids) { + const image = await Cast(idMapping[id], Doc); + if (image) { + const tags = Cast(image.googlePhotosTags, listSpec("string"))!; + if (!tags.includes(value)) { + tags.push(value); + } } } } } - console.log(); } + images && images.forEach(image => { + const tags = Cast(image.googlePhotosTags, listSpec("string"))!; + if (tags.includes(ContentCategories.NONE) && tags.length > 1) { + image.googlePhotosTags = new List(tags.splice(tags.indexOf(ContentCategories.NONE), 1)); + } + }); + }; interface DateRange { |