diff options
author | bob <bcz@cs.brown.edu> | 2019-11-06 12:38:11 -0500 |
---|---|---|
committer | bob <bcz@cs.brown.edu> | 2019-11-06 12:38:11 -0500 |
commit | 11e2a3ca056ca519227755b3c9cd80d354302aa5 (patch) | |
tree | 4c2afc8b9540c5905b2490d4da01a26fc05c6f52 | |
parent | f83205e4ea3486ebeeaa52918650bf6521c36cb9 (diff) |
from last
-rw-r--r-- | src/server/index.ts | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/src/server/index.ts b/src/server/index.ts index c6753a253..1595781dc 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -1049,42 +1049,34 @@ addSecureRoute({ let failed: number[] = []; - // bcz: this doesn't compile: - // Using ts-node version 7.0.1, typescript version 3.5.3 - // [ERROR] 09:54:48 тип Unable to compile TypeScript: - // src/server/index.ts(1055,13): error TS2345: Argument of type '(batch: MediaInput[], collector: BatchContext) => Promise<void>' is not assignable to parameter of type 'BatchFunction<MediaInput, NewMediaItem[] | Promise<NewMediaItem[]>>'. - // Type 'Promise<void>' is not assignable to type 'NewMediaItem[] | Promise<NewMediaItem[]>'. - // Type 'Promise<void>' is not assignable to type 'Promise<NewMediaItem[]>'. - // Type 'void' is not assignable to type 'NewMediaItem[]'. - // src/server/index.ts(1062,35): error TS2339: Property 'push' does not exist on type 'BatchContext'. - // const batched = BatchedArray.from<GooglePhotosUploadUtils.MediaInput>(media, { batchSize: 25 }); - // const newMediaItems = await batched.batchedMapPatientInterval<NewMediaItem>( - // { magnitude: 100, unit: TimeUnit.Milliseconds }, - // async (batch, collector) => { - // for (let index = 0; index < batch.length; index++) { - // const { url, description } = batch[index]; - // const uploadToken = await GooglePhotosUploadUtils.DispatchGooglePhotosUpload(url); - // if (!uploadToken) { - // failed.push(index); - // } else { - // collector.push({ - // description, - // simpleMediaItem: { uploadToken } - // }); - // } - // } - // } - // ); - - // const failedCount = failed.length; - // if (failedCount) { - // console.error(`Unable to upload ${failedCount} image${failedCount === 1 ? "" : "s"} to Google's servers`); - // } - - // GooglePhotosUploadUtils.CreateMediaItems(newMediaItems, req.body.album).then( - // results => _success(res, { results, failed }), - // error => _error(res, mediaError, error) - // ); + const batched = BatchedArray.from<GooglePhotosUploadUtils.MediaInput>(media, { batchSize: 25 }); + const newMediaItems = await batched.batchedMapPatientInterval<NewMediaItem>( + { magnitude: 100, unit: TimeUnit.Milliseconds }, + async (batch, collector) => { + for (let index = 0; index < batch.length; index++) { + const { url, description } = batch[index]; + const uploadToken = await GooglePhotosUploadUtils.DispatchGooglePhotosUpload(url); + if (!uploadToken) { + failed.push(index); + } else { + collector.push({ + description, + simpleMediaItem: { uploadToken } + }); + } + } + } + ); + + const failedCount = failed.length; + if (failedCount) { + console.error(`Unable to upload ${failedCount} image${failedCount === 1 ? "" : "s"} to Google's servers`); + } + + GooglePhotosUploadUtils.CreateMediaItems(newMediaItems, req.body.album).then( + results => _success(res, { results, failed }), + error => _error(res, mediaError, error) + ); } }); |