fix: API response

This commit is contained in:
Tom Moor
2020-12-26 23:12:22 -08:00
parent 7021c2a9e5
commit c8cd7fcf4a
7 changed files with 38 additions and 18 deletions

View File

@ -1,10 +1,10 @@
// @flow // @flow
import * as React from "react"; import * as React from "react";
import { Switch, Route } from "react-router-dom"; import { Switch, Route } from "react-router-dom";
import ImportExport from "scenes/Settings/ImportExport";
import Settings from "scenes/Settings"; import Settings from "scenes/Settings";
import Details from "scenes/Settings/Details"; import Details from "scenes/Settings/Details";
import Groups from "scenes/Settings/Groups"; import Groups from "scenes/Settings/Groups";
import ImportExport from "scenes/Settings/ImportExport";
import Notifications from "scenes/Settings/Notifications"; import Notifications from "scenes/Settings/Notifications";
import People from "scenes/Settings/People"; import People from "scenes/Settings/People";
import Security from "scenes/Settings/Security"; import Security from "scenes/Settings/Security";

View File

@ -97,12 +97,12 @@ export default class CollectionsStore extends BaseStore<Collection> {
if (path) return path.title; if (path) return path.title;
} }
delete(collection: Collection) { delete = async (collection: Collection) => {
super.delete(collection); await super.delete(collection);
this.rootStore.documents.fetchRecentlyUpdated(); this.rootStore.documents.fetchRecentlyUpdated();
this.rootStore.documents.fetchRecentlyViewed(); this.rootStore.documents.fetchRecentlyViewed();
} };
export = () => { export = () => {
return client.post("/collections.export_all"); return client.post("/collections.export_all");

View File

@ -503,7 +503,11 @@ export default class DocumentsStore extends BaseStore<Document> {
formData.append("type", "outline"); formData.append("type", "outline");
formData.append("file", file); formData.append("file", file);
await client.post("/documents.batchImport", formData); const res = await client.post("/documents.batchImport", formData);
invariant(res && res.data, "Data should be available");
this.addPolicies(res.policies);
res.data.collections.forEach(this.rootStore.collections.add);
}; };
@action @action

View File

@ -1124,7 +1124,7 @@ router.post("documents.batchImport", auth(), async (ctx) => {
const user = ctx.state.user; const user = ctx.state.user;
authorize(user, "batchImport", Document); authorize(user, "batchImport", Document);
await documentBatchImporter({ const { collections } = await documentBatchImporter({
file, file,
user, user,
type, type,
@ -1132,7 +1132,12 @@ router.post("documents.batchImport", auth(), async (ctx) => {
}); });
ctx.body = { ctx.body = {
success: true, data: {
collections: collections.map((collection) =>
presentCollection(collection)
),
},
policies: presentPolicies(user, collections),
}; };
}); });

View File

@ -1,6 +1,7 @@
// @flow // @flow
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import debug from "debug";
import File from "formidable/lib/file"; import File from "formidable/lib/file";
import invariant from "invariant"; import invariant from "invariant";
import JSZip from "jszip"; import JSZip from "jszip";
@ -11,6 +12,8 @@ import attachmentCreator from "./attachmentCreator";
import documentCreator from "./documentCreator"; import documentCreator from "./documentCreator";
import documentImporter from "./documentImporter"; import documentImporter from "./documentImporter";
const log = debug("commands");
export default async function documentBatchImporter({ export default async function documentBatchImporter({
file, file,
type, type,
@ -145,7 +148,7 @@ export default async function documentBatchImporter({
continue; continue;
} }
console.log(`Skipped ${itemPath}`); log(`Skipped importing ${itemPath}`);
} }
// All collections, documents, and attachments have been created time to // All collections, documents, and attachments have been created time to
@ -154,9 +157,12 @@ export default async function documentBatchImporter({
const attachment = attachments[attachmentPath]; const attachment = attachments[attachmentPath];
for (const document of values(documents)) { for (const document of values(documents)) {
// pull the collection out of the path name // pull the collection and subdirectory out of the path name, upload folders
const pathParts = attachmentPath.split("/"); // in an Outline export are relative to the document itself
const normalizedAttachmentPath = pathParts.splice(1).join("/"); const normalizedAttachmentPath = attachmentPath.replace(
/(.*)uploads\//,
"uploads/"
);
document.text = document.text document.text = document.text
.replace(attachmentPath, attachment.redirectUrl) .replace(attachmentPath, attachment.redirectUrl)
@ -168,9 +174,14 @@ export default async function documentBatchImporter({
} }
} }
// reload collections to get document mapping
for (const collection of values(collections)) {
await collection.reload();
}
return { return {
documents, documents: values(documents),
collections, collections: values(collections),
attachments, attachments: values(attachments),
}; };
} }

View File

@ -28,8 +28,8 @@ describe("documentBatchImporter", () => {
ip, ip,
}); });
expect(Object.keys(response.collections).length).toEqual(1); expect(response.collections.length).toEqual(1);
expect(Object.keys(response.documents).length).toEqual(8); expect(response.documents.length).toEqual(8);
expect(Object.keys(response.attachments).length).toEqual(6); expect(response.attachments.length).toEqual(6);
}); });
}); });

View File

@ -278,7 +278,7 @@
"Import completed": "Import completed", "Import completed": "Import completed",
"Export in progress…": "Export in progress…", "Export in progress…": "Export in progress…",
"Import": "Import", "Import": "Import",
"It is possible to import a zip file of folders and Markdown files previously exported from an Outline instance. Well soon add support for importing from other services.": "It is possible to import a zip file of folders and Markdown files previously exported from an Outline instance. Well soon add support for importing from other services.", "It is possible to import a zip file of folders and Markdown files previously exported from an Outline instance. Support will soon be added for importing from other services.": "It is possible to import a zip file of folders and Markdown files previously exported from an Outline instance. Support will soon be added for importing from other services.",
"Importing": "Importing", "Importing": "Importing",
"Import Data": "Import Data", "Import Data": "Import Data",
"A full export might take some time, consider exporting a single document or collection if possible. Well put together a zip of all your documents in Markdown format and email it to <2>{{userEmail}}</2>.": "A full export might take some time, consider exporting a single document or collection if possible. Well put together a zip of all your documents in Markdown format and email it to <2>{{userEmail}}</2>.", "A full export might take some time, consider exporting a single document or collection if possible. Well put together a zip of all your documents in Markdown format and email it to <2>{{userEmail}}</2>.": "A full export might take some time, consider exporting a single document or collection if possible. Well put together a zip of all your documents in Markdown format and email it to <2>{{userEmail}}</2>.",