fix: Document title with slashes produces folders in exported zip file

closes #2036
This commit is contained in:
Tom Moor
2021-04-17 19:30:31 -07:00
parent 03d90b3f15
commit e9f083feb8
6 changed files with 68 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import * as Sentry from "@sentry/node";
import JSZip from "jszip";
import tmp from "tmp";
import { Attachment, Collection, Document } from "../models";
import { serializeFilename } from "./fs";
import { getFileByKey } from "./s3";
async function addToArchive(zip, documents) {
@ -23,7 +24,9 @@ async function addToArchive(zip, documents) {
text = text.replace(attachment.redirectUrl, encodeURI(attachment.key));
}
zip.file(`${document.title || "Untitled"}.md`, text, {
const title = serializeFilename(document.title) || "Untitled";
zip.file(`${title}.md`, text, {
date: document.updatedAt,
comment: JSON.stringify({
pinned: document.pinned,
@ -33,7 +36,7 @@ async function addToArchive(zip, documents) {
});
if (doc.children && doc.children.length) {
const folder = zip.folder(document.title);
const folder = zip.folder(title);
await addToArchive(folder, doc.children);
}
}