diff --git a/src/entities/label.js b/src/entities/label.js
index 5c346c511..1f1595b53 100644
--- a/src/entities/label.js
+++ b/src/entities/label.js
@@ -18,13 +18,13 @@ class Label extends Entity {
this.labelId = utils.newLabelId();
}
- if (this.value) {
+ if (!this.value) {
// null value isn't allowed
this.value = "";
}
if (this.position === undefined) {
- this.position = 1 + await sql.getValue(`SELECT COALESCE(MAX(position), 0) FROM labels WHERE noteId = ?`, [noteId]);
+ this.position = 1 + await sql.getValue(`SELECT COALESCE(MAX(position), 0) FROM labels WHERE noteId = ?`, [this.noteId]);
}
if (!this.isDeleted) {
diff --git a/src/public/javascripts/dialogs/edit_tree_prefix.js b/src/public/javascripts/dialogs/branch_prefix.js
similarity index 100%
rename from src/public/javascripts/dialogs/edit_tree_prefix.js
rename to src/public/javascripts/dialogs/branch_prefix.js
diff --git a/src/public/javascripts/services/context_menu.js b/src/public/javascripts/services/context_menu.js
index 61e55821a..67dbd1820 100644
--- a/src/public/javascripts/services/context_menu.js
+++ b/src/public/javascripts/services/context_menu.js
@@ -5,7 +5,7 @@ import messagingService from './messaging.js';
import protectedSessionService from './protected_session.js';
import treeChangesService from './branches.js';
import treeUtils from './tree_utils.js';
-import editTreePrefixDialog from '../dialogs/edit_tree_prefix.js';
+import branchPrefixDialog from '../dialogs/branch_prefix.js';
import infoService from "./info.js";
import treeCache from "./tree_cache.js";
@@ -83,7 +83,7 @@ const contextMenuOptions = {
{title: "Insert child note Ctrl+P", cmd: "insertChildNote", uiIcon: "ui-icon-plus"},
{title: "Delete Ctrl+Del", cmd: "delete", uiIcon: "ui-icon-trash"},
{title: "----"},
- {title: "Edit tree prefix F2", cmd: "editTreePrefix", uiIcon: "ui-icon-pencil"},
+ {title: "Edit branch prefix F2", cmd: "editBranchPrefix", uiIcon: "ui-icon-pencil"},
{title: "----"},
{title: "Protect branch", cmd: "protectBranch", uiIcon: "ui-icon-locked"},
{title: "Unprotect branch", cmd: "unprotectBranch", uiIcon: "ui-icon-unlocked"},
@@ -134,8 +134,8 @@ const contextMenuOptions = {
else if (ui.cmd === "insertChildNote") {
treeService.createNote(node, node.data.noteId, 'into');
}
- else if (ui.cmd === "editTreePrefix") {
- editTreePrefixDialog.showDialog(node);
+ else if (ui.cmd === "editBranchPrefix") {
+ branchPrefixDialog.showDialog(node);
}
else if (ui.cmd === "protectBranch") {
protectedSessionService.protectBranch(node.data.noteId, true);
diff --git a/src/public/javascripts/services/file.js b/src/public/javascripts/services/file.js
index 20052e110..bc222101f 100644
--- a/src/public/javascripts/services/file.js
+++ b/src/public/javascripts/services/file.js
@@ -11,7 +11,7 @@ $("#file-upload").change(async function() {
formData.append('upload', this.files[0]);
const resp = await $.ajax({
- url: baseApiUrl + 'files/upload/' + noteDetailService.getCurrentNoteId(),
+ url: baseApiUrl + 'notes/' + noteDetailService.getCurrentNoteId() + '/upload',
headers: server.getHeaders(),
data: formData,
type: 'POST',
diff --git a/src/public/javascripts/services/note_detail_file.js b/src/public/javascripts/services/note_detail_file.js
index 84a03f6be..6176538f2 100644
--- a/src/public/javascripts/services/note_detail_file.js
+++ b/src/public/javascripts/services/note_detail_file.js
@@ -39,8 +39,8 @@ $fileOpen.click(() => {
function getFileUrl() {
// electron needs absolute URL so we extract current host, port, protocol
- return utils.getHost() + "/api/files/download/" + noteDetailService.getCurrentNoteId()
- + "?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
+ return utils.getHost() + "/api/notes/" + noteDetailService.getCurrentNoteId()
+ + "/download?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
}
export default {
diff --git a/src/public/javascripts/services/tree_keybindings.js b/src/public/javascripts/services/tree_keybindings.js
index 062fdbf89..e811e65cb 100644
--- a/src/public/javascripts/services/tree_keybindings.js
+++ b/src/public/javascripts/services/tree_keybindings.js
@@ -3,7 +3,7 @@ import utils from "./utils.js";
import treeChangesService from "./branches.js";
import contextMenuService from "./context_menu.js";
import treeService from "./tree.js";
-import editTreePrefixDialog from "../dialogs/edit_tree_prefix.js";
+import editBranchPrefixDialog from "../dialogs/branch_prefix.js";
const keyBindings = {
"del": node => {
@@ -67,7 +67,7 @@ const keyBindings = {
return false;
},
"f2": node => {
- editTreePrefixDialog.showDialog(node);
+ editBranchPrefixDialog.showDialog(node);
},
"alt+-": node => {
treeService.collapseTree(node);
diff --git a/src/routes/api/import.js b/src/routes/api/import.js
index 8c8ad4db2..ca5c1b64c 100644
--- a/src/routes/api/import.js
+++ b/src/routes/api/import.js
@@ -86,18 +86,18 @@ async function parseImportFile(file) {
}
async function importTar(req) {
- const noteId = req.params.noteId;
+ const parentNoteId = req.params.parentNoteId;
const file = req.file;
- const parentNote = await repository.getNote(noteId);
+ const parentNote = await repository.getNote(parentNoteId);
if (!parentNote) {
- return [404, `Note ${noteId} doesn't exist.`];
+ return [404, `Note ${parentNoteId} doesn't exist.`];
}
const files = await parseImportFile(file);
- await importNotes(files, noteId);
+ await importNotes(files, parentNoteId);
}
async function importNotes(files, parentNoteId) {
diff --git a/src/routes/routes.js b/src/routes/routes.js
index a7aaffdaa..32f03feba 100644
--- a/src/routes/routes.js
+++ b/src/routes/routes.js
@@ -119,13 +119,21 @@ function register(app) {
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);
+ route(POST, '/api/notes/:parentNoteId/import', [auth.checkApiAuthOrElectron, uploadMiddleware], importRoute.importTar, apiResultHandler);
+
+ route(POST, '/api/notes/:parentNoteId/upload', [auth.checkApiAuthOrElectron, uploadMiddleware],
+ filesRoute.uploadFile, apiResultHandler);
+
+ route(GET, '/api/notes/:noteId/download', [auth.checkApiAuthOrElectron], filesRoute.downloadFile);
apiRoute(GET, '/api/notes/:noteId/labels', labelsRoute.getNoteLabels);
apiRoute(PUT, '/api/notes/:noteId/labels', labelsRoute.updateNoteLabels);
apiRoute(GET, '/api/labels/names', labelsRoute.getAllLabelNames);
apiRoute(GET, '/api/labels/values/:labelName', labelsRoute.getValuesForLabel);
+ route(GET, '/api/images/:imageId/:filename', [auth.checkApiAuthOrElectron], imageRoute.returnImage);
+ route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware], imageRoute.uploadImage, apiResultHandler);
+
apiRoute(GET, '/api/recent-changes', recentChangesApiRoute.getRecentChanges);
apiRoute(GET, '/api/options', optionsApiRoute.getOptions);
@@ -174,9 +182,6 @@ function register(app) {
apiRoute(POST, '/api/cleanup/cleanup-unused-images', cleanupRoute.cleanupUnusedImages);
apiRoute(POST, '/api/cleanup/vacuum-database', cleanupRoute.vacuumDatabase);
- route(GET, '/api/images/:imageId/:filename', [auth.checkApiAuthOrElectron], imageRoute.returnImage);
- route(POST, '/api/images', [auth.checkApiAuthOrElectron, uploadMiddleware], imageRoute.uploadImage, apiResultHandler);
-
apiRoute(POST, '/api/script/exec', scriptRoute.exec);
apiRoute(POST, '/api/script/run/:noteId', scriptRoute.run);
apiRoute(GET, '/api/script/startup', scriptRoute.getStartupBundles);
@@ -186,11 +191,6 @@ function register(app) {
route(POST, '/api/sender/image', [auth.checkSenderToken], senderRoute.uploadImage, apiResultHandler);
route(POST, '/api/sender/note', [auth.checkSenderToken], senderRoute.saveNote, apiResultHandler);
- route(POST, '/api/files/upload/:parentNoteId', [auth.checkApiAuthOrElectron, uploadMiddleware],
- filesRoute.uploadFile, apiResultHandler);
-
- route(GET, '/api/files/download/:noteId', [auth.checkApiAuthOrElectron], filesRoute.downloadFile);
-
apiRoute(GET, '/api/search/:searchString', searchRoute.searchNotes);
apiRoute(POST, '/api/search/:searchString', searchRoute.saveSearchToNote);
diff --git a/src/services/sql.js b/src/services/sql.js
index 271f1ae19..a85044feb 100644
--- a/src/services/sql.js
+++ b/src/services/sql.js
@@ -193,13 +193,8 @@ let transactionPromise = null;
async function doInTransaction(func) {
if (cls.namespace.get('isInTransaction')) {
- console.log("Transaction already active");
-
return await func();
}
- else {
- console.log("Starting new transaction");
- }
while (transactionActive) {
await transactionPromise;