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:
@@ -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,
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user