mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	changes in API format
This commit is contained in:
		| @@ -33,7 +33,7 @@ async function showDialog() { | |||||||
| async function savePrefix() { | async function savePrefix() { | ||||||
|     const prefix = $treePrefixInput.val(); |     const prefix = $treePrefixInput.val(); | ||||||
|  |  | ||||||
|     await server.put('tree/' + branchId + '/set-prefix', { prefix: prefix }); |     await server.put('branches/' + branchId + '/set-prefix', { prefix: prefix }); | ||||||
|  |  | ||||||
|     await treeService.setPrefix(branchId, prefix); |     await treeService.setPrefix(branchId, prefix); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -25,7 +25,7 @@ async function showNoteRevisionsDialog(noteId, noteRevisionId) { | |||||||
|     $list.empty(); |     $list.empty(); | ||||||
|     $content.empty(); |     $content.empty(); | ||||||
|  |  | ||||||
|     revisionItems = await server.get('note-revisions/' + noteId); |     revisionItems = await server.get('notes/' + noteId + '/revisions'); | ||||||
|  |  | ||||||
|     for (const item of revisionItems) { |     for (const item of revisionItems) { | ||||||
|         const dateModified = utils.parseDate(item.dateModifiedFrom); |         const dateModified = utils.parseDate(item.dateModifiedFrom); | ||||||
|   | |||||||
| @@ -34,10 +34,7 @@ async function showDialog() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function saveOptions(optionName, optionValue) { | async function saveOptions(optionName, optionValue) { | ||||||
|     await server.post('options', { |     await server.put('options/' + encodeURIComponent(optionName) + '/' + encodeURIComponent(optionValue)); | ||||||
|         name: optionName, |  | ||||||
|         value: optionValue |  | ||||||
|     }); |  | ||||||
|  |  | ||||||
|     infoService.showMessage("Options change have been saved."); |     infoService.showMessage("Options change have been saved."); | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								src/public/javascripts/services/bootstrap.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								src/public/javascripts/services/bootstrap.js
									
									
									
									
										vendored
									
									
								
							| @@ -22,7 +22,7 @@ import ScriptApi from './script_api.js'; | |||||||
| import ScriptContext from './script_context.js'; | import ScriptContext from './script_context.js'; | ||||||
| import sync from './sync.js'; | import sync from './sync.js'; | ||||||
| import treeService from './tree.js'; | import treeService from './tree.js'; | ||||||
| import treeChanges from './tree_changes.js'; | import treeChanges from './branches.js'; | ||||||
| import treeUtils from './tree_utils.js'; | import treeUtils from './tree_utils.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ import treeCache from "./tree_cache.js"; | |||||||
| 
 | 
 | ||||||
| async function moveBeforeNode(nodesToMove, beforeNode) { | async function moveBeforeNode(nodesToMove, beforeNode) { | ||||||
|     for (const nodeToMove of nodesToMove) { |     for (const nodeToMove of nodesToMove) { | ||||||
|         const resp = await server.put('tree/' + nodeToMove.data.branchId + '/move-before/' + beforeNode.data.branchId); |         const resp = await server.put('branches/' + nodeToMove.data.branchId + '/move-before/' + beforeNode.data.branchId); | ||||||
| 
 | 
 | ||||||
|         if (!resp.success) { |         if (!resp.success) { | ||||||
|             alert(resp.message); |             alert(resp.message); | ||||||
| @@ -21,7 +21,7 @@ async function moveAfterNode(nodesToMove, afterNode) { | |||||||
|     nodesToMove.reverse(); // need to reverse to keep the note order
 |     nodesToMove.reverse(); // need to reverse to keep the note order
 | ||||||
| 
 | 
 | ||||||
|     for (const nodeToMove of nodesToMove) { |     for (const nodeToMove of nodesToMove) { | ||||||
|         const resp = await server.put('tree/' + nodeToMove.data.branchId + '/move-after/' + afterNode.data.branchId); |         const resp = await server.put('branches/' + nodeToMove.data.branchId + '/move-after/' + afterNode.data.branchId); | ||||||
| 
 | 
 | ||||||
|         if (!resp.success) { |         if (!resp.success) { | ||||||
|             alert(resp.message); |             alert(resp.message); | ||||||
| @@ -34,7 +34,7 @@ async function moveAfterNode(nodesToMove, afterNode) { | |||||||
| 
 | 
 | ||||||
| async function moveToNode(nodesToMove, toNode) { | async function moveToNode(nodesToMove, toNode) { | ||||||
|     for (const nodeToMove of nodesToMove) { |     for (const nodeToMove of nodesToMove) { | ||||||
|         const resp = await server.put('tree/' + nodeToMove.data.branchId + '/move-to/' + toNode.data.noteId); |         const resp = await server.put('branches/' + nodeToMove.data.branchId + '/move-to/' + toNode.data.noteId); | ||||||
| 
 | 
 | ||||||
|         if (!resp.success) { |         if (!resp.success) { | ||||||
|             alert(resp.message); |             alert(resp.message); | ||||||
| @@ -64,7 +64,7 @@ async function deleteNodes(nodes) { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     for (const node of nodes) { |     for (const node of nodes) { | ||||||
|         await server.remove('tree/' + node.data.branchId); |         await server.remove('branches/' + node.data.branchId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has been
 |     // following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has been
 | ||||||
| @@ -96,7 +96,7 @@ async function moveNodeUpInHierarchy(node) { | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const resp = await server.put('tree/' + node.data.branchId + '/move-after/' + node.getParent().data.branchId); |     const resp = await server.put('branches/' + node.data.branchId + '/move-after/' + node.getParent().data.branchId); | ||||||
| 
 | 
 | ||||||
|     if (!resp.success) { |     if (!resp.success) { | ||||||
|         alert(resp.message); |         alert(resp.message); | ||||||
| @@ -3,9 +3,8 @@ import cloningService from './cloning.js'; | |||||||
| import exportService from './export.js'; | import exportService from './export.js'; | ||||||
| import messagingService from './messaging.js'; | import messagingService from './messaging.js'; | ||||||
| import protectedSessionService from './protected_session.js'; | import protectedSessionService from './protected_session.js'; | ||||||
| import treeChangesService from './tree_changes.js'; | import treeChangesService from './branches.js'; | ||||||
| import treeUtils from './tree_utils.js'; | import treeUtils from './tree_utils.js'; | ||||||
| import utils from './utils.js'; |  | ||||||
| import editTreePrefixDialog from '../dialogs/edit_tree_prefix.js'; | import editTreePrefixDialog from '../dialogs/edit_tree_prefix.js'; | ||||||
| import infoService from "./info.js"; | import infoService from "./info.js"; | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
| @@ -86,18 +85,18 @@ const contextMenuOptions = { | |||||||
|         {title: "----"}, |         {title: "----"}, | ||||||
|         {title: "Edit tree prefix <kbd>F2</kbd>", cmd: "editTreePrefix", uiIcon: "ui-icon-pencil"}, |         {title: "Edit tree prefix <kbd>F2</kbd>", cmd: "editTreePrefix", uiIcon: "ui-icon-pencil"}, | ||||||
|         {title: "----"}, |         {title: "----"}, | ||||||
|         {title: "Protect sub-tree", cmd: "protectSubTree", uiIcon: "ui-icon-locked"}, |         {title: "Protect branch", cmd: "protectBranch", uiIcon: "ui-icon-locked"}, | ||||||
|         {title: "Unprotect sub-tree", cmd: "unprotectSubTree", uiIcon: "ui-icon-unlocked"}, |         {title: "Unprotect branch", cmd: "unprotectBranch", uiIcon: "ui-icon-unlocked"}, | ||||||
|         {title: "----"}, |         {title: "----"}, | ||||||
|         {title: "Copy / clone <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "ui-icon-copy"}, |         {title: "Copy / clone <kbd>Ctrl+C</kbd>", cmd: "copy", uiIcon: "ui-icon-copy"}, | ||||||
|         {title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "ui-icon-scissors"}, |         {title: "Cut <kbd>Ctrl+X</kbd>", cmd: "cut", uiIcon: "ui-icon-scissors"}, | ||||||
|         {title: "Paste into <kbd>Ctrl+V</kbd>", cmd: "pasteInto", uiIcon: "ui-icon-clipboard"}, |         {title: "Paste into <kbd>Ctrl+V</kbd>", cmd: "pasteInto", uiIcon: "ui-icon-clipboard"}, | ||||||
|         {title: "Paste after", cmd: "pasteAfter", uiIcon: "ui-icon-clipboard"}, |         {title: "Paste after", cmd: "pasteAfter", uiIcon: "ui-icon-clipboard"}, | ||||||
|         {title: "----"}, |         {title: "----"}, | ||||||
|         {title: "Export sub-tree", cmd: "exportSubTree", uiIcon: " ui-icon-arrowthick-1-ne"}, |         {title: "Export branch", cmd: "exportBranch", uiIcon: " ui-icon-arrowthick-1-ne"}, | ||||||
|         {title: "Import sub-tree into", cmd: "importSubTree", uiIcon: "ui-icon-arrowthick-1-sw"}, |         {title: "Import into branch", cmd: "importBranch", uiIcon: "ui-icon-arrowthick-1-sw"}, | ||||||
|         {title: "----"}, |         {title: "----"}, | ||||||
|         {title: "Collapse sub-tree <kbd>Alt+-</kbd>", cmd: "collapseSubTree", uiIcon: "ui-icon-minus"}, |         {title: "Collapse branch <kbd>Alt+-</kbd>", cmd: "collapseBranch", uiIcon: "ui-icon-minus"}, | ||||||
|         {title: "Force note sync", cmd: "forceNoteSync", uiIcon: "ui-icon-refresh"}, |         {title: "Force note sync", cmd: "forceNoteSync", uiIcon: "ui-icon-refresh"}, | ||||||
|         {title: "Sort alphabetically <kbd>Alt+S</kbd>", cmd: "sortAlphabetically", uiIcon: " ui-icon-arrowthick-2-n-s"} |         {title: "Sort alphabetically <kbd>Alt+S</kbd>", cmd: "sortAlphabetically", uiIcon: " ui-icon-arrowthick-2-n-s"} | ||||||
|  |  | ||||||
| @@ -113,8 +112,8 @@ const contextMenuOptions = { | |||||||
|         $tree.contextmenu("enableEntry", "pasteInto", clipboardIds.length > 0 && note.type !== 'search'); |         $tree.contextmenu("enableEntry", "pasteInto", clipboardIds.length > 0 && note.type !== 'search'); | ||||||
|         $tree.contextmenu("enableEntry", "insertNoteHere", !parentNote || parentNote.type !== 'search'); |         $tree.contextmenu("enableEntry", "insertNoteHere", !parentNote || parentNote.type !== 'search'); | ||||||
|         $tree.contextmenu("enableEntry", "insertChildNote", note.type !== 'search'); |         $tree.contextmenu("enableEntry", "insertChildNote", note.type !== 'search'); | ||||||
|         $tree.contextmenu("enableEntry", "importSubTree", note.type !== 'search'); |         $tree.contextmenu("enableEntry", "importBranch", note.type !== 'search'); | ||||||
|         $tree.contextmenu("enableEntry", "exportSubTree", note.type !== 'search'); |         $tree.contextmenu("enableEntry", "exportBranch", note.type !== 'search'); | ||||||
|  |  | ||||||
|         // Activate node on right-click |         // Activate node on right-click | ||||||
|         node.setActive(); |         node.setActive(); | ||||||
| @@ -138,11 +137,11 @@ const contextMenuOptions = { | |||||||
|         else if (ui.cmd === "editTreePrefix") { |         else if (ui.cmd === "editTreePrefix") { | ||||||
|             editTreePrefixDialog.showDialog(node); |             editTreePrefixDialog.showDialog(node); | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "protectSubTree") { |         else if (ui.cmd === "protectBranch") { | ||||||
|             protectedSessionService.protectSubTree(node.data.noteId, true); |             protectedSessionService.protectBranch(node.data.noteId, true); | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "unprotectSubTree") { |         else if (ui.cmd === "unprotectBranch") { | ||||||
|             protectedSessionService.protectSubTree(node.data.noteId, false); |             protectedSessionService.protectBranch(node.data.noteId, false); | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "copy") { |         else if (ui.cmd === "copy") { | ||||||
|             copy(treeService.getSelectedNodes()); |             copy(treeService.getSelectedNodes()); | ||||||
| @@ -159,13 +158,13 @@ const contextMenuOptions = { | |||||||
|         else if (ui.cmd === "delete") { |         else if (ui.cmd === "delete") { | ||||||
|             treeChangesService.deleteNodes(treeService.getSelectedNodes(true)); |             treeChangesService.deleteNodes(treeService.getSelectedNodes(true)); | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "exportSubTree") { |         else if (ui.cmd === "exportBranch") { | ||||||
|             exportService.exportSubTree(node.data.noteId); |             exportService.exportBranch(node.data.noteId); | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "importSubTree") { |         else if (ui.cmd === "importBranch") { | ||||||
|             exportService.importSubTree(node.data.noteId); |             exportService.importBranch(node.data.noteId); | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "collapseSubTree") { |         else if (ui.cmd === "collapseBranch") { | ||||||
|             treeService.collapseTree(node); |             treeService.collapseTree(node); | ||||||
|         } |         } | ||||||
|         else if (ui.cmd === "forceNoteSync") { |         else if (ui.cmd === "forceNoteSync") { | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| import treeService from './tree.js'; | import treeService from './tree.js'; | ||||||
| import treeChangesService from './tree_changes.js'; | import treeChangesService from './branches.js'; | ||||||
|  |  | ||||||
| const dragAndDropSetup = { | const dragAndDropSetup = { | ||||||
|     autoExpandMS: 600, |     autoExpandMS: 600, | ||||||
|   | |||||||
| @@ -3,8 +3,8 @@ import protectedSessionHolder from './protected_session_holder.js'; | |||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
|  |  | ||||||
| function exportSubTree(noteId) { | function exportBranch(noteId) { | ||||||
|     const url = utils.getHost() + "/api/export/" + noteId + "?protectedSessionId=" |     const url = utils.getHost() + "/api/notes/" + noteId + "/export?protectedSessionId=" | ||||||
|         + encodeURIComponent(protectedSessionHolder.getProtectedSessionId()); |         + encodeURIComponent(protectedSessionHolder.getProtectedSessionId()); | ||||||
|  |  | ||||||
|     utils.download(url); |     utils.download(url); | ||||||
| @@ -12,7 +12,7 @@ function exportSubTree(noteId) { | |||||||
|  |  | ||||||
| let importNoteId; | let importNoteId; | ||||||
|  |  | ||||||
| function importSubTree(noteId) { | function importBranch(noteId) { | ||||||
|     importNoteId = noteId; |     importNoteId = noteId; | ||||||
|  |  | ||||||
|     $("#import-upload").trigger('click'); |     $("#import-upload").trigger('click'); | ||||||
| @@ -23,7 +23,7 @@ $("#import-upload").change(async function() { | |||||||
|     formData.append('upload', this.files[0]); |     formData.append('upload', this.files[0]); | ||||||
|  |  | ||||||
|     await $.ajax({ |     await $.ajax({ | ||||||
|         url: baseApiUrl + 'import/' + importNoteId, |         url: baseApiUrl + 'notes/' + importNoteId + '/import', | ||||||
|         headers: server.getHeaders(), |         headers: server.getHeaders(), | ||||||
|         data: formData, |         data: formData, | ||||||
|         type: 'POST', |         type: 'POST', | ||||||
| @@ -35,6 +35,6 @@ $("#import-upload").change(async function() { | |||||||
| }); | }); | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     exportSubTree, |     exportBranch, | ||||||
|     importSubTree |     importBranch | ||||||
| }; | }; | ||||||
| @@ -119,10 +119,10 @@ async function unprotectNoteAndSendToServer() { | |||||||
|     noteDetail.setNoteBackgroundIfProtected(note); |     noteDetail.setNoteBackgroundIfProtected(note); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function protectSubTree(noteId, protect) { | async function protectBranch(noteId, protect) { | ||||||
|     await ensureProtectedSession(true, true); |     await ensureProtectedSession(true, true); | ||||||
|  |  | ||||||
|     await server.put('notes/' + noteId + "/protect-sub-tree/" + (protect ? 1 : 0)); |     await server.put('notes/' + noteId + "/protect/" + (protect ? 1 : 0)); | ||||||
|  |  | ||||||
|     infoService.showMessage("Request to un/protect sub tree has finished successfully"); |     infoService.showMessage("Request to un/protect sub tree has finished successfully"); | ||||||
|  |  | ||||||
| @@ -143,6 +143,6 @@ export default { | |||||||
|     ensureProtectedSession, |     ensureProtectedSession, | ||||||
|     protectNoteAndSendToServer, |     protectNoteAndSendToServer, | ||||||
|     unprotectNoteAndSendToServer, |     unprotectNoteAndSendToServer, | ||||||
|     protectSubTree, |     protectBranch, | ||||||
|     ensureDialogIsClosed |     ensureDialogIsClosed | ||||||
| }; | }; | ||||||
| @@ -6,7 +6,7 @@ let protectedSessionTimeout = null; | |||||||
| let protectedSessionId = null; | let protectedSessionId = null; | ||||||
|  |  | ||||||
| $(document).ready(() => { | $(document).ready(() => { | ||||||
|     server.get('options/all').then(options => protectedSessionTimeout = options.protected_session_timeout); |     server.get('options').then(options => protectedSessionTimeout = options.protected_session_timeout); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| setInterval(() => { | setInterval(() => { | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ import linkService from './link.js'; | |||||||
| import messagingService from './messaging.js'; | import messagingService from './messaging.js'; | ||||||
| import noteDetailService from './note_detail.js'; | import noteDetailService from './note_detail.js'; | ||||||
| import protectedSessionHolder from './protected_session_holder.js'; | import protectedSessionHolder from './protected_session_holder.js'; | ||||||
| import treeChangesService from './tree_changes.js'; | import treeChangesService from './branches.js'; | ||||||
| import treeUtils from './tree_utils.js'; | import treeUtils from './tree_utils.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
| @@ -238,7 +238,7 @@ async function setExpandedToServer(branchId, isExpanded) { | |||||||
|  |  | ||||||
|     const expandedNum = isExpanded ? 1 : 0; |     const expandedNum = isExpanded ? 1 : 0; | ||||||
|  |  | ||||||
|     await server.put('tree/' + branchId + '/expanded/' + expandedNum); |     await server.put('branches/' + branchId + '/expanded/' + expandedNum); | ||||||
| } | } | ||||||
|  |  | ||||||
| function setCurrentNotePathToHash(node) { | function setCurrentNotePathToHash(node) { | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| import noteDetailService from "./note_detail.js"; | import noteDetailService from "./note_detail.js"; | ||||||
| import utils from "./utils.js"; | import utils from "./utils.js"; | ||||||
| import treeChangesService from "./tree_changes.js"; | import treeChangesService from "./branches.js"; | ||||||
| import contextMenuService from "./context_menu.js"; | import contextMenuService from "./context_menu.js"; | ||||||
| import treeService from "./tree.js"; | import treeService from "./tree.js"; | ||||||
| import editTreePrefixDialog from "../dialogs/edit_tree_prefix.js"; | import editTreePrefixDialog from "../dialogs/edit_tree_prefix.js"; | ||||||
|   | |||||||
| @@ -105,10 +105,20 @@ async function deleteBranch(req) { | |||||||
|     await notes.deleteNote(branch); |     await notes.deleteNote(branch); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | async function setPrefix(req) { | ||||||
|  |     const branchId = req.params.branchId; | ||||||
|  |     const prefix = utils.isEmptyOrWhitespace(req.body.prefix) ? null : req.body.prefix; | ||||||
|  | 
 | ||||||
|  |     const branch = await repository.getBranch(branchId); | ||||||
|  |     branch.prefix = prefix; | ||||||
|  |     await branch.save(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| module.exports = { | module.exports = { | ||||||
|     moveBranchToParent, |     moveBranchToParent, | ||||||
|     moveBranchBeforeNote, |     moveBranchBeforeNote, | ||||||
|     moveBranchAfterNote, |     moveBranchAfterNote, | ||||||
|     setExpanded, |     setExpanded, | ||||||
|     deleteBranch |     deleteBranch, | ||||||
|  |     setPrefix | ||||||
| }; | }; | ||||||
| @@ -1,17 +1,16 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const sql = require('../../services/sql'); | const sql = require('../../services/sql'); | ||||||
| const utils = require('../../services/utils'); |  | ||||||
| const sync_table = require('../../services/sync_table'); | const sync_table = require('../../services/sync_table'); | ||||||
| const tree = require('../../services/tree'); | const tree = require('../../services/tree'); | ||||||
| const Branch = require('../../entities/branch'); | const Branch = require('../../entities/branch'); | ||||||
|  |  | ||||||
| async function cloneNoteToParent(req) { | async function cloneNoteToParent(req) { | ||||||
|  |     const noteId = req.params.noteId; | ||||||
|     const parentNoteId = req.params.parentNoteId; |     const parentNoteId = req.params.parentNoteId; | ||||||
|     const childNoteId = req.params.childNoteId; |  | ||||||
|     const prefix = req.body.prefix; |     const prefix = req.body.prefix; | ||||||
|  |  | ||||||
|     const validationResult = await tree.validateParentChild(parentNoteId, childNoteId); |     const validationResult = await tree.validateParentChild(parentNoteId, noteId); | ||||||
|  |  | ||||||
|     if (!validationResult.success) { |     if (!validationResult.success) { | ||||||
|         return validationResult; |         return validationResult; | ||||||
| @@ -21,7 +20,7 @@ async function cloneNoteToParent(req) { | |||||||
|     const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1; |     const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1; | ||||||
|  |  | ||||||
|     const branch = new Branch({ |     const branch = new Branch({ | ||||||
|         noteId: childNoteId, |         noteId: noteId, | ||||||
|         parentNoteId: parentNoteId, |         parentNoteId: parentNoteId, | ||||||
|         prefix: prefix, |         prefix: prefix, | ||||||
|         notePosition: newNotePos, |         notePosition: newNotePos, | ||||||
|   | |||||||
| @@ -86,18 +86,18 @@ async function parseImportFile(file) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function importTar(req) { | async function importTar(req) { | ||||||
|     const parentNoteId = req.params.parentNoteId; |     const noteId = req.params.noteId; | ||||||
|     const file = req.file; |     const file = req.file; | ||||||
|  |  | ||||||
|     const parentNote = await repository.getNote(parentNoteId); |     const parentNote = await repository.getNote(noteId); | ||||||
|  |  | ||||||
|     if (!parentNote) { |     if (!parentNote) { | ||||||
|         return [404, `Note ${parentNoteId} doesn't exist.`]; |         return [404, `Note ${noteId} doesn't exist.`]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const files = await parseImportFile(file); |     const files = await parseImportFile(file); | ||||||
|  |  | ||||||
|     await importNotes(files, parentNoteId); |     await importNotes(files, noteId); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function importNotes(files, parentNoteId) { | async function importNotes(files, parentNoteId) { | ||||||
|   | |||||||
| @@ -6,11 +6,7 @@ const options = require('../../services/options'); | |||||||
| // options allowed to be updated directly in options dialog | // options allowed to be updated directly in options dialog | ||||||
| const ALLOWED_OPTIONS = ['protected_session_timeout', 'note_revision_snapshot_time_interval']; | const ALLOWED_OPTIONS = ['protected_session_timeout', 'note_revision_snapshot_time_interval']; | ||||||
|  |  | ||||||
| async function getAllOptions() { | async function getOptions() { | ||||||
|     return await sql.getMap("SELECT name, value FROM options"); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function getAllowedOptions() { |  | ||||||
|     const options = await sql.getMap("SELECT name, value FROM options WHERE name IN (" |     const options = await sql.getMap("SELECT name, value FROM options WHERE name IN (" | ||||||
|         + ALLOWED_OPTIONS.map(x => '?').join(",") + ")", ALLOWED_OPTIONS); |         + ALLOWED_OPTIONS.map(x => '?').join(",") + ")", ALLOWED_OPTIONS); | ||||||
|  |  | ||||||
| @@ -18,17 +14,16 @@ async function getAllowedOptions() { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function updateOption(req) { | async function updateOption(req) { | ||||||
|     const body = req.body; |     const {name, value} = req.params; | ||||||
|  |  | ||||||
|     if (!ALLOWED_OPTIONS.includes(body['name'])) { |     if (!ALLOWED_OPTIONS.includes(name)) { | ||||||
|         return [400, "not allowed option to set"]; |         return [400, "not allowed option to set"]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     await options.setOption(body['name'], body['value']); |     await options.setOption(name, value); | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     getAllowedOptions, |     getOptions, | ||||||
|     getAllOptions, |  | ||||||
|     updateOption |     updateOption | ||||||
| }; | }; | ||||||
| @@ -60,16 +60,6 @@ async function getTree() { | |||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function setPrefix(req) { |  | ||||||
|     const branchId = req.params.branchId; |  | ||||||
|     const prefix = utils.isEmptyOrWhitespace(req.body.prefix) ? null : req.body.prefix; |  | ||||||
|  |  | ||||||
|     const branch = await repository.getBranch(branchId); |  | ||||||
|     branch.prefix = prefix; |  | ||||||
|     await branch.save(); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     getTree, |     getTree | ||||||
|     setPrefix |  | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ const multer = require('multer')(); | |||||||
| // API routes | // API routes | ||||||
| const treeApiRoute = require('./api/tree'); | const treeApiRoute = require('./api/tree'); | ||||||
| const notesApiRoute = require('./api/notes'); | const notesApiRoute = require('./api/notes'); | ||||||
| const treeChangesApiRoute = require('./api/tree_changes'); | const branchesApiRoute = require('./api/branches'); | ||||||
| const cloningApiRoute = require('./api/cloning'); | const cloningApiRoute = require('./api/cloning'); | ||||||
| const noteRevisionsApiRoute = require('./api/note_revisions'); | const noteRevisionsApiRoute = require('./api/note_revisions'); | ||||||
| const recentChangesApiRoute = require('./api/recent_changes'); | const recentChangesApiRoute = require('./api/recent_changes'); | ||||||
| @@ -99,36 +99,37 @@ function register(app) { | |||||||
|     route(GET, '/setup', [auth.checkAppNotInitialized], setupRoute.setupPage); |     route(GET, '/setup', [auth.checkAppNotInitialized], setupRoute.setupPage); | ||||||
|  |  | ||||||
|     apiRoute(GET, '/api/tree', treeApiRoute.getTree); |     apiRoute(GET, '/api/tree', treeApiRoute.getTree); | ||||||
|     apiRoute(PUT, '/api/tree/:branchId/set-prefix', treeApiRoute.setPrefix); |     apiRoute(PUT, '/api/branches/:branchId/set-prefix', branchesApiRoute.setPrefix); | ||||||
|  |  | ||||||
|     apiRoute(PUT, '/api/tree/:branchId/move-to/:parentNoteId', treeChangesApiRoute.moveBranchToParent); |     apiRoute(PUT, '/api/branches/:branchId/move-to/:parentNoteId', branchesApiRoute.moveBranchToParent); | ||||||
|     apiRoute(PUT, '/api/tree/:branchId/move-before/:beforeBranchId', treeChangesApiRoute.moveBranchBeforeNote); |     apiRoute(PUT, '/api/branches/:branchId/move-before/:beforeBranchId', branchesApiRoute.moveBranchBeforeNote); | ||||||
|     apiRoute(PUT, '/api/tree/:branchId/move-after/:afterBranchId', treeChangesApiRoute.moveBranchAfterNote); |     apiRoute(PUT, '/api/branches/:branchId/move-after/:afterBranchId', branchesApiRoute.moveBranchAfterNote); | ||||||
|     apiRoute(PUT, '/api/tree/:branchId/expanded/:expanded', treeChangesApiRoute.setExpanded); |     apiRoute(PUT, '/api/branches/:branchId/expanded/:expanded', branchesApiRoute.setExpanded); | ||||||
|     apiRoute(DELETE, '/api/tree/:branchId', treeChangesApiRoute.deleteBranch); |     apiRoute(DELETE, '/api/branches/:branchId', branchesApiRoute.deleteBranch); | ||||||
|  |  | ||||||
|     apiRoute(GET, '/api/notes/:noteId', notesApiRoute.getNote); |     apiRoute(GET, '/api/notes/:noteId', notesApiRoute.getNote); | ||||||
|     apiRoute(PUT, '/api/notes/:noteId', notesApiRoute.updateNote); |     apiRoute(PUT, '/api/notes/:noteId', notesApiRoute.updateNote); | ||||||
|     apiRoute(POST, '/api/notes/:parentNoteId/children', notesApiRoute.createNote); |     apiRoute(POST, '/api/notes/:parentNoteId/children', notesApiRoute.createNote); | ||||||
|     apiRoute(PUT, '/api/notes/:noteId/sort', notesApiRoute.sortNotes); |     apiRoute(PUT, '/api/notes/:noteId/sort', notesApiRoute.sortNotes); | ||||||
|     apiRoute(PUT, '/api/notes/:noteId/protect-sub-tree/:isProtected', notesApiRoute.protectBranch); |     apiRoute(PUT, '/api/notes/:noteId/protect/:isProtected', notesApiRoute.protectBranch); | ||||||
|     apiRoute(PUT, /\/api\/notes\/(.*)\/type\/(.*)\/mime\/(.*)/, notesApiRoute.setNoteTypeMime); |     apiRoute(PUT, /\/api\/notes\/(.*)\/type\/(.*)\/mime\/(.*)/, notesApiRoute.setNoteTypeMime); | ||||||
|  |     apiRoute(GET, '/api/notes/:noteId/revisions', noteRevisionsApiRoute.getNoteRevisions); | ||||||
|  |  | ||||||
|     apiRoute(PUT, '/api/notes/:childNoteId/clone-to/:parentNoteId', cloningApiRoute.cloneNoteToParent); |     apiRoute(PUT, '/api/notes/:noteId/clone-to/:parentNoteId', cloningApiRoute.cloneNoteToParent); | ||||||
|     apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter); |     apiRoute(PUT, '/api/notes/:noteId/clone-after/:afterBranchId', cloningApiRoute.cloneNoteAfter); | ||||||
|  |  | ||||||
|  |     route(GET, '/api/notes/:noteId/export', [auth.checkApiAuthOrElectron], exportRoute.exportNote); | ||||||
|  |     route(POST, '/api/notes/:noteId/import', [auth.checkApiAuthOrElectron, uploadMiddleware], importRoute.importTar, apiResultHandler); | ||||||
|  |  | ||||||
|     apiRoute(GET, '/api/notes/:noteId/labels', labelsRoute.getNoteLabels); |     apiRoute(GET, '/api/notes/:noteId/labels', labelsRoute.getNoteLabels); | ||||||
|     apiRoute(PUT, '/api/notes/:noteId/labels', labelsRoute.updateNoteLabels); |     apiRoute(PUT, '/api/notes/:noteId/labels', labelsRoute.updateNoteLabels); | ||||||
|     apiRoute(GET, '/api/labels/names', labelsRoute.getAllLabelNames); |     apiRoute(GET, '/api/labels/names', labelsRoute.getAllLabelNames); | ||||||
|     apiRoute(GET, '/api/labels/values/:labelName', labelsRoute.getValuesForLabel); |     apiRoute(GET, '/api/labels/values/:labelName', labelsRoute.getValuesForLabel); | ||||||
|  |  | ||||||
|     apiRoute(GET, '/api/note-revisions/:noteId', noteRevisionsApiRoute.getNoteRevisions); |  | ||||||
|  |  | ||||||
|     apiRoute(GET, '/api/recent-changes', recentChangesApiRoute.getRecentChanges); |     apiRoute(GET, '/api/recent-changes', recentChangesApiRoute.getRecentChanges); | ||||||
|  |  | ||||||
|     apiRoute(GET, '/api/options', optionsApiRoute.getAllowedOptions); |     apiRoute(GET, '/api/options', optionsApiRoute.getOptions); | ||||||
|     apiRoute(GET, '/api/options/all', optionsApiRoute.getAllOptions); |     apiRoute(PUT, '/api/options/:name/:value', optionsApiRoute.updateOption); | ||||||
|     apiRoute(POST, '/api/options', optionsApiRoute.updateOption); |  | ||||||
|  |  | ||||||
|     apiRoute(POST, '/api/password/change', passwordApiRoute.changePassword); |     apiRoute(POST, '/api/password/change', passwordApiRoute.changePassword); | ||||||
|  |  | ||||||
| @@ -164,9 +165,6 @@ function register(app) { | |||||||
|     apiRoute(PUT, '/api/recent-notes/:branchId/:notePath', recentNotesRoute.addRecentNote); |     apiRoute(PUT, '/api/recent-notes/:branchId/:notePath', recentNotesRoute.addRecentNote); | ||||||
|     apiRoute(GET, '/api/app-info', appInfoRoute.getAppInfo); |     apiRoute(GET, '/api/app-info', appInfoRoute.getAppInfo); | ||||||
|  |  | ||||||
|     route(GET, '/api/export/:noteId', [auth.checkApiAuthOrElectron], exportRoute.exportNote); |  | ||||||
|     route(POST, '/api/import/:parentNoteId', [auth.checkApiAuthOrElectron], importRoute.importTar, apiResultHandler); |  | ||||||
|  |  | ||||||
|     route(POST, '/api/setup', [auth.checkAppNotInitialized], setupApiRoute.setup, apiResultHandler); |     route(POST, '/api/setup', [auth.checkAppNotInitialized], setupApiRoute.setup, apiResultHandler); | ||||||
|  |  | ||||||
|     apiRoute(POST, '/api/sql/execute', sqlRoute.execute); |     apiRoute(POST, '/api/sql/execute', sqlRoute.execute); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user