mirror of
https://github.com/zadam/trilium.git
synced 2025-11-18 03:00:41 +01:00
changes in API format
This commit is contained in:
@@ -105,10 +105,20 @@ async function deleteBranch(req) {
|
||||
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 = {
|
||||
moveBranchToParent,
|
||||
moveBranchBeforeNote,
|
||||
moveBranchAfterNote,
|
||||
setExpanded,
|
||||
deleteBranch
|
||||
deleteBranch,
|
||||
setPrefix
|
||||
};
|
||||
@@ -1,17 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
const sql = require('../../services/sql');
|
||||
const utils = require('../../services/utils');
|
||||
const sync_table = require('../../services/sync_table');
|
||||
const tree = require('../../services/tree');
|
||||
const Branch = require('../../entities/branch');
|
||||
|
||||
async function cloneNoteToParent(req) {
|
||||
const noteId = req.params.noteId;
|
||||
const parentNoteId = req.params.parentNoteId;
|
||||
const childNoteId = req.params.childNoteId;
|
||||
const prefix = req.body.prefix;
|
||||
|
||||
const validationResult = await tree.validateParentChild(parentNoteId, childNoteId);
|
||||
const validationResult = await tree.validateParentChild(parentNoteId, noteId);
|
||||
|
||||
if (!validationResult.success) {
|
||||
return validationResult;
|
||||
@@ -21,7 +20,7 @@ async function cloneNoteToParent(req) {
|
||||
const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1;
|
||||
|
||||
const branch = new Branch({
|
||||
noteId: childNoteId,
|
||||
noteId: noteId,
|
||||
parentNoteId: parentNoteId,
|
||||
prefix: prefix,
|
||||
notePosition: newNotePos,
|
||||
|
||||
@@ -86,18 +86,18 @@ async function parseImportFile(file) {
|
||||
}
|
||||
|
||||
async function importTar(req) {
|
||||
const parentNoteId = req.params.parentNoteId;
|
||||
const noteId = req.params.noteId;
|
||||
const file = req.file;
|
||||
|
||||
const parentNote = await repository.getNote(parentNoteId);
|
||||
const parentNote = await repository.getNote(noteId);
|
||||
|
||||
if (!parentNote) {
|
||||
return [404, `Note ${parentNoteId} doesn't exist.`];
|
||||
return [404, `Note ${noteId} doesn't exist.`];
|
||||
}
|
||||
|
||||
const files = await parseImportFile(file);
|
||||
|
||||
await importNotes(files, parentNoteId);
|
||||
await importNotes(files, noteId);
|
||||
}
|
||||
|
||||
async function importNotes(files, parentNoteId) {
|
||||
|
||||
@@ -6,11 +6,7 @@ const options = require('../../services/options');
|
||||
// options allowed to be updated directly in options dialog
|
||||
const ALLOWED_OPTIONS = ['protected_session_timeout', 'note_revision_snapshot_time_interval'];
|
||||
|
||||
async function getAllOptions() {
|
||||
return await sql.getMap("SELECT name, value FROM options");
|
||||
}
|
||||
|
||||
async function getAllowedOptions() {
|
||||
async function getOptions() {
|
||||
const options = await sql.getMap("SELECT name, value FROM options WHERE name IN ("
|
||||
+ ALLOWED_OPTIONS.map(x => '?').join(",") + ")", ALLOWED_OPTIONS);
|
||||
|
||||
@@ -18,17 +14,16 @@ async function getAllowedOptions() {
|
||||
}
|
||||
|
||||
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"];
|
||||
}
|
||||
|
||||
await options.setOption(body['name'], body['value']);
|
||||
await options.setOption(name, value);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAllowedOptions,
|
||||
getAllOptions,
|
||||
getOptions,
|
||||
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 = {
|
||||
getTree,
|
||||
setPrefix
|
||||
getTree
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user