Adds duplicateSubtree to backend API. (#6577)

This commit is contained in:
Elian Doran 2025-08-07 23:57:28 +03:00 committed by GitHub
commit 20018b9c21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 5 deletions

View File

@ -412,6 +412,17 @@ export interface Api {
*/ */
backupNow(backupName: string): Promise<string>; backupNow(backupName: string): Promise<string>;
/**
* Enables the complete duplication of the specified original note and all its children into the specified parent note.
* The new note will be named the same as the original, with (Dup) added to the end of it.
*
* @param origNoteId - the noteId for the original note to be duplicated
* @param newParentNoteId - the noteId for the parent note where the duplication is to be placed.
*
* @returns the note and the branch of the newly created note.
*/
duplicateSubtree(origNoteId: string, newParentNoteId: string): { note: BNote; branch: BBranch; }
/** /**
* This object contains "at your risk" and "no BC guarantees" objects for advanced use cases. * This object contains "at your risk" and "no BC guarantees" objects for advanced use cases.
*/ */
@ -703,6 +714,7 @@ function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {
this.runOutsideOfSync = syncMutex.doExclusively; this.runOutsideOfSync = syncMutex.doExclusively;
this.backupNow = backupService.backupNow; this.backupNow = backupService.backupNow;
this.duplicateSubtree = noteService.duplicateSubtree;
this.__private = { this.__private = {
becca becca

View File

@ -931,10 +931,6 @@ function duplicateSubtree(origNoteId: string, newParentNoteId: string) {
const noteIdMapping = getNoteIdMapping(origNote); const noteIdMapping = getNoteIdMapping(origNote);
if (!origBranch) {
throw new Error("Unable to find original branch to duplicate.");
}
const res = duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapping); const res = duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapping);
const duplicateNoteSuffix = t("notes.duplicate-note-suffix"); const duplicateNoteSuffix = t("notes.duplicate-note-suffix");
@ -966,7 +962,7 @@ function duplicateSubtreeWithoutRoot(origNoteId: string, newNoteId: string) {
} }
} }
function duplicateSubtreeInner(origNote: BNote, origBranch: BBranch, newParentNoteId: string, noteIdMapping: Record<string, string>) { function duplicateSubtreeInner(origNote: BNote, origBranch: BBranch | null | undefined, newParentNoteId: string, noteIdMapping: Record<string, string>) {
if (origNote.isProtected && !protectedSessionService.isProtectedSessionAvailable()) { if (origNote.isProtected && !protectedSessionService.isProtectedSessionAvailable()) {
throw new Error(`Cannot duplicate note '${origNote.noteId}' because it is protected and protected session is not available. Enter protected session and try again.`); throw new Error(`Cannot duplicate note '${origNote.noteId}' because it is protected and protected session is not available. Enter protected session and try again.`);
} }