refactor: Upload file to storage, and then pass attachmentId to collections.import

This avoids having large file uploads going directly to the server and allows us to fetch it async into a worker process
This commit is contained in:
Tom Moor
2021-02-18 22:36:07 -08:00
parent 568e271738
commit df233c95a9
12 changed files with 70 additions and 54 deletions

View File

@@ -1,5 +1,4 @@
// @flow
import invariant from "invariant";
import { concat, filter, last } from "lodash";
import { computed, action } from "mobx";
import naturalSort from "shared/utils/naturalSort";
@@ -89,18 +88,11 @@ export default class CollectionsStore extends BaseStore<Collection> {
}
@action
import = async (file: File) => {
const formData = new FormData();
formData.append("type", "outline");
formData.append("file", file);
const res = await client.post("/collections.import", formData);
invariant(res && res.data, "Data should be available");
this.addPolicies(res.policies);
res.data.collections.forEach(this.add);
return res.data;
import = async (attachmentId: string) => {
await client.post("/collections.import", {
type: "outline",
attachmentId,
});
};
async update(params: Object): Promise<Collection> {