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();
}
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) {

View file

@ -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 <kbd>Ctrl+P</kbd>", cmd: "insertChildNote", uiIcon: "ui-icon-plus"},
{title: "Delete <kbd>Ctrl+Del</kbd>", cmd: "delete", uiIcon: "ui-icon-trash"},
{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: "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);

View file

@ -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',

View file

@ -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 {

View file

@ -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);

View file

@ -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) {

View file

@ -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);

View file

@ -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;