fix: Handle public attachments in Markdown export, closes #6161
This commit is contained in:
@@ -16,7 +16,7 @@ describe("ImportMarkdownZipTask", () => {
|
||||
"..",
|
||||
"test",
|
||||
"fixtures",
|
||||
"outline.zip"
|
||||
"outline-markdown.zip"
|
||||
),
|
||||
cleanup: async () => {},
|
||||
};
|
||||
@@ -36,6 +36,37 @@ describe("ImportMarkdownZipTask", () => {
|
||||
expect(response.attachments.size).toEqual(6);
|
||||
}, 10000);
|
||||
|
||||
it("should import the documents, public attachments", async () => {
|
||||
const fileOperation = await buildFileOperation();
|
||||
Object.defineProperty(fileOperation, "handle", {
|
||||
get() {
|
||||
return {
|
||||
path: path.resolve(
|
||||
__dirname,
|
||||
"..",
|
||||
"..",
|
||||
"test",
|
||||
"fixtures",
|
||||
"outline-markdown-public.zip"
|
||||
),
|
||||
cleanup: async () => {},
|
||||
};
|
||||
},
|
||||
});
|
||||
jest.spyOn(FileOperation, "findByPk").mockResolvedValue(fileOperation);
|
||||
|
||||
const props = {
|
||||
fileOperationId: fileOperation.id,
|
||||
};
|
||||
|
||||
const task = new ImportMarkdownZipTask();
|
||||
const response = await task.perform(props);
|
||||
|
||||
expect(response.collections.size).toEqual(1);
|
||||
expect(response.documents.size).toEqual(2);
|
||||
expect(response.attachments.size).toEqual(1);
|
||||
}, 10000);
|
||||
|
||||
it("should throw an error with corrupt zip", async () => {
|
||||
const fileOperation = await buildFileOperation();
|
||||
Object.defineProperty(fileOperation, "handle", {
|
||||
|
||||
@@ -5,6 +5,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||
import documentImporter from "@server/commands/documentImporter";
|
||||
import Logger from "@server/logging/Logger";
|
||||
import { FileOperation, User } from "@server/models";
|
||||
import { Buckets } from "@server/models/helpers/AttachmentHelper";
|
||||
import ImportHelper, { FileTreeNode } from "@server/utils/ImportHelper";
|
||||
import ImportTask, { StructuredImportData } from "./ImportTask";
|
||||
|
||||
@@ -51,8 +52,11 @@ export default class ImportMarkdownZipTask extends ImportTask {
|
||||
children.map(async (child) => {
|
||||
// special case for folders of attachments
|
||||
if (
|
||||
child.name === "uploads" ||
|
||||
(child.children.length > 0 && child.path.includes("/uploads/"))
|
||||
child.name === Buckets.uploads ||
|
||||
child.name === Buckets.public ||
|
||||
(child.children.length > 0 &&
|
||||
(child.path.includes(`/${Buckets.public}/`) ||
|
||||
child.path.includes(`/${Buckets.uploads}/`)))
|
||||
) {
|
||||
return parseNodeChildren(child.children, collectionId);
|
||||
}
|
||||
@@ -60,7 +64,11 @@ export default class ImportMarkdownZipTask extends ImportTask {
|
||||
const id = uuidv4();
|
||||
|
||||
// this is an attachment
|
||||
if (child.path.includes("/uploads/") && child.children.length === 0) {
|
||||
if (
|
||||
child.children.length === 0 &&
|
||||
(child.path.includes(`/${Buckets.uploads}/`) ||
|
||||
child.path.includes(`/${Buckets.public}/`))
|
||||
) {
|
||||
output.attachments.push({
|
||||
id,
|
||||
name: child.name,
|
||||
@@ -145,10 +153,12 @@ export default class ImportMarkdownZipTask extends ImportTask {
|
||||
|
||||
// Pull the collection and subdirectory out of the path name, upload
|
||||
// folders in an export are relative to the document itself
|
||||
const normalizedAttachmentPath = encodedPath.replace(
|
||||
/(.*)uploads\//,
|
||||
"uploads/"
|
||||
);
|
||||
const normalizedAttachmentPath = encodedPath
|
||||
.replace(
|
||||
new RegExp(`(.*)/${Buckets.uploads}/`),
|
||||
`${Buckets.uploads}/`
|
||||
)
|
||||
.replace(new RegExp(`(.*)/${Buckets.public}/`), `${Buckets.public}/`);
|
||||
|
||||
const reference = `<<${attachment.id}>>`;
|
||||
document.text = document.text
|
||||
|
||||
BIN
server/test/fixtures/outline-markdown-public.zip
vendored
Normal file
BIN
server/test/fixtures/outline-markdown-public.zip
vendored
Normal file
Binary file not shown.
Reference in New Issue
Block a user