mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
refactoring of routes - noteId needs to go to /notes noteTreeId to /tree
This commit is contained in:
parent
16eb156033
commit
9860c8deef
@ -142,7 +142,7 @@ const protected_session = (function() {
|
|||||||
async function protectSubTree(noteId, protect) {
|
async function protectSubTree(noteId, protect) {
|
||||||
await ensureProtectedSession(true, true);
|
await ensureProtectedSession(true, true);
|
||||||
|
|
||||||
await server.put('tree/' + noteId + "/protect-sub-tree/" + (protect ? 1 : 0));
|
await server.put('notes/' + noteId + "/protect-sub-tree/" + (protect ? 1 : 0));
|
||||||
|
|
||||||
showMessage("Request to un/protect sub tree has finished successfully");
|
showMessage("Request to un/protect sub tree has finished successfully");
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ const notes = require('../../services/notes');
|
|||||||
const log = require('../../services/log');
|
const log = require('../../services/log');
|
||||||
const protected_session = require('../../services/protected_session');
|
const protected_session = require('../../services/protected_session');
|
||||||
const data_encryption = require('../../services/data_encryption');
|
const data_encryption = require('../../services/data_encryption');
|
||||||
const sync_table = require('../../services/sync_table');
|
const tree = require('../../services/tree');
|
||||||
const wrap = require('express-promise-wrap').wrap;
|
const wrap = require('express-promise-wrap').wrap;
|
||||||
|
|
||||||
router.get('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
router.get('/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||||
@ -77,28 +77,19 @@ router.put('/:noteId/sort', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|||||||
const sourceId = req.headers.source_id;
|
const sourceId = req.headers.source_id;
|
||||||
const dataKey = protected_session.getDataKey(req);
|
const dataKey = protected_session.getDataKey(req);
|
||||||
|
|
||||||
|
await tree.sortNotesAlphabetically(noteId, dataKey, sourceId);
|
||||||
|
|
||||||
|
res.send({});
|
||||||
|
}));
|
||||||
|
|
||||||
|
router.put('/:noteId/protect-sub-tree/:isProtected', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||||
|
const noteId = req.params.noteId;
|
||||||
|
const isProtected = !!parseInt(req.params.isProtected);
|
||||||
|
const dataKey = protected_session.getDataKey(req);
|
||||||
|
const sourceId = req.headers.source_id;
|
||||||
|
|
||||||
await sql.doInTransaction(async () => {
|
await sql.doInTransaction(async () => {
|
||||||
const notes = await sql.getAll(`SELECT note_tree_id, note_id, note_title, is_protected
|
await notes.protectNoteRecursively(noteId, dataKey, isProtected, sourceId);
|
||||||
FROM notes JOIN notes_tree USING(note_id) WHERE parent_note_id = ?`, [noteId]);
|
|
||||||
|
|
||||||
for (const note of notes) {
|
|
||||||
if (note.is_protected) {
|
|
||||||
note.note_title = data_encryption.decryptString(dataKey, data_encryption.noteTitleIv(note.note_id), note.note_title);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notes.sort((a, b) => a.note_title.toLowerCase() < b.note_title.toLowerCase() ? -1 : 1);
|
|
||||||
|
|
||||||
let position = 1;
|
|
||||||
|
|
||||||
for (const note of notes) {
|
|
||||||
await sql.execute("UPDATE notes_tree SET note_position = ? WHERE note_tree_id = ?",
|
|
||||||
[position, note.note_tree_id]);
|
|
||||||
|
|
||||||
position++;
|
|
||||||
}
|
|
||||||
|
|
||||||
await sync_table.addNoteReorderingSync(noteId, sourceId);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
res.send({});
|
res.send({});
|
||||||
|
@ -8,7 +8,6 @@ const utils = require('../../services/utils');
|
|||||||
const auth = require('../../services/auth');
|
const auth = require('../../services/auth');
|
||||||
const protected_session = require('../../services/protected_session');
|
const protected_session = require('../../services/protected_session');
|
||||||
const data_encryption = require('../../services/data_encryption');
|
const data_encryption = require('../../services/data_encryption');
|
||||||
const notes = require('../../services/notes');
|
|
||||||
const sync_table = require('../../services/sync_table');
|
const sync_table = require('../../services/sync_table');
|
||||||
const wrap = require('express-promise-wrap').wrap;
|
const wrap = require('express-promise-wrap').wrap;
|
||||||
|
|
||||||
@ -42,19 +41,6 @@ router.get('/', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
router.put('/:noteId/protect-sub-tree/:isProtected', auth.checkApiAuth, wrap(async (req, res, next) => {
|
|
||||||
const noteId = req.params.noteId;
|
|
||||||
const isProtected = !!parseInt(req.params.isProtected);
|
|
||||||
const dataKey = protected_session.getDataKey(req);
|
|
||||||
const sourceId = req.headers.source_id;
|
|
||||||
|
|
||||||
await sql.doInTransaction(async () => {
|
|
||||||
await notes.protectNoteRecursively(noteId, dataKey, isProtected, sourceId);
|
|
||||||
});
|
|
||||||
|
|
||||||
res.send({});
|
|
||||||
}));
|
|
||||||
|
|
||||||
router.put('/:noteTreeId/set-prefix', auth.checkApiAuth, wrap(async (req, res, next) => {
|
router.put('/:noteTreeId/set-prefix', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||||
const noteTreeId = req.params.noteTreeId;
|
const noteTreeId = req.params.noteTreeId;
|
||||||
const sourceId = req.headers.source_id;
|
const sourceId = req.headers.source_id;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
|
const sync_table = require('./sync_table');
|
||||||
|
const data_encryption = require('./data_encryption');
|
||||||
|
|
||||||
async function validateParentChild(res, parentNoteId, childNoteId, noteTreeId = null) {
|
async function validateParentChild(res, parentNoteId, childNoteId, noteTreeId = null) {
|
||||||
const existing = await getExistingNoteTree(parentNoteId, childNoteId);
|
const existing = await getExistingNoteTree(parentNoteId, childNoteId);
|
||||||
@ -78,7 +80,34 @@ async function loadSubTreeNoteIds(parentNoteId, subTreeNoteIds) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sortNotesAlphabetically(parentNoteId, dataKey, sourceId) {
|
||||||
|
await sql.doInTransaction(async () => {
|
||||||
|
const notes = await sql.getAll(`SELECT note_tree_id, note_id, note_title, is_protected
|
||||||
|
FROM notes JOIN notes_tree USING(note_id) WHERE parent_note_id = ?`, [parentNoteId]);
|
||||||
|
|
||||||
|
for (const note of notes) {
|
||||||
|
if (note.is_protected) {
|
||||||
|
note.note_title = data_encryption.decryptString(dataKey, data_encryption.noteTitleIv(note.note_id), note.note_title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notes.sort((a, b) => a.note_title.toLowerCase() < b.note_title.toLowerCase() ? -1 : 1);
|
||||||
|
|
||||||
|
let position = 1;
|
||||||
|
|
||||||
|
for (const note of notes) {
|
||||||
|
await sql.execute("UPDATE notes_tree SET note_position = ? WHERE note_tree_id = ?",
|
||||||
|
[position, note.note_tree_id]);
|
||||||
|
|
||||||
|
position++;
|
||||||
|
}
|
||||||
|
|
||||||
|
await sync_table.addNoteReorderingSync(parentNoteId, sourceId);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
validateParentChild,
|
validateParentChild,
|
||||||
getNoteTree
|
getNoteTree,
|
||||||
|
sortNotesAlphabetically
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user