feat: Allow document metadata to be stored in zip comment
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user