mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	Compare commits
	
		
			15 Commits
		
	
	
		
			v0.10.0-be
			...
			v0.10.2-be
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | b5e6f46b9c | ||
|  | 08af4a0465 | ||
|  | 8c5df6321f | ||
|  | d19f044961 | ||
|  | e378d9f645 | ||
|  | 39dc0f71b4 | ||
|  | 0cef5c6b8c | ||
|  | 9b5a44cef4 | ||
|  | 29769ed91d | ||
|  | 867d794e17 | ||
|  | fdd8458336 | ||
|  | a0bec22e96 | ||
|  | 5aeb5cd214 | ||
|  | e827ddffb9 | ||
|  | 98f80998b9 | 
| @@ -76,12 +76,12 @@ app.on('ready', () => { | |||||||
|         const dateNoteService = require('./src/services/date_notes'); |         const dateNoteService = require('./src/services/date_notes'); | ||||||
|         const dateUtils = require('./src/services/date_utils'); |         const dateUtils = require('./src/services/date_utils'); | ||||||
|  |  | ||||||
|         const parentNoteId = await dateNoteService.getDateNoteId(dateUtils.nowDate()); |         const parentNote = await dateNoteService.getDateNote(dateUtils.nowDate()); | ||||||
|  |  | ||||||
|         // window may be hidden / not in focus |         // window may be hidden / not in focus | ||||||
|         mainWindow.focus(); |         mainWindow.focus(); | ||||||
|  |  | ||||||
|         mainWindow.webContents.send('create-day-sub-note', parentNoteId); |         mainWindow.webContents.send('create-day-sub-note', parentNote.noteId); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     if (!result) { |     if (!result) { | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| { | { | ||||||
|   "name": "trilium", |   "name": "trilium", | ||||||
|   "description": "Trilium Notes", |   "description": "Trilium Notes", | ||||||
|   "version": "0.10.0-beta", |   "version": "0.10.2-beta", | ||||||
|   "license": "AGPL-3.0-only", |   "license": "AGPL-3.0-only", | ||||||
|   "main": "electron.js", |   "main": "electron.js", | ||||||
|   "repository": { |   "repository": { | ||||||
|   | |||||||
| @@ -1,9 +1,9 @@ | |||||||
| import server from './services/server.js'; | import server from './services/server.js'; | ||||||
|  |  | ||||||
| $(document).ready(() => { | $(document).ready(async () => { | ||||||
|     server.get('migration').then(result => { |     const {appDbVersion, dbVersion} = await server.get('migration'); | ||||||
|         const appDbVersion = result.app_dbVersion; |  | ||||||
|         const dbVersion = result.dbVersion; |     console.log("HI", {appDbVersion, dbVersion}); | ||||||
|  |  | ||||||
|     if (appDbVersion === dbVersion) { |     if (appDbVersion === dbVersion) { | ||||||
|         $("#up-to-date").show(); |         $("#up-to-date").show(); | ||||||
| @@ -14,7 +14,6 @@ $(document).ready(() => { | |||||||
|         $("#app-db-version").html(appDbVersion); |         $("#app-db-version").html(appDbVersion); | ||||||
|         $("#db-version").html(dbVersion); |         $("#db-version").html(dbVersion); | ||||||
|     } |     } | ||||||
|     }); |  | ||||||
| }); | }); | ||||||
|  |  | ||||||
| $("#run-migration").click(async () => { | $("#run-migration").click(async () => { | ||||||
| @@ -38,3 +37,10 @@ $("#run-migration").click(async () => { | |||||||
|         $("#migration-table").append(row); |         $("#migration-table").append(row); | ||||||
|     } |     } | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | // copy of this shortcut to be able to debug migration problems | ||||||
|  | $(document).bind('keydown', 'ctrl+shift+i', () => { | ||||||
|  |     require('electron').remote.getCurrentWindow().toggleDevTools(); | ||||||
|  |  | ||||||
|  |     return false; | ||||||
|  | }); | ||||||
| @@ -8,6 +8,7 @@ import treeUtils from './tree_utils.js'; | |||||||
| import branchPrefixDialog from '../dialogs/branch_prefix.js'; | import branchPrefixDialog from '../dialogs/branch_prefix.js'; | ||||||
| import infoService from "./info.js"; | import infoService from "./info.js"; | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
|  | import syncService from "./sync.js"; | ||||||
|  |  | ||||||
| const $tree = $("#tree"); | const $tree = $("#tree"); | ||||||
|  |  | ||||||
| @@ -103,7 +104,7 @@ const contextMenuOptions = { | |||||||
|     ], |     ], | ||||||
|     beforeOpen: async (event, ui) => { |     beforeOpen: async (event, ui) => { | ||||||
|         const node = $.ui.fancytree.getNode(ui.target); |         const node = $.ui.fancytree.getNode(ui.target); | ||||||
|         const branch = await treeCache.getBranch(branchId); |         const branch = await treeCache.getBranch(node.data.branchId); | ||||||
|         const note = await treeCache.getNote(node.data.noteId); |         const note = await treeCache.getNote(node.data.noteId); | ||||||
|         const parentNote = await treeCache.getNote(branch.parentNoteId); |         const parentNote = await treeCache.getNote(branch.parentNoteId); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -32,18 +32,19 @@ async function requireLibrary(library) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| const dynamicallyLoadedScripts = []; | // we save the promises in case of the same script being required concurrently multiple times | ||||||
|  | const loadedScriptPromises = {}; | ||||||
|  |  | ||||||
| async function requireScript(url) { | async function requireScript(url) { | ||||||
|     if (!dynamicallyLoadedScripts.includes(url)) { |     if (!loadedScriptPromises[url]) { | ||||||
|         dynamicallyLoadedScripts.push(url); |         loadedScriptPromises[url] = $.ajax({ | ||||||
|  |  | ||||||
|         return await $.ajax({ |  | ||||||
|             url: url, |             url: url, | ||||||
|             dataType: "script", |             dataType: "script", | ||||||
|             cache: true |             cache: true | ||||||
|         }) |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     await loadedScriptPromises[url]; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function requireCss(url) { | async function requireCss(url) { | ||||||
|   | |||||||
| @@ -100,7 +100,7 @@ setTimeout(() => { | |||||||
|             lastSyncId: lastSyncId |             lastSyncId: lastSyncId | ||||||
|         })); |         })); | ||||||
|     }, 1000); |     }, 1000); | ||||||
| }, 1000); | }, 0); | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     logError, |     logError, | ||||||
|   | |||||||
| @@ -1,4 +1,3 @@ | |||||||
| import utils from "./utils.js"; |  | ||||||
| import libraryLoader from "./library_loader.js"; | import libraryLoader from "./library_loader.js"; | ||||||
| import bundleService from "./bundle.js"; | import bundleService from "./bundle.js"; | ||||||
| import infoService from "./info.js"; | import infoService from "./info.js"; | ||||||
| @@ -11,15 +10,15 @@ const $noteDetailCode = $('#note-detail-code'); | |||||||
| const $executeScriptButton = $("#execute-script-button"); | const $executeScriptButton = $("#execute-script-button"); | ||||||
|  |  | ||||||
| async function show() { | async function show() { | ||||||
|     if (!codeEditor) { |  | ||||||
|     await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR); |     await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR); | ||||||
|  |  | ||||||
|  |     if (!codeEditor) { | ||||||
|         CodeMirror.keyMap.default["Shift-Tab"] = "indentLess"; |         CodeMirror.keyMap.default["Shift-Tab"] = "indentLess"; | ||||||
|         CodeMirror.keyMap.default["Tab"] = "indentMore"; |         CodeMirror.keyMap.default["Tab"] = "indentMore"; | ||||||
|  |  | ||||||
|         CodeMirror.modeURL = 'libraries/codemirror/mode/%N/%N.js'; |         CodeMirror.modeURL = 'libraries/codemirror/mode/%N/%N.js'; | ||||||
|  |  | ||||||
|         codeEditor = CodeMirror($("#note-detail-code")[0], { |         codeEditor = CodeMirror($noteDetailCode[0], { | ||||||
|             value: "", |             value: "", | ||||||
|             viewportMargin: Infinity, |             viewportMargin: Infinity, | ||||||
|             indentUnit: 4, |             indentUnit: 4, | ||||||
| @@ -38,7 +37,7 @@ async function show() { | |||||||
|  |  | ||||||
|     const currentNote = noteDetailService.getCurrentNote(); |     const currentNote = noteDetailService.getCurrentNote(); | ||||||
|  |  | ||||||
|     // this needs to happen after the element is shown, otherwise the editor won't be refresheds |     // this needs to happen after the element is shown, otherwise the editor won't be refreshed | ||||||
|     codeEditor.setValue(currentNote.content); |     codeEditor.setValue(currentNote.content); | ||||||
|  |  | ||||||
|     const info = CodeMirror.findModeByMIME(currentNote.mime); |     const info = CodeMirror.findModeByMIME(currentNote.mime); | ||||||
| @@ -67,13 +66,13 @@ async function executeCurrentNote() { | |||||||
|         const currentNote = noteDetailService.getCurrentNote(); |         const currentNote = noteDetailService.getCurrentNote(); | ||||||
|  |  | ||||||
|         if (currentNote.mime.endsWith("env=frontend")) { |         if (currentNote.mime.endsWith("env=frontend")) { | ||||||
|             const bundle = await server.get('script/bundle/' + getCurrentNoteId()); |             const bundle = await server.get('script/bundle/' + noteDetailService.getCurrentNoteId()); | ||||||
|  |  | ||||||
|             bundleService.executeBundle(bundle); |             bundleService.executeBundle(bundle); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (currentNote.mime.endsWith("env=backend")) { |         if (currentNote.mime.endsWith("env=backend")) { | ||||||
|             await server.post('script/run/' + getCurrentNoteId()); |             await server.post('script/run/' + noteDetailService.getCurrentNoteId()); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         infoService.showMessage("Note executed"); |         infoService.showMessage("Note executed"); | ||||||
|   | |||||||
| @@ -54,7 +54,11 @@ function ScriptApi(startNote, currentNote) { | |||||||
|         activateNote, |         activateNote, | ||||||
|         getInstanceName: () => window.glob.instanceName, |         getInstanceName: () => window.glob.instanceName, | ||||||
|         runOnServer, |         runOnServer, | ||||||
|         formatDateISO: utils.formatDateISO |         formatDateISO: utils.formatDateISO, | ||||||
|  |         parseDate: utils.parseDate, | ||||||
|  |         showMessage: utils.showMessage, | ||||||
|  |         showError: utils.showError, | ||||||
|  |         reloadTree: treeService.reload | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -85,8 +85,7 @@ async function ajax(url, method, data) { | |||||||
|     }); |     }); | ||||||
| } | } | ||||||
|  |  | ||||||
| setTimeout(() => { | if (utils.isElectron()) { | ||||||
|     if (utils.isElectron()) { |  | ||||||
|     const ipc = require('electron').ipcRenderer; |     const ipc = require('electron').ipcRenderer; | ||||||
|  |  | ||||||
|     ipc.on('server-response', (event, arg) => { |     ipc.on('server-response', (event, arg) => { | ||||||
| @@ -96,8 +95,7 @@ setTimeout(() => { | |||||||
|  |  | ||||||
|         delete reqResolves[arg.requestId]; |         delete reqResolves[arg.requestId]; | ||||||
|     }); |     }); | ||||||
|     } | } | ||||||
| }, 100); |  | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|     get, |     get, | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| import utils from './utils.js'; | import server from './server.js'; | ||||||
| import infoService from "./info.js"; | import infoService from "./info.js"; | ||||||
|  |  | ||||||
| async function syncNow() { | async function syncNow() { | ||||||
| @@ -19,7 +19,7 @@ async function syncNow() { | |||||||
| $("#sync-now-button").click(syncNow); | $("#sync-now-button").click(syncNow); | ||||||
|  |  | ||||||
| async function forceNoteSync(noteId) { | async function forceNoteSync(noteId) { | ||||||
|     const result = await server.post('sync/force-note-sync/' + noteId); |     await server.post('sync/force-note-sync/' + noteId); | ||||||
|  |  | ||||||
|     infoService.showMessage("Note added to sync queue."); |     infoService.showMessage("Note added to sync queue."); | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										7
									
								
								src/public/libraries/jquery.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								src/public/libraries/jquery.min.js
									
									
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| @@ -7,7 +7,7 @@ const appInfo = require('../../services/app_info'); | |||||||
| async function getMigrationInfo() { | async function getMigrationInfo() { | ||||||
|     return { |     return { | ||||||
|         dbVersion: parseInt(await optionService.getOption('dbVersion')), |         dbVersion: parseInt(await optionService.getOption('dbVersion')), | ||||||
|         app_dbVersion: appInfo.dbVersion |         appDbVersion: appInfo.dbVersion | ||||||
|     }; |     }; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -36,9 +36,9 @@ async function uploadImage(req) { | |||||||
|         return [400, "Unknown image type: " + file.mimetype]; |         return [400, "Unknown image type: " + file.mimetype]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const parentNoteId = await dateNoteService.getDateNoteId(req.headers['x-local-date']); |     const parentNote = await dateNoteService.getDateNote(req.headers['x-local-date']); | ||||||
|  |  | ||||||
|     const {note} = await noteService.createNewNote(parentNoteId, { |     const {note} = await noteService.createNewNote(parentNote.noteId, { | ||||||
|         title: "Sender image", |         title: "Sender image", | ||||||
|         content: "", |         content: "", | ||||||
|         target: 'into', |         target: 'into', | ||||||
| @@ -57,9 +57,9 @@ async function uploadImage(req) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function saveNote(req) { | async function saveNote(req) { | ||||||
|     const parentNoteId = await dateNoteService.getDateNoteId(req.headers['x-local-date']); |     const parentNote = await dateNoteService.getDateNote(req.headers['x-local-date']); | ||||||
|  |  | ||||||
|     await noteService.createNewNote(parentNoteId, { |     await noteService.createNewNote(parentNote.noteId, { | ||||||
|         title: req.body.title, |         title: req.body.title, | ||||||
|         content: req.body.content, |         content: req.body.content, | ||||||
|         target: 'into', |         target: 'into', | ||||||
|   | |||||||
| @@ -55,7 +55,7 @@ async function forceNoteSync(req) { | |||||||
|     syncService.sync(); |     syncService.sync(); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getChanged() { | async function getChanged(req) { | ||||||
|     const lastSyncId = parseInt(req.query.lastSyncId); |     const lastSyncId = parseInt(req.query.lastSyncId); | ||||||
|  |  | ||||||
|     return await sql.getRows("SELECT * FROM sync WHERE id > ?", [lastSyncId]); |     return await sql.getRows("SELECT * FROM sync WHERE id > ?", [lastSyncId]); | ||||||
|   | |||||||
| @@ -19,6 +19,7 @@ function init(app) { | |||||||
|  |  | ||||||
|         res.status = function(statusCode) { |         res.status = function(statusCode) { | ||||||
|             res.statusCode = statusCode; |             res.statusCode = statusCode; | ||||||
|  |             return res; | ||||||
|         }; |         }; | ||||||
|  |  | ||||||
|         res.send = function(obj) { |         res.send = function(obj) { | ||||||
|   | |||||||
| @@ -40,22 +40,22 @@ const cls = require('../services/cls'); | |||||||
| const sql = require('../services/sql'); | const sql = require('../services/sql'); | ||||||
| const protectedSessionService = require('../services/protected_session'); | const protectedSessionService = require('../services/protected_session'); | ||||||
|  |  | ||||||
| function apiResultHandler(res, result) { | function apiResultHandler(req, res, result) { | ||||||
|     // if it's an array and first element is integer then we consider this to be [statusCode, response] format |     // if it's an array and first element is integer then we consider this to be [statusCode, response] format | ||||||
|     if (Array.isArray(result) && result.length > 0 && Number.isInteger(result[0])) { |     if (Array.isArray(result) && result.length > 0 && Number.isInteger(result[0])) { | ||||||
|         const [statusCode, response] = result; |         const [statusCode, response] = result; | ||||||
|  |  | ||||||
|         res.status(statusCode).send(response); |         res.status(statusCode).send(response); | ||||||
|  |  | ||||||
|         if (statusCode !== 200) { |         if (statusCode !== 200 && statusCode !== 201 && statusCode !== 204) { | ||||||
|             log.info(`${method} ${path} returned ${statusCode} with response ${JSON.stringify(response)}`); |             log.info(`${req.method} ${req.originalUrl} returned ${statusCode} with response ${JSON.stringify(response)}`); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     else if (result === undefined) { |     else if (result === undefined) { | ||||||
|         res.status(204).send(); |         res.status(204).send(); | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         res.status(200).send(result); |         res.send(result); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -70,13 +70,13 @@ function route(method, path, middleware, routeHandler, resultHandler) { | |||||||
|                 cls.namespace.set('sourceId', req.headers.source_id); |                 cls.namespace.set('sourceId', req.headers.source_id); | ||||||
|                 protectedSessionService.setProtectedSessionId(req); |                 protectedSessionService.setProtectedSessionId(req); | ||||||
|  |  | ||||||
|                 return await sql.doInTransaction(async () => { |                 return await sql.transactional(async () => { | ||||||
|                     return await routeHandler(req, res, next); |                     return await routeHandler(req, res, next); | ||||||
|                 }); |                 }); | ||||||
|             }); |             }); | ||||||
|  |  | ||||||
|             if (resultHandler) { |             if (resultHandler) { | ||||||
|                 resultHandler(res, result); |                 resultHandler(req, res, result); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         catch (e) { |         catch (e) { | ||||||
| @@ -158,6 +158,7 @@ function register(app) { | |||||||
|     apiRoute(GET, '/api/sync/labels/:labelId', syncApiRoute.getLabel); |     apiRoute(GET, '/api/sync/labels/:labelId', syncApiRoute.getLabel); | ||||||
|     apiRoute(GET, '/api/sync/api_tokens/:apiTokenId', syncApiRoute.getApiToken); |     apiRoute(GET, '/api/sync/api_tokens/:apiTokenId', syncApiRoute.getApiToken); | ||||||
|     apiRoute(PUT, '/api/sync/notes', syncApiRoute.updateNote); |     apiRoute(PUT, '/api/sync/notes', syncApiRoute.updateNote); | ||||||
|  |     apiRoute(PUT, '/api/sync/branches', syncApiRoute.updateBranch); | ||||||
|     apiRoute(PUT, '/api/sync/note_revisions', syncApiRoute.updateNoteRevision); |     apiRoute(PUT, '/api/sync/note_revisions', syncApiRoute.updateNoteRevision); | ||||||
|     apiRoute(PUT, '/api/sync/note_reordering', syncApiRoute.updateNoteReordering); |     apiRoute(PUT, '/api/sync/note_reordering', syncApiRoute.updateNoteReordering); | ||||||
|     apiRoute(PUT, '/api/sync/options', syncApiRoute.updateOption); |     apiRoute(PUT, '/api/sync/options', syncApiRoute.updateOption); | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ async function changePassword(currentPassword, newPassword) { | |||||||
|     const newPasswordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(newPassword)); |     const newPasswordVerificationKey = utils.toBase64(await myScryptService.getVerificationHash(newPassword)); | ||||||
|     const decryptedDataKey = await passwordEncryptionService.getDataKey(currentPassword); |     const decryptedDataKey = await passwordEncryptionService.getDataKey(currentPassword); | ||||||
|  |  | ||||||
|     await sql.doInTransaction(async () => { |     await sql.transactional(async () => { | ||||||
|         await passwordEncryptionService.setDataKey(newPassword, decryptedDataKey); |         await passwordEncryptionService.setDataKey(newPassword, decryptedDataKey); | ||||||
|  |  | ||||||
|         await optionService.setOption('passwordVerificationHash', newPasswordVerificationKey); |         await optionService.setOption('passwordVerificationHash', newPasswordVerificationKey); | ||||||
|   | |||||||
| @@ -4,6 +4,7 @@ const sql = require('./sql'); | |||||||
| const noteService = require('./notes'); | const noteService = require('./notes'); | ||||||
| const labelService = require('./labels'); | const labelService = require('./labels'); | ||||||
| const dateUtils = require('./date_utils'); | const dateUtils = require('./date_utils'); | ||||||
|  | const repository = require('./repository'); | ||||||
|  |  | ||||||
| const CALENDAR_ROOT_LABEL = 'calendarRoot'; | const CALENDAR_ROOT_LABEL = 'calendarRoot'; | ||||||
| const YEAR_LABEL = 'yearNote'; | const YEAR_LABEL = 'yearNote'; | ||||||
| @@ -14,117 +15,112 @@ const DAYS = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Satur | |||||||
| const MONTHS = ['January','February','March','April','May','June','July','August','September','October','November','December']; | const MONTHS = ['January','February','March','April','May','June','July','August','September','October','November','December']; | ||||||
|  |  | ||||||
| async function createNote(parentNoteId, noteTitle, noteText) { | async function createNote(parentNoteId, noteTitle, noteText) { | ||||||
|     const {note} = await noteService.createNewNote(parentNoteId, { |     return (await noteService.createNewNote(parentNoteId, { | ||||||
|         title: noteTitle, |         title: noteTitle, | ||||||
|         content: noteText, |         content: noteText, | ||||||
|         target: 'into', |         target: 'into', | ||||||
|         isProtected: false |         isProtected: false | ||||||
|     }); |     })).note; | ||||||
|  |  | ||||||
|     return note.noteId; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getNoteStartingWith(parentNoteId, startsWith) { | async function getNoteStartingWith(parentNoteId, startsWith) { | ||||||
|     return await sql.getValue(`SELECT noteId FROM notes JOIN branches USING(noteId)  |     return await repository.getEntity(`SELECT notes.* FROM notes JOIN branches USING(noteId)  | ||||||
|                                     WHERE parentNoteId = ? AND title LIKE '${startsWith}%' |                                     WHERE parentNoteId = ? AND title LIKE '${startsWith}%' | ||||||
|                                     AND notes.isDeleted = 0 AND isProtected = 0  |                                     AND notes.isDeleted = 0 AND isProtected = 0  | ||||||
|                                     AND branches.isDeleted = 0`, [parentNoteId]); |                                     AND branches.isDeleted = 0`, [parentNoteId]); | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getRootCalendarNoteId() { | async function getRootCalendarNote() { | ||||||
|     let rootNoteId = await sql.getValue(`SELECT notes.noteId FROM notes JOIN labels USING(noteId)  |     let rootNote = await labelService.getNoteWithLabel(CALENDAR_ROOT_LABEL); | ||||||
|               WHERE labels.name = '${CALENDAR_ROOT_LABEL}' AND notes.isDeleted = 0`); |  | ||||||
|  |  | ||||||
|     if (!rootNoteId) { |     if (!rootNote) { | ||||||
|         const {rootNote} = await noteService.createNewNote('root', { |         rootNote = (await noteService.createNewNote('root', { | ||||||
|             title: 'Calendar', |             title: 'Calendar', | ||||||
|             target: 'into', |             target: 'into', | ||||||
|             isProtected: false |             isProtected: false | ||||||
|         }); |         })).note; | ||||||
|  |  | ||||||
|         const rootNoteId = rootNote.noteId; |         await labelService.createLabel(rootNote.noteId, CALENDAR_ROOT_LABEL); | ||||||
|  |  | ||||||
|         await labelService.createLabel(rootNoteId, CALENDAR_ROOT_LABEL); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return rootNoteId; |     return rootNote; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getYearNoteId(dateTimeStr, rootNoteId) { | async function getYearNote(dateTimeStr, rootNote) { | ||||||
|     const yearStr = dateTimeStr.substr(0, 4); |     const yearStr = dateTimeStr.substr(0, 4); | ||||||
|  |  | ||||||
|     let yearNoteId = await labelService.getNoteIdWithLabel(YEAR_LABEL, yearStr); |     let yearNote = await labelService.getNoteWithLabel(YEAR_LABEL, yearStr); | ||||||
|  |  | ||||||
|     if (!yearNoteId) { |     if (!yearNote) { | ||||||
|         yearNoteId = await getNoteStartingWith(rootNoteId, yearStr); |         yearNote = await getNoteStartingWith(rootNote.noteId, yearStr); | ||||||
|  |  | ||||||
|         if (!yearNoteId) { |         if (!yearNote) { | ||||||
|             yearNoteId = await createNote(rootNoteId, yearStr); |             yearNote = await createNote(rootNote.noteId, yearStr); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         await labelService.createLabel(yearNoteId, YEAR_LABEL, yearStr); |         await labelService.createLabel(yearNote.noteId, YEAR_LABEL, yearStr); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return yearNoteId; |     return yearNote; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getMonthNoteId(dateTimeStr, rootNoteId) { | async function getMonthNote(dateTimeStr, rootNote) { | ||||||
|     const monthStr = dateTimeStr.substr(0, 7); |     const monthStr = dateTimeStr.substr(0, 7); | ||||||
|     const monthNumber = dateTimeStr.substr(5, 2); |     const monthNumber = dateTimeStr.substr(5, 2); | ||||||
|  |  | ||||||
|     let monthNoteId = await labelService.getNoteIdWithLabel(MONTH_LABEL, monthStr); |     let monthNote = await labelService.getNoteWithLabel(MONTH_LABEL, monthStr); | ||||||
|  |  | ||||||
|     if (!monthNoteId) { |     if (!monthNote) { | ||||||
|         const yearNoteId = await getYearNoteId(dateTimeStr, rootNoteId); |         const yearNote = await getYearNote(dateTimeStr, rootNote); | ||||||
|  |  | ||||||
|         monthNoteId = await getNoteStartingWith(yearNoteId, monthNumber); |         monthNote = await getNoteStartingWith(yearNote.noteId, monthNumber); | ||||||
|  |  | ||||||
|         if (!monthNoteId) { |         if (!monthNote) { | ||||||
|             const dateObj = dateUtils.parseDate(dateTimeStr); |             const dateObj = dateUtils.parseDate(dateTimeStr); | ||||||
|  |  | ||||||
|             const noteTitle = monthNumber + " - " + MONTHS[dateObj.getMonth()]; |             const noteTitle = monthNumber + " - " + MONTHS[dateObj.getMonth()]; | ||||||
|  |  | ||||||
|             monthNoteId = await createNote(yearNoteId, noteTitle); |             monthNote = await createNote(yearNote.noteId, noteTitle); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         await labelService.createLabel(monthNoteId, MONTH_LABEL, monthStr); |         await labelService.createLabel(monthNote.noteId, MONTH_LABEL, monthStr); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return monthNoteId; |     return monthNote; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getDateNoteId(dateTimeStr, rootNoteId = null) { | async function getDateNote(dateTimeStr, rootNote = null) { | ||||||
|     if (!rootNoteId) { |     if (!rootNote) { | ||||||
|         rootNoteId = await getRootCalendarNoteId(); |         rootNote = await getRootCalendarNote(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const dateStr = dateTimeStr.substr(0, 10); |     const dateStr = dateTimeStr.substr(0, 10); | ||||||
|     const dayNumber = dateTimeStr.substr(8, 2); |     const dayNumber = dateTimeStr.substr(8, 2); | ||||||
|  |  | ||||||
|     let dateNoteId = await labelService.getNoteIdWithLabel(DATE_LABEL, dateStr); |     let dateNote = await labelService.getNoteWithLabel(DATE_LABEL, dateStr); | ||||||
|  |  | ||||||
|     if (!dateNoteId) { |     if (!dateNote) { | ||||||
|         const monthNoteId = await getMonthNoteId(dateTimeStr, rootNoteId); |         const monthNote = await getMonthNote(dateTimeStr, rootNote); | ||||||
|  |  | ||||||
|         dateNoteId = await getNoteStartingWith(monthNoteId, dayNumber); |         dateNote = await getNoteStartingWith(monthNote.noteId, dayNumber); | ||||||
|  |  | ||||||
|         if (!dateNoteId) { |         if (!dateNote) { | ||||||
|             const dateObj = dateUtils.parseDate(dateTimeStr); |             const dateObj = dateUtils.parseDate(dateTimeStr); | ||||||
|  |  | ||||||
|             const noteTitle = dayNumber + " - " + DAYS[dateObj.getDay()]; |             const noteTitle = dayNumber + " - " + DAYS[dateObj.getDay()]; | ||||||
|  |  | ||||||
|             dateNoteId = await createNote(monthNoteId, noteTitle); |             dateNote = await createNote(monthNote.noteId, noteTitle); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         await labelService.createLabel(dateNoteId, DATE_LABEL, dateStr); |         await labelService.createLabel(dateNote.noteId, DATE_LABEL, dateStr); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return dateNoteId; |     return dateNote; | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     getRootCalendarNoteId, |     getRootCalendarNote, | ||||||
|     getYearNoteId, |     getYearNote, | ||||||
|     getMonthNoteId, |     getMonthNote, | ||||||
|     getDateNoteId |     getDateNote | ||||||
| }; | }; | ||||||
| @@ -1,6 +1,5 @@ | |||||||
| "use strict"; | "use strict"; | ||||||
|  |  | ||||||
| const sql = require('./sql'); |  | ||||||
| const repository = require('./repository'); | const repository = require('./repository'); | ||||||
| const Label = require('../entities/label'); | const Label = require('../entities/label'); | ||||||
|  |  | ||||||
| @@ -15,14 +14,6 @@ const BUILTIN_LABELS = [ | |||||||
|     'appCss' |     'appCss' | ||||||
| ]; | ]; | ||||||
|  |  | ||||||
| async function getNoteIdWithLabel(name, value) { |  | ||||||
|     return await sql.getValue(`SELECT notes.noteId FROM notes JOIN labels USING(noteId)  |  | ||||||
|           WHERE notes.isDeleted = 0 |  | ||||||
|                 AND labels.isDeleted = 0 |  | ||||||
|                 AND labels.name = ?  |  | ||||||
|                 AND labels.value = ?`, [name, value]); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function getNotesWithLabel(name, value) { | async function getNotesWithLabel(name, value) { | ||||||
|     let notes; |     let notes; | ||||||
|  |  | ||||||
| @@ -44,11 +35,6 @@ async function getNoteWithLabel(name, value) { | |||||||
|     return notes.length > 0 ? notes[0] : null; |     return notes.length > 0 ? notes[0] : null; | ||||||
| } | } | ||||||
|  |  | ||||||
| async function getNoteIdsWithLabel(name) { |  | ||||||
|     return await sql.getColumn(`SELECT DISTINCT notes.noteId FROM notes JOIN labels USING(noteId)  |  | ||||||
|           WHERE notes.isDeleted = 0 AND labels.isDeleted = 0 AND labels.name = ? AND labels.isDeleted = 0`, [name]); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| async function createLabel(noteId, name, value = "") { | async function createLabel(noteId, name, value = "") { | ||||||
|     return await new Label({ |     return await new Label({ | ||||||
|         noteId: noteId, |         noteId: noteId, | ||||||
| @@ -58,10 +44,8 @@ async function createLabel(noteId, name, value = "") { | |||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = { | module.exports = { | ||||||
|     getNoteIdWithLabel, |  | ||||||
|     getNotesWithLabel, |     getNotesWithLabel, | ||||||
|     getNoteWithLabel, |     getNoteWithLabel, | ||||||
|     getNoteIdsWithLabel, |  | ||||||
|     createLabel, |     createLabel, | ||||||
|     BUILTIN_LABELS |     BUILTIN_LABELS | ||||||
| }; | }; | ||||||
| @@ -45,7 +45,7 @@ async function migrate() { | |||||||
|             // needs to happen outside of the transaction (otherwise it's a NO-OP) |             // needs to happen outside of the transaction (otherwise it's a NO-OP) | ||||||
|             await sql.execute("PRAGMA foreign_keys = OFF"); |             await sql.execute("PRAGMA foreign_keys = OFF"); | ||||||
|  |  | ||||||
|             await sql.doInTransaction(async () => { |             await sql.transactional(async () => { | ||||||
|                 if (mig.type === 'sql') { |                 if (mig.type === 'sql') { | ||||||
|                     const migrationSql = fs.readFileSync(resourceDir.MIGRATIONS_DIR + "/" + mig.file).toString('utf8'); |                     const migrationSql = fs.readFileSync(resourceDir.MIGRATIONS_DIR + "/" + mig.file).toString('utf8'); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -50,7 +50,7 @@ async function updateEntity(entity) { | |||||||
|  |  | ||||||
|     delete clone.jsonContent; |     delete clone.jsonContent; | ||||||
|  |  | ||||||
|     await sql.doInTransaction(async () => { |     await sql.transactional(async () => { | ||||||
|         await sql.replace(entity.constructor.tableName, clone); |         await sql.replace(entity.constructor.tableName, clone); | ||||||
|  |  | ||||||
|         const primaryKey = entity[entity.constructor.primaryKeyName]; |         const primaryKey = entity[entity.constructor.primaryKeyName]; | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| const scriptService = require('./script'); | const scriptService = require('./script'); | ||||||
| const repository = require('./repository'); | const repository = require('./repository'); | ||||||
| const cls = require('./cls'); | const cls = require('./cls'); | ||||||
|  | const sqlInit = require('./sql_init'); | ||||||
|  |  | ||||||
| async function runNotesWithLabel(runAttrValue) { | async function runNotesWithLabel(runAttrValue) { | ||||||
|     const notes = await repository.getEntities(` |     const notes = await repository.getEntities(` | ||||||
| @@ -19,8 +20,10 @@ async function runNotesWithLabel(runAttrValue) { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| setTimeout(cls.wrap(() => runNotesWithLabel('backendStartup')), 10 * 1000); | sqlInit.dbReady.then(() => { | ||||||
|  |     setTimeout(cls.wrap(() => runNotesWithLabel('backendStartup')), 10 * 1000); | ||||||
|  |  | ||||||
| setInterval(cls.wrap(() => runNotesWithLabel('hourly')), 3600 * 1000); |     setInterval(cls.wrap(() => runNotesWithLabel('hourly')), 3600 * 1000); | ||||||
|  |  | ||||||
| setInterval(cls.wrap(() => runNotesWithLabel('daily')), 24 * 3600 * 1000); |     setInterval(cls.wrap(() => runNotesWithLabel('daily')), 24 * 3600 * 1000); | ||||||
|  | }); | ||||||
| @@ -27,7 +27,7 @@ async function executeBundle(bundle, startNote) { | |||||||
|         return await execute(ctx, script, ''); |         return await execute(ctx, script, ''); | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         return await sql.doInTransaction(async () => execute(ctx, script, '')); |         return await sql.transactional(async () => execute(ctx, script, '')); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -56,10 +56,10 @@ function ScriptApi(startNote, currentNote) { | |||||||
|  |  | ||||||
|     this.log = message => log.info(`Script ${currentNote.noteId}: ${message}`); |     this.log = message => log.info(`Script ${currentNote.noteId}: ${message}`); | ||||||
|  |  | ||||||
|     this.getRootCalendarNoteId = dateNoteService.getRootCalendarNoteId; |     this.getRootCalendarNote = dateNoteService.getRootCalendarNote; | ||||||
|     this.getDateNoteId = dateNoteService.getDateNoteId; |     this.getDateNote = dateNoteService.getDateNote; | ||||||
|  |  | ||||||
|     this.transactional = sql.doInTransaction; |     this.transactional = sql.transactional; | ||||||
| } | } | ||||||
|  |  | ||||||
| module.exports = ScriptContext; | module.exports = ScriptContext; | ||||||
| @@ -122,7 +122,7 @@ async function wrap(func) { | |||||||
| let transactionActive = false; | let transactionActive = false; | ||||||
| let transactionPromise = null; | let transactionPromise = null; | ||||||
|  |  | ||||||
| async function doInTransaction(func) { | async function transactional(func) { | ||||||
|     if (cls.namespace.get('isInTransaction')) { |     if (cls.namespace.get('isInTransaction')) { | ||||||
|         return await func(); |         return await func(); | ||||||
|     } |     } | ||||||
| @@ -181,5 +181,5 @@ module.exports = { | |||||||
|     getColumn, |     getColumn, | ||||||
|     execute, |     execute, | ||||||
|     executeScript, |     executeScript, | ||||||
|     doInTransaction |     transactional | ||||||
| }; | }; | ||||||
| @@ -58,7 +58,7 @@ async function createInitialDatabase() { | |||||||
|     const imagesSql = fs.readFileSync(resourceDir.DB_INIT_DIR + '/main_images.sql', 'UTF-8'); |     const imagesSql = fs.readFileSync(resourceDir.DB_INIT_DIR + '/main_images.sql', 'UTF-8'); | ||||||
|     const notesImageSql = fs.readFileSync(resourceDir.DB_INIT_DIR + '/main_note_images.sql', 'UTF-8'); |     const notesImageSql = fs.readFileSync(resourceDir.DB_INIT_DIR + '/main_note_images.sql', 'UTF-8'); | ||||||
|  |  | ||||||
|     await sql.doInTransaction(async () => { |     await sql.transactional(async () => { | ||||||
|         await sql.executeScript(schema); |         await sql.executeScript(schema); | ||||||
|         await sql.executeScript(notesSql); |         await sql.executeScript(notesSql); | ||||||
|         await sql.executeScript(notesTreeSql); |         await sql.executeScript(notesTreeSql); | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ async function updateNote(entity, sourceId) { | |||||||
|     const origNote = await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [entity.noteId]); |     const origNote = await sql.getRow("SELECT * FROM notes WHERE noteId = ?", [entity.noteId]); | ||||||
|  |  | ||||||
|     if (!origNote || origNote.dateModified <= entity.dateModified) { |     if (!origNote || origNote.dateModified <= entity.dateModified) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.transactional(async () => { | ||||||
|             await sql.replace("notes", entity); |             await sql.replace("notes", entity); | ||||||
|  |  | ||||||
|             await syncTableService.addNoteSync(entity.noteId, sourceId); |             await syncTableService.addNoteSync(entity.noteId, sourceId); | ||||||
| @@ -29,7 +29,7 @@ async function updateNote(entity, sourceId) { | |||||||
| async function updateBranch(entity, sourceId) { | async function updateBranch(entity, sourceId) { | ||||||
|     const orig = await sql.getRowOrNull("SELECT * FROM branches WHERE branchId = ?", [entity.branchId]); |     const orig = await sql.getRowOrNull("SELECT * FROM branches WHERE branchId = ?", [entity.branchId]); | ||||||
|  |  | ||||||
|     await sql.doInTransaction(async () => { |     await sql.transactional(async () => { | ||||||
|         if (orig === null || orig.dateModified < entity.dateModified) { |         if (orig === null || orig.dateModified < entity.dateModified) { | ||||||
|             delete entity.isExpanded; |             delete entity.isExpanded; | ||||||
|  |  | ||||||
| @@ -45,7 +45,7 @@ async function updateBranch(entity, sourceId) { | |||||||
| async function updateNoteRevision(entity, sourceId) { | async function updateNoteRevision(entity, sourceId) { | ||||||
|     const orig = await sql.getRowOrNull("SELECT * FROM note_revisions WHERE noteRevisionId = ?", [entity.noteRevisionId]); |     const orig = await sql.getRowOrNull("SELECT * FROM note_revisions WHERE noteRevisionId = ?", [entity.noteRevisionId]); | ||||||
|  |  | ||||||
|     await sql.doInTransaction(async () => { |     await sql.transactional(async () => { | ||||||
|         // we update note revision even if date modified to is the same because the only thing which might have changed |         // we update note revision even if date modified to is the same because the only thing which might have changed | ||||||
|         // is the protected status (and correnspondingly title and content) which doesn't affect the dateModifiedTo |         // is the protected status (and correnspondingly title and content) which doesn't affect the dateModifiedTo | ||||||
|         if (orig === null || orig.dateModifiedTo <= entity.dateModifiedTo) { |         if (orig === null || orig.dateModifiedTo <= entity.dateModifiedTo) { | ||||||
| @@ -59,7 +59,7 @@ async function updateNoteRevision(entity, sourceId) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function updateNoteReordering(entity, sourceId) { | async function updateNoteReordering(entity, sourceId) { | ||||||
|     await sql.doInTransaction(async () => { |     await sql.transactional(async () => { | ||||||
|         Object.keys(entity.ordering).forEach(async key => { |         Object.keys(entity.ordering).forEach(async key => { | ||||||
|             await sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?", [entity.ordering[key], key]); |             await sql.execute("UPDATE branches SET notePosition = ? WHERE branchId = ?", [entity.ordering[key], key]); | ||||||
|         }); |         }); | ||||||
| @@ -75,7 +75,7 @@ async function updateOptions(entity, sourceId) { | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     await sql.doInTransaction(async () => { |     await sql.transactional(async () => { | ||||||
|         if (orig === null || orig.dateModified < entity.dateModified) { |         if (orig === null || orig.dateModified < entity.dateModified) { | ||||||
|             await sql.replace('options', entity); |             await sql.replace('options', entity); | ||||||
|  |  | ||||||
| @@ -90,7 +90,7 @@ async function updateRecentNotes(entity, sourceId) { | |||||||
|     const orig = await sql.getRowOrNull("SELECT * FROM recent_notes WHERE branchId = ?", [entity.branchId]); |     const orig = await sql.getRowOrNull("SELECT * FROM recent_notes WHERE branchId = ?", [entity.branchId]); | ||||||
|  |  | ||||||
|     if (orig === null || orig.dateAccessed < entity.dateAccessed) { |     if (orig === null || orig.dateAccessed < entity.dateAccessed) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.transactional(async () => { | ||||||
|             await sql.replace('recent_notes', entity); |             await sql.replace('recent_notes', entity); | ||||||
|  |  | ||||||
|             await syncTableService.addRecentNoteSync(entity.branchId, sourceId); |             await syncTableService.addRecentNoteSync(entity.branchId, sourceId); | ||||||
| @@ -106,7 +106,7 @@ async function updateImage(entity, sourceId) { | |||||||
|     const origImage = await sql.getRow("SELECT * FROM images WHERE imageId = ?", [entity.imageId]); |     const origImage = await sql.getRow("SELECT * FROM images WHERE imageId = ?", [entity.imageId]); | ||||||
|  |  | ||||||
|     if (!origImage || origImage.dateModified <= entity.dateModified) { |     if (!origImage || origImage.dateModified <= entity.dateModified) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.transactional(async () => { | ||||||
|             await sql.replace("images", entity); |             await sql.replace("images", entity); | ||||||
|  |  | ||||||
|             await syncTableService.addImageSync(entity.imageId, sourceId); |             await syncTableService.addImageSync(entity.imageId, sourceId); | ||||||
| @@ -120,7 +120,7 @@ async function updateNoteImage(entity, sourceId) { | |||||||
|     const origNoteImage = await sql.getRow("SELECT * FROM note_images WHERE noteImageId = ?", [entity.noteImageId]); |     const origNoteImage = await sql.getRow("SELECT * FROM note_images WHERE noteImageId = ?", [entity.noteImageId]); | ||||||
|  |  | ||||||
|     if (!origNoteImage || origNoteImage.dateModified <= entity.dateModified) { |     if (!origNoteImage || origNoteImage.dateModified <= entity.dateModified) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.transactional(async () => { | ||||||
|             await sql.replace("note_images", entity); |             await sql.replace("note_images", entity); | ||||||
|  |  | ||||||
|             await syncTableService.addNoteImageSync(entity.noteImageId, sourceId); |             await syncTableService.addNoteImageSync(entity.noteImageId, sourceId); | ||||||
| @@ -134,7 +134,7 @@ async function updateLabel(entity, sourceId) { | |||||||
|     const origLabel = await sql.getRow("SELECT * FROM labels WHERE labelId = ?", [entity.labelId]); |     const origLabel = await sql.getRow("SELECT * FROM labels WHERE labelId = ?", [entity.labelId]); | ||||||
|  |  | ||||||
|     if (!origLabel || origLabel.dateModified <= entity.dateModified) { |     if (!origLabel || origLabel.dateModified <= entity.dateModified) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.transactional(async () => { | ||||||
|             await sql.replace("labels", entity); |             await sql.replace("labels", entity); | ||||||
|  |  | ||||||
|             await syncTableService.addLabelSync(entity.labelId, sourceId); |             await syncTableService.addLabelSync(entity.labelId, sourceId); | ||||||
| @@ -148,7 +148,7 @@ async function updateApiToken(entity, sourceId) { | |||||||
|     const apiTokenId = await sql.getRow("SELECT * FROM api_tokens WHERE apiTokenId = ?", [entity.apiTokenId]); |     const apiTokenId = await sql.getRow("SELECT * FROM api_tokens WHERE apiTokenId = ?", [entity.apiTokenId]); | ||||||
|  |  | ||||||
|     if (!apiTokenId) { |     if (!apiTokenId) { | ||||||
|         await sql.doInTransaction(async () => { |         await sql.transactional(async () => { | ||||||
|             await sql.replace("api_tokens", entity); |             await sql.replace("api_tokens", entity); | ||||||
|  |  | ||||||
|             await syncTableService.addApiTokenSync(entity.apiTokenId, sourceId); |             await syncTableService.addApiTokenSync(entity.apiTokenId, sourceId); | ||||||
|   | |||||||
| @@ -77,7 +77,7 @@ async function loadSubTreeNoteIds(parentNoteId, subTreeNoteIds) { | |||||||
| } | } | ||||||
|  |  | ||||||
| async function sortNotesAlphabetically(parentNoteId) { | async function sortNotesAlphabetically(parentNoteId) { | ||||||
|     await sql.doInTransaction(async () => { |     await sql.transactional(async () => { | ||||||
|         const notes = await sql.getRows(`SELECT branchId, noteId, title, isProtected  |         const notes = await sql.getRows(`SELECT branchId, noteId, title, isProtected  | ||||||
|                                        FROM notes JOIN branches USING(noteId)  |                                        FROM notes JOIN branches USING(noteId)  | ||||||
|                                        WHERE branches.isDeleted = 0 AND parentNoteId = ?`, [parentNoteId]); |                                        WHERE branches.isDeleted = 0 AND parentNoteId = ?`, [parentNoteId]); | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								src/www
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								src/www
									
									
									
									
									
								
							| @@ -18,8 +18,6 @@ const log = require('./services/log'); | |||||||
| const appInfo = require('./services/app_info'); | const appInfo = require('./services/app_info'); | ||||||
| const messagingService = require('./services/messaging'); | const messagingService = require('./services/messaging'); | ||||||
| const utils = require('./services/utils'); | const utils = require('./services/utils'); | ||||||
| const sql = require('./services/sql'); |  | ||||||
| const sqlInit = require('./services/sql_init'); |  | ||||||
|  |  | ||||||
| const port = normalizePort(config['Network']['port'] || '3000'); | const port = normalizePort(config['Network']['port'] || '3000'); | ||||||
| app.set('port', port); | app.set('port', port); | ||||||
| @@ -56,7 +54,7 @@ httpServer.listen(port); | |||||||
| httpServer.on('error', onError); | httpServer.on('error', onError); | ||||||
| httpServer.on('listening', onListening); | httpServer.on('listening', onListening); | ||||||
|  |  | ||||||
| sqlInit.dbReady.then(() => messagingService.init(httpServer, sessionParser)); | messagingService.init(httpServer, sessionParser); | ||||||
|  |  | ||||||
| if (utils.isElectron()) { | if (utils.isElectron()) { | ||||||
|     const electronRouting = require('./routes/electron'); |     const electronRouting = require('./routes/electron'); | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ | |||||||
|     <content url="file://$MODULE_DIR$"> |     <content url="file://$MODULE_DIR$"> | ||||||
|       <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> |       <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||||||
|       <sourceFolder url="file://$MODULE_DIR$/src/public" isTestSource="false" /> |       <sourceFolder url="file://$MODULE_DIR$/src/public" isTestSource="false" /> | ||||||
|  |       <excludeFolder url="file://$MODULE_DIR$/dist" /> | ||||||
|     </content> |     </content> | ||||||
|     <orderEntry type="inheritedJdk" /> |     <orderEntry type="inheritedJdk" /> | ||||||
|     <orderEntry type="sourceFolder" forTests="false" /> |     <orderEntry type="sourceFolder" forTests="false" /> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user