mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 07:08:55 +02:00
Adds duplicateSubtree to backend API.
This commit is contained in:
parent
faa40494d8
commit
8e04690568
@ -412,6 +412,13 @@ export interface Api {
|
||||
*/
|
||||
backupNow(backupName: string): Promise<string>;
|
||||
|
||||
/**
|
||||
* Exposes the backend duplicateSubtree to the API
|
||||
* @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.
|
||||
*/
|
||||
duplicateSubtree(origNoteId: string, newParentNoteId: string): { note: BNote; branch: BBranch; }
|
||||
|
||||
/**
|
||||
* This object contains "at your risk" and "no BC guarantees" objects for advanced use cases.
|
||||
*/
|
||||
@ -703,6 +710,7 @@ function BackendScriptApi(this: Api, currentNote: BNote, apiParams: ApiParams) {
|
||||
|
||||
this.runOutsideOfSync = syncMutex.doExclusively;
|
||||
this.backupNow = backupService.backupNow;
|
||||
this.duplicateSubtree = noteService.duplicateSubtree;
|
||||
|
||||
this.__private = {
|
||||
becca
|
||||
|
@ -931,9 +931,10 @@ function duplicateSubtree(origNoteId: string, newParentNoteId: string) {
|
||||
|
||||
const noteIdMapping = getNoteIdMapping(origNote);
|
||||
|
||||
if (!origBranch) {
|
||||
throw new Error("Unable to find original branch to duplicate.");
|
||||
}
|
||||
// Not required - if origBranch doesn't exist, the subtree can still be created.
|
||||
// if (!origBranch) {
|
||||
// throw new Error("Unable to find original branch to duplicate.");
|
||||
// }
|
||||
|
||||
const res = duplicateSubtreeInner(origNote, origBranch, newParentNoteId, noteIdMapping);
|
||||
|
||||
@ -966,7 +967,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()) {
|
||||
throw new Error(`Cannot duplicate note '${origNote.noteId}' because it is protected and protected session is not available. Enter protected session and try again.`);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user