diff options
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/client/util/Import & Export/DirectoryImportBox.tsx | 3 | ||||
-rw-r--r-- | src/server/DashUploadUtils.ts | 4 | ||||
-rw-r--r-- | src/server/apis/google/GooglePhotosUploadUtils.ts | 8 | ||||
-rw-r--r-- | src/server/index.ts | 8 |
5 files changed, 13 insertions, 12 deletions
diff --git a/package.json b/package.json index ea31b08a3..7a9e29f50 100644 --- a/package.json +++ b/package.json @@ -114,7 +114,7 @@ "@types/youtube": "0.0.38", "adm-zip": "^0.4.13", "archiver": "^3.0.3", - "array-batcher": "^1.0.7", + "array-batcher": "^1.1.3", "async": "^2.6.2", "babel-runtime": "^6.26.0", "bcrypt-nodejs": "0.0.3", diff --git a/src/client/util/Import & Export/DirectoryImportBox.tsx b/src/client/util/Import & Export/DirectoryImportBox.tsx index de5287456..d3f81b992 100644 --- a/src/client/util/Import & Export/DirectoryImportBox.tsx +++ b/src/client/util/Import & Export/DirectoryImportBox.tsx @@ -20,10 +20,11 @@ import { listSpec } from "../../../new_fields/Schema"; import { GooglePhotos } from "../../apis/google_docs/GooglePhotosClientUtils"; import { SchemaHeaderField } from "../../../new_fields/SchemaHeaderField"; import "./DirectoryImportBox.scss"; -import BatchedArray from "array-batcher"; import { Identified } from "../../Network"; +import { BatchedArray } from "array-batcher"; const unsupported = ["text/html", "text/plain"]; + interface FileResponse { name: string; path: string; diff --git a/src/server/DashUploadUtils.ts b/src/server/DashUploadUtils.ts index 04a3559dc..4230e9b17 100644 --- a/src/server/DashUploadUtils.ts +++ b/src/server/DashUploadUtils.ts @@ -50,10 +50,10 @@ export namespace DashUploadUtils { * event that @param filename is not specified * * @returns {UploadInformation} This method returns - * 1) the paths to the uploaded image + * 1) the paths to the uploaded images (plural due to resizing) * 2) the file name of each of the resized images * 3) the size of the image, in bytes (4432130) - * 4) the content type of the image (jpg | png | etc.) + * 4) the content type of the image, i.e. image/(jpeg | png | ...) */ export const UploadImage = async (source: string, filename?: string, prefix: string = ""): Promise<UploadInformation> => { const metadata = await InspectImage(source); diff --git a/src/server/apis/google/GooglePhotosUploadUtils.ts b/src/server/apis/google/GooglePhotosUploadUtils.ts index 507a868a3..16c4f6c3a 100644 --- a/src/server/apis/google/GooglePhotosUploadUtils.ts +++ b/src/server/apis/google/GooglePhotosUploadUtils.ts @@ -3,7 +3,7 @@ import { GoogleApiServerUtils } from './GoogleApiServerUtils'; import * as path from 'path'; import { MediaItemCreationResult } from './SharedTypes'; import { NewMediaItem } from "../../index"; -import BatchedArray, { FixedBatcher, TimeUnit, Interval } from "array-batcher"; +import { BatchedArray, TimeUnit } from 'array-batcher'; export namespace GooglePhotosUploadUtils { @@ -53,7 +53,8 @@ export namespace GooglePhotosUploadUtils { }; export const CreateMediaItems = async (newMediaItems: NewMediaItem[], album?: { id: string }): Promise<MediaItemCreationResult> => { - const newMediaItemResults = await BatchedArray.from(newMediaItems, { batchSize: 50 }).batchedMapInterval( + const newMediaItemResults = await BatchedArray.from(newMediaItems, { batchSize: 50 }).batchedMapPatientInterval( + { magnitude: 100, unit: TimeUnit.Milliseconds }, async (batch: NewMediaItem[]) => { const parameters = { method: 'POST', @@ -72,8 +73,7 @@ export namespace GooglePhotosUploadUtils { } }); })).newMediaItemResults; - }, - { magnitude: 100, unit: TimeUnit.Milliseconds } + } ); return { newMediaItemResults }; }; diff --git a/src/server/index.ts b/src/server/index.ts index 3da726cfa..9a778b88c 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -47,8 +47,8 @@ const mongoose = require('mongoose'); const probe = require("probe-image-size"); import * as qs from 'query-string'; import { Opt } from '../new_fields/Doc'; -import BatchedArray, { TimeUnit } from "array-batcher"; import { DashUploadUtils } from './DashUploadUtils'; +import { BatchedArray, TimeUnit } from 'array-batcher'; const download = (url: string, dest: fs.PathLike) => request.get(url).pipe(fs.createWriteStream(dest)); let youtubeApiKey: string; @@ -848,7 +848,8 @@ app.post(RouteStore.googlePhotosMediaUpload, async (req, res) => { let failed = 0; - const newMediaItems = await BatchedArray.from<GooglePhotosUploadUtils.MediaInput>(media, { batchSize: 25 }).batchedMapInterval( + const newMediaItems = await BatchedArray.from<GooglePhotosUploadUtils.MediaInput>(media, { batchSize: 25 }).batchedMapPatientInterval( + { magnitude: 100, unit: TimeUnit.Milliseconds }, async (batch: GooglePhotosUploadUtils.MediaInput[]) => { const newMediaItems: NewMediaItem[] = []; for (let element of batch) { @@ -863,8 +864,7 @@ app.post(RouteStore.googlePhotosMediaUpload, async (req, res) => { } } return newMediaItems; - }, - { magnitude: 100, unit: TimeUnit.Milliseconds } + } ); if (failed) { |