diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2019-09-20 16:39:14 -0400 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-09-20 16:39:14 -0400 |
commit | 8d9c9d0f51be91ee10b631be9f464af0822bb9be (patch) | |
tree | 00bc3798f03be1531dea457184844bcc09290871 /src/client/util/Import & Export/DirectoryImportBox.tsx | |
parent | d66b51213e448d5f4f37781389af488a3ac744c4 (diff) |
integrated with array batcher npm module
Diffstat (limited to 'src/client/util/Import & Export/DirectoryImportBox.tsx')
-rw-r--r-- | src/client/util/Import & Export/DirectoryImportBox.tsx | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/src/client/util/Import & Export/DirectoryImportBox.tsx b/src/client/util/Import & Export/DirectoryImportBox.tsx index 762302bc8..26a00dc7c 100644 --- a/src/client/util/Import & Export/DirectoryImportBox.tsx +++ b/src/client/util/Import & Export/DirectoryImportBox.tsx @@ -20,7 +20,7 @@ import { listSpec } from "../../../new_fields/Schema"; import { GooglePhotos } from "../../apis/google_docs/GooglePhotosClientUtils"; import { SchemaHeaderField } from "../../../new_fields/SchemaHeaderField"; import "./DirectoryImportBox.scss"; -import { batchedMapAsync } from "array-batcher"; +import BatchedArray from "array-batcher"; const unsupported = ["text/html", "text/plain"]; interface FileResponse { @@ -104,19 +104,22 @@ export default class DirectoryImportBox extends React.Component<FieldViewProps> runInAction(() => this.phase = `Internal: uploading ${this.quota - this.completed} files to Dash...`); - const uploads = await batchedMapAsync(validated, { batchSize: 15 }, async batch => { - const formData = new FormData(); - const parameters = { method: 'POST', body: formData }; - - batch.forEach(file => { - sizes.push(file.size); - modifiedDates.push(file.lastModified); - formData.append(Utils.GenerateGuid(), file); - }); - - const responses = await (await fetch(RouteStore.upload, parameters)).json(); - runInAction(() => this.completed += batch.length); - return responses as FileResponse[]; + const uploads = await BatchedArray.from(validated).batchedMapAsync({ + batcher: { batchSize: 15 }, + converter: async batch => { + const formData = new FormData(); + const parameters = { method: 'POST', body: formData }; + + batch.forEach(file => { + sizes.push(file.size); + modifiedDates.push(file.lastModified); + formData.append(Utils.GenerateGuid(), file); + }); + + const responses = await (await fetch(RouteStore.upload, parameters)).json(); + runInAction(() => this.completed += batch.length); + return responses as FileResponse[]; + } }); await Promise.all(uploads.map(async upload => { |