feat: Add import/export of documents as JSON (#4621)

* feat: Add export of documents as JSON

* Rename, add structured collection description

* stash

* ui

* Add entity creation data to JSON archive

* Import JSON UI plumbing

* stash

* Messy, but working

* tsc

* tsc
This commit is contained in:
Tom Moor
2023-01-29 10:24:44 -08:00
committed by GitHub
parent 85ca25371c
commit d02d3cb55d
23 changed files with 649 additions and 119 deletions

View File

@@ -4,8 +4,10 @@ import DocumentHelper from "@server/models/helpers/DocumentHelper";
type Props = {
id?: string;
urlId?: string;
title: string;
text: string;
text?: string;
state?: Buffer;
publish?: boolean;
collectionId?: string | null;
parentDocumentId?: string | null;
@@ -19,13 +21,15 @@ type Props = {
editorVersion?: string;
source?: "import";
ip?: string;
transaction: Transaction;
transaction?: Transaction;
};
export default async function documentCreator({
title = "",
text = "",
state,
id,
urlId,
publish,
collectionId,
parentDocumentId,
@@ -43,9 +47,24 @@ export default async function documentCreator({
transaction,
}: Props): Promise<Document> {
const templateId = templateDocument ? templateDocument.id : undefined;
if (urlId) {
const existing = await Document.unscoped().findOne({
attributes: ["id"],
transaction,
where: {
urlId,
},
});
if (existing) {
urlId = undefined;
}
}
const document = await Document.create(
{
id,
urlId,
parentDocumentId,
editorVersion,
collectionId,
@@ -63,8 +82,10 @@ export default async function documentCreator({
? DocumentHelper.replaceTemplateVariables(templateDocument.title, user)
: title,
text: templateDocument ? templateDocument.text : text,
state,
},
{
silent: !!createdAt,
transaction,
}
);