mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 08:29:00 +01:00
fix(server): attachments not copied for templates (closes #7612)
This commit is contained in:
parent
051e2b4eef
commit
0e95610d4e
@ -97,6 +97,23 @@ function copyChildAttributes(parentNote: BNote, childNote: BNote) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function copyAttachments(origNote: BNote, newNote: BNote) {
|
||||||
|
for (const attachment of origNote.getAttachments()) {
|
||||||
|
if (attachment.role === "image") {
|
||||||
|
// Handled separately, see `checkImageAttachments`.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newAttachment = new BAttachment({
|
||||||
|
...attachment,
|
||||||
|
attachmentId: undefined,
|
||||||
|
ownerId: newNote.noteId
|
||||||
|
});
|
||||||
|
|
||||||
|
newAttachment.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getNewNoteTitle(parentNote: BNote) {
|
function getNewNoteTitle(parentNote: BNote) {
|
||||||
let title = t("notes.new-note");
|
let title = t("notes.new-note");
|
||||||
|
|
||||||
@ -225,11 +242,13 @@ function createNewNote(params: NoteParams): {
|
|||||||
asyncPostProcessContent(note, params.content);
|
asyncPostProcessContent(note, params.content);
|
||||||
|
|
||||||
if (params.templateNoteId) {
|
if (params.templateNoteId) {
|
||||||
if (!becca.getNote(params.templateNoteId)) {
|
const templateNote = becca.getNote(params.templateNoteId);
|
||||||
|
if (!templateNote) {
|
||||||
throw new Error(`Template note '${params.templateNoteId}' does not exist.`);
|
throw new Error(`Template note '${params.templateNoteId}' does not exist.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
note.addRelation("template", params.templateNoteId);
|
note.addRelation("template", params.templateNoteId);
|
||||||
|
copyAttachments(templateNote, note);
|
||||||
|
|
||||||
// no special handling for ~inherit since it doesn't matter if it's assigned with the note creation or later
|
// no special handling for ~inherit since it doesn't matter if it's assigned with the note creation or later
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export interface AttachmentRow {
|
|||||||
isProtected?: boolean;
|
isProtected?: boolean;
|
||||||
dateModified?: string;
|
dateModified?: string;
|
||||||
utcDateModified?: string;
|
utcDateModified?: string;
|
||||||
utcDateScheduledForErasureSince?: string;
|
utcDateScheduledForErasureSince?: string | null;
|
||||||
isDeleted?: boolean;
|
isDeleted?: boolean;
|
||||||
deleteId?: string;
|
deleteId?: string;
|
||||||
contentLength?: number;
|
contentLength?: number;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user