feat: Allow document metadata to be stored in zip comment
This commit is contained in:
parent
c8cd7fcf4a
commit
012e6b320e
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Reference in New Issue