mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	refactoring of note creation APIs WIP
This commit is contained in:
		| @@ -114,6 +114,10 @@ class Note extends Entity { | |||||||
|  |  | ||||||
|     /** @returns {Promise} */ |     /** @returns {Promise} */ | ||||||
|     async setContent(content) { |     async setContent(content) { | ||||||
|  |         if (content === null || content === undefined) { | ||||||
|  |             throw new Error(`Cannot set null content to note ${this.noteId}`); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         // force updating note itself so that dateModified is represented correctly even for the content |         // force updating note itself so that dateModified is represented correctly even for the content | ||||||
|         this.forcedChange = true; |         this.forcedChange = true; | ||||||
|         this.contentLength = content.length; |         this.contentLength = content.length; | ||||||
|   | |||||||
| @@ -651,7 +651,7 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) { | |||||||
|  |  | ||||||
|     const {note, branch} = await server.post(`notes/${parentNoteId}/children?target=${target}&targetBranchId=${node.data.branchId}`, { |     const {note, branch} = await server.post(`notes/${parentNoteId}/children?target=${target}&targetBranchId=${node.data.branchId}`, { | ||||||
|         title: newNoteName, |         title: newNoteName, | ||||||
|         content: extraOptions.content, |         content: extraOptions.content || "", | ||||||
|         isProtected: extraOptions.isProtected, |         isProtected: extraOptions.isProtected, | ||||||
|         type: extraOptions.type |         type: extraOptions.type | ||||||
|     }); |     }); | ||||||
|   | |||||||
| @@ -129,6 +129,14 @@ async function createNewNote(params) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function createNewNoteWithTarget(target, targetBranchId, params) { | async function createNewNoteWithTarget(target, targetBranchId, params) { | ||||||
|  |     if (!params.type) { | ||||||
|  |         const parentNote = await repository.getNote(params.parentNoteId); | ||||||
|  |  | ||||||
|  |         // code note type can be inherited, otherwise text is default | ||||||
|  |         params.type = parentNote.type === 'code' ? 'code' : 'text'; | ||||||
|  |         params.mime = parentNote.type === 'code' ? parentNote.mime : 'text/html'; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     if (target === 'into') { |     if (target === 'into') { | ||||||
|         return await createNewNote(params); |         return await createNewNote(params); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user