continuing in API review

This commit is contained in:
azivner 2018-04-01 20:50:58 -04:00
parent a066c6fe2b
commit c765dbc5cf
9 changed files with 24 additions and 29 deletions

View file

@ -18,13 +18,13 @@ class Label extends Entity {
this.labelId = utils.newLabelId(); this.labelId = utils.newLabelId();
} }
if (this.value) { if (!this.value) {
// null value isn't allowed // null value isn't allowed
this.value = ""; this.value = "";
} }
if (this.position === undefined) { 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) { if (!this.isDeleted) {

View file

@ -5,7 +5,7 @@ import messagingService from './messaging.js';
import protectedSessionService from './protected_session.js'; import protectedSessionService from './protected_session.js';
import treeChangesService from './branches.js'; import treeChangesService from './branches.js';
import treeUtils from './tree_utils.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 infoService from "./info.js";
import treeCache from "./tree_cache.js"; import treeCache from "./tree_cache.js";
@ -83,7 +83,7 @@ const contextMenuOptions = {
{title: "Insert child note <kbd>Ctrl+P</kbd>", cmd: "insertChildNote", uiIcon: "ui-icon-plus"}, {title: "Insert child note <kbd>Ctrl+P</kbd>", cmd: "insertChildNote", uiIcon: "ui-icon-plus"},
{title: "Delete <kbd>Ctrl+Del</kbd>", cmd: "delete", uiIcon: "ui-icon-trash"}, {title: "Delete <kbd>Ctrl+Del</kbd>", cmd: "delete", uiIcon: "ui-icon-trash"},
{title: "----"}, {title: "----"},
{title: "Edit tree prefix <kbd>F2</kbd>", cmd: "editTreePrefix", uiIcon: "ui-icon-pencil"}, {title: "Edit branch prefix <kbd>F2</kbd>", cmd: "editBranchPrefix", uiIcon: "ui-icon-pencil"},
{title: "----"}, {title: "----"},
{title: "Protect branch", cmd: "protectBranch", uiIcon: "ui-icon-locked"}, {title: "Protect branch", cmd: "protectBranch", uiIcon: "ui-icon-locked"},
{title: "Unprotect branch", cmd: "unprotectBranch", uiIcon: "ui-icon-unlocked"}, {title: "Unprotect branch", cmd: "unprotectBranch", uiIcon: "ui-icon-unlocked"},
@ -134,8 +134,8 @@ const contextMenuOptions = {
else if (ui.cmd === "insertChildNote") { else if (ui.cmd === "insertChildNote") {
treeService.createNote(node, node.data.noteId, 'into'); treeService.createNote(node, node.data.noteId, 'into');
} }
else if (ui.cmd === "editTreePrefix") { else if (ui.cmd === "editBranchPrefix") {
editTreePrefixDialog.showDialog(node); branchPrefixDialog.showDialog(node);
} }
else if (ui.cmd === "protectBranch") { else if (ui.cmd === "protectBranch") {
protectedSessionService.protectBranch(node.data.noteId, true); protectedSessionService.protectBranch(node.data.noteId, true);

View file

@ -11,7 +11,7 @@ $("#file-upload").change(async function() {
formData.append('upload', this.files[0]); formData.append('upload', this.files[0]);
const resp = await $.ajax({ const resp = await $.ajax({
url: baseApiUrl + 'files/upload/' + noteDetailService.getCurrentNoteId(), url: baseApiUrl + 'notes/' + noteDetailService.getCurrentNoteId() + '/upload',
headers: server.getHeaders(), headers: server.getHeaders(),
data: formData, data: formData,
type: 'POST', type: 'POST',

View file

@ -39,8 +39,8 @@ $fileOpen.click(() => {
function getFileUrl() { function getFileUrl() {
// electron needs absolute URL so we extract current host, port, protocol // electron needs absolute URL so we extract current host, port, protocol
return utils.getHost() + "/api/files/download/" + noteDetailService.getCurrentNoteId() return utils.getHost() + "/api/notes/" + noteDetailService.getCurrentNoteId()
+ "?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId()); + "/download?protectedSessionId=" + encodeURIComponent(protectedSessionHolder.getProtectedSessionId());
} }
export default { export default {

View file

@ -3,7 +3,7 @@ import utils from "./utils.js";
import treeChangesService from "./branches.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 editBranchPrefixDialog from "../dialogs/branch_prefix.js";
const keyBindings = { const keyBindings = {
"del": node => { "del": node => {
@ -67,7 +67,7 @@ const keyBindings = {
return false; return false;
}, },
"f2": node => { "f2": node => {
editTreePrefixDialog.showDialog(node); editBranchPrefixDialog.showDialog(node);
}, },
"alt+-": node => { "alt+-": node => {
treeService.collapseTree(node); treeService.collapseTree(node);

View file

@ -86,18 +86,18 @@ async function parseImportFile(file) {
} }
async function importTar(req) { async function importTar(req) {
const noteId = req.params.noteId; const parentNoteId = req.params.parentNoteId;
const file = req.file; const file = req.file;
const parentNote = await repository.getNote(noteId); const parentNote = await repository.getNote(parentNoteId);
if (!parentNote) { if (!parentNote) {
return [404, `Note ${noteId} doesn't exist.`]; return [404, `Note ${parentNoteId} doesn't exist.`];
} }
const files = await parseImportFile(file); const files = await parseImportFile(file);
await importNotes(files, noteId); await importNotes(files, parentNoteId);
} }
async function importNotes(files, parentNoteId) { async function importNotes(files, parentNoteId) {

View file

@ -119,13 +119,21 @@ function register(app) {
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(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(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);
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/recent-changes', recentChangesApiRoute.getRecentChanges);
apiRoute(GET, '/api/options', optionsApiRoute.getOptions); 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/cleanup-unused-images', cleanupRoute.cleanupUnusedImages);
apiRoute(POST, '/api/cleanup/vacuum-database', cleanupRoute.vacuumDatabase); 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/exec', scriptRoute.exec);
apiRoute(POST, '/api/script/run/:noteId', scriptRoute.run); apiRoute(POST, '/api/script/run/:noteId', scriptRoute.run);
apiRoute(GET, '/api/script/startup', scriptRoute.getStartupBundles); 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/image', [auth.checkSenderToken], senderRoute.uploadImage, apiResultHandler);
route(POST, '/api/sender/note', [auth.checkSenderToken], senderRoute.saveNote, 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(GET, '/api/search/:searchString', searchRoute.searchNotes);
apiRoute(POST, '/api/search/:searchString', searchRoute.saveSearchToNote); apiRoute(POST, '/api/search/:searchString', searchRoute.saveSearchToNote);

View file

@ -193,13 +193,8 @@ let transactionPromise = null;
async function doInTransaction(func) { async function doInTransaction(func) {
if (cls.namespace.get('isInTransaction')) { if (cls.namespace.get('isInTransaction')) {
console.log("Transaction already active");
return await func(); return await func();
} }
else {
console.log("Starting new transaction");
}
while (transactionActive) { while (transactionActive) {
await transactionPromise; await transactionPromise;