diff --git a/apps/server/src/services/notes.ts b/apps/server/src/services/notes.ts index 3ecf98e0a..4e8869414 100644 --- a/apps/server/src/services/notes.ts +++ b/apps/server/src/services/notes.ts @@ -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) { let title = t("notes.new-note"); @@ -225,11 +242,13 @@ function createNewNote(params: NoteParams): { asyncPostProcessContent(note, params.content); 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.`); } 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 } diff --git a/packages/commons/src/lib/rows.ts b/packages/commons/src/lib/rows.ts index 9bb9d11d5..5710cf84f 100644 --- a/packages/commons/src/lib/rows.ts +++ b/packages/commons/src/lib/rows.ts @@ -12,7 +12,7 @@ export interface AttachmentRow { isProtected?: boolean; dateModified?: string; utcDateModified?: string; - utcDateScheduledForErasureSince?: string; + utcDateScheduledForErasureSince?: string | null; isDeleted?: boolean; deleteId?: string; contentLength?: number;