feat: Allow document metadata to be stored in zip comment
This commit is contained in:
@ -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`] = `
|
exports[`#collections.memberships should require authentication 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"error": "authentication_required",
|
"error": "authentication_required",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
import { metadata } from "core-js/fn/reflect";
|
||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import File from "formidable/lib/file";
|
import File from "formidable/lib/file";
|
||||||
import invariant from "invariant";
|
import invariant from "invariant";
|
||||||
@ -62,6 +63,16 @@ export default async function documentBatchImporter({
|
|||||||
const name = path.basename(item.name);
|
const name = path.basename(item.name);
|
||||||
const depth = itemPath.split("/").length - 1;
|
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) {
|
if (depth === 0 && item.dir && name) {
|
||||||
// check if collection with name exists
|
// check if collection with name exists
|
||||||
let [collection, isCreated] = await Collection.findOrCreate({
|
let [collection, isCreated] = await Collection.findOrCreate({
|
||||||
@ -125,6 +136,10 @@ export default async function documentBatchImporter({
|
|||||||
text,
|
text,
|
||||||
publish: true,
|
publish: true,
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
|
createdAt: metadata.createdAt
|
||||||
|
? new Date(metadata.createdAt)
|
||||||
|
: item.date,
|
||||||
|
updatedAt: item.date,
|
||||||
parentDocumentId,
|
parentDocumentId,
|
||||||
user,
|
user,
|
||||||
ip,
|
ip,
|
||||||
|
@ -8,6 +8,8 @@ export default async function documentCreator({
|
|||||||
collectionId,
|
collectionId,
|
||||||
parentDocumentId,
|
parentDocumentId,
|
||||||
templateDocument,
|
templateDocument,
|
||||||
|
createdAt, // allows override for import
|
||||||
|
updatedAt,
|
||||||
template,
|
template,
|
||||||
index,
|
index,
|
||||||
user,
|
user,
|
||||||
@ -21,6 +23,8 @@ export default async function documentCreator({
|
|||||||
parentDocumentId?: string,
|
parentDocumentId?: string,
|
||||||
templateDocument?: Document,
|
templateDocument?: Document,
|
||||||
template?: boolean,
|
template?: boolean,
|
||||||
|
createdAt?: Date,
|
||||||
|
updatedAt?: Date,
|
||||||
index?: number,
|
index?: number,
|
||||||
user: User,
|
user: User,
|
||||||
editorVersion?: string,
|
editorVersion?: string,
|
||||||
@ -33,6 +37,8 @@ export default async function documentCreator({
|
|||||||
collectionId,
|
collectionId,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
|
createdAt,
|
||||||
|
updatedAt,
|
||||||
lastModifiedById: user.id,
|
lastModifiedById: user.id,
|
||||||
createdById: user.id,
|
createdById: user.id,
|
||||||
template,
|
template,
|
||||||
|
@ -20,7 +20,14 @@ async function addToArchive(zip, documents) {
|
|||||||
text = text.replace(attachment.redirectUrl, encodeURI(attachment.key));
|
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) {
|
if (doc.children && doc.children.length) {
|
||||||
const folder = zip.folder(document.title);
|
const folder = zip.folder(document.title);
|
||||||
|
Reference in New Issue
Block a user