aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/apis/google/GooglePhotosUploadUtils.ts12
-rw-r--r--src/server/index.ts4
2 files changed, 7 insertions, 9 deletions
diff --git a/src/server/apis/google/GooglePhotosUploadUtils.ts b/src/server/apis/google/GooglePhotosUploadUtils.ts
index a98399621..d8cf795b5 100644
--- a/src/server/apis/google/GooglePhotosUploadUtils.ts
+++ b/src/server/apis/google/GooglePhotosUploadUtils.ts
@@ -100,12 +100,12 @@ export namespace GooglePhotosUploadUtils {
* @param album if included, will add all of the newly created remote images to the album
* with the specified id
*/
- export const CreateMediaItems = async (bearerToken: string, newMediaItems: NewMediaItem[], album?: { id: string }): Promise<MediaItemCreationResult> => {
+ export const CreateMediaItems = async (bearerToken: string, newMediaItems: NewMediaItem[], album?: { id: string }): Promise<NewMediaItemResult[]> => {
// it's important to note that the API can't handle more than 50 items in each request and
// seems to need at least some latency between requests (spamming it synchronously has led to the server returning errors)...
const batched = BatchedArray.from(newMediaItems, { batchSize: 50 });
// ...so we execute them in delayed batches and await the entire execution
- const newMediaItemResults = await batched.batchedMapPatientInterval<NewMediaItemResult>(
+ return batched.batchedMapPatientInterval(
{ magnitude: 100, unit: TimeUnit.Milliseconds },
async (batch: NewMediaItem[], collector) => {
const parameters = {
@@ -117,19 +117,17 @@ export namespace GooglePhotosUploadUtils {
};
// register the target album, if provided
album && (parameters.body.albumId = album.id);
- const { newMediaItemResults } = await new Promise<MediaItemCreationResult>((resolve, reject) => {
+ collector.push(...(await new Promise<NewMediaItemResult[]>((resolve, reject) => {
request(parameters, (error, _response, body) => {
if (error) {
reject(error);
} else {
- resolve(body);
+ resolve(body.newMediaItemResults);
}
});
- });
- collector.push(...newMediaItemResults);
+ })));
}
);
- return { newMediaItemResults };
};
} \ No newline at end of file
diff --git a/src/server/index.ts b/src/server/index.ts
index 9f3e34761..25697e71f 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -650,11 +650,11 @@ function routeSetter(router: RouteManager) {
const failedCount = failed.length;
if (failedCount) {
console.error(`Unable to upload ${failedCount} image${failedCount === 1 ? "" : "s"} to Google's servers`);
- console.log(failed.map(({ reason, batch, index, url }) => `@${batch}.${index}: ${url} failed: ${reason}`).join('\n'));
+ console.log(failed.map(({ reason, batch, index, url }) => `@${batch}.${index}: ${url} failed:\n${reason}`).join('\n\n'));
}
return GooglePhotosUploadUtils.CreateMediaItems(token, newMediaItems, req.body.album).then(
- result => _success(res, { results: result.newMediaItemResults, failed }),
+ results => _success(res, { results, failed }),
error => _error(res, mediaError, error)
);
}