diff --git a/server/api/__snapshots__/collections.test.js.snap b/server/api/__snapshots__/collections.test.js.snap index da385b86..95fec2a7 100644 --- a/server/api/__snapshots__/collections.test.js.snap +++ b/server/api/__snapshots__/collections.test.js.snap @@ -79,15 +79,6 @@ Object { } `; -exports[`#collections.list should return collections 1`] = ` -Object { - "error": "authentication_required", - "message": "Authentication required", - "ok": false, - "status": 401, -} -`; - exports[`#collections.memberships should require authentication 1`] = ` Object { "error": "authentication_required", diff --git a/server/commands/documentBatchImporter.js b/server/commands/documentBatchImporter.js index 66f82c71..8a8f1060 100644 --- a/server/commands/documentBatchImporter.js +++ b/server/commands/documentBatchImporter.js @@ -1,6 +1,7 @@ // @flow import fs from "fs"; import path from "path"; +import { metadata } from "core-js/fn/reflect"; import debug from "debug"; import File from "formidable/lib/file"; import invariant from "invariant"; @@ -62,6 +63,16 @@ export default async function documentBatchImporter({ const name = path.basename(item.name); const depth = itemPath.split("/").length - 1; + // metadata + let metadata = {}; + try { + metadata = item.comment ? JSON.parse(item.comment) : {}; + } catch (err) { + log( + `ZIP comment found for ${item.name}, but could not be parsed as metadata: ${item.comment}` + ); + } + if (depth === 0 && item.dir && name) { // check if collection with name exists let [collection, isCreated] = await Collection.findOrCreate({ @@ -125,6 +136,10 @@ export default async function documentBatchImporter({ text, publish: true, collectionId: collection.id, + createdAt: metadata.createdAt + ? new Date(metadata.createdAt) + : item.date, + updatedAt: item.date, parentDocumentId, user, ip, diff --git a/server/commands/documentCreator.js b/server/commands/documentCreator.js index 0652fc90..805af277 100644 --- a/server/commands/documentCreator.js +++ b/server/commands/documentCreator.js @@ -8,6 +8,8 @@ export default async function documentCreator({ collectionId, parentDocumentId, templateDocument, + createdAt, // allows override for import + updatedAt, template, index, user, @@ -21,6 +23,8 @@ export default async function documentCreator({ parentDocumentId?: string, templateDocument?: Document, template?: boolean, + createdAt?: Date, + updatedAt?: Date, index?: number, user: User, editorVersion?: string, @@ -33,6 +37,8 @@ export default async function documentCreator({ collectionId, teamId: user.teamId, userId: user.id, + createdAt, + updatedAt, lastModifiedById: user.id, createdById: user.id, template, diff --git a/server/utils/zip.js b/server/utils/zip.js index 0c665095..bae9d457 100644 --- a/server/utils/zip.js +++ b/server/utils/zip.js @@ -20,7 +20,14 @@ async function addToArchive(zip, documents) { text = text.replace(attachment.redirectUrl, encodeURI(attachment.key)); } - zip.file(`${document.title || "Untitled"}.md`, text); + zip.file(`${document.title || "Untitled"}.md`, text, { + date: document.updatedAt, + comment: JSON.stringify({ + pinned: document.pinned, + createdAt: document.createdAt, + updatedAt: document.updatedAt, + }), + }); if (doc.children && doc.children.length) { const folder = zip.folder(document.title);