mirror of
https://github.com/zadam/trilium.git
synced 2025-11-04 20:36:13 +01:00
notes_tree now has note_tree_id so we stricly distinguish between working on notes or note trees
This commit is contained in:
@@ -4,7 +4,6 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
const auth = require('../../services/auth');
|
||||
const sql = require('../../services/sql');
|
||||
const options = require('../../services/options');
|
||||
const utils = require('../../services/utils');
|
||||
const notes = require('../../services/notes');
|
||||
const protected_session = require('../../services/protected_session');
|
||||
@@ -14,33 +13,32 @@ const RequestContext = require('../../services/request_context');
|
||||
router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
await options.setOption('start_node', noteId);
|
||||
|
||||
const detail = await sql.getSingleResult("select * from notes where note_id = ?", [noteId]);
|
||||
|
||||
if (detail.is_protected) {
|
||||
const dataKey = protected_session.getDataKey(req);
|
||||
|
||||
detail.note_title = data_encryption.decryptString(dataKey, data_encryption.noteTitleIv(noteId), detail.note_title);
|
||||
detail.note_text = data_encryption.decryptString(dataKey, data_encryption.noteTextIv(noteId), detail.note_text);
|
||||
detail.note_title = data_encryption.decryptString(dataKey, data_encryption.noteTitleIv(detail.note_id), detail.note_title);
|
||||
detail.note_text = data_encryption.decryptString(dataKey, data_encryption.noteTextIv(detail.note_id), detail.note_text);
|
||||
}
|
||||
|
||||
res.send({
|
||||
detail: detail,
|
||||
images: await sql.getResults("select * from images where note_id = ? order by note_offset", [noteId]),
|
||||
images: await sql.getResults("select * from images where note_id = ? order by note_offset", [detail.note_id]),
|
||||
loadTime: utils.nowTimestamp()
|
||||
});
|
||||
});
|
||||
|
||||
router.post('/:parentNoteId/children', async (req, res, next) => {
|
||||
const parentNoteId = req.params.parentNoteId;
|
||||
router.post('/:parentNoteTreeId/children', async (req, res, next) => {
|
||||
const parentNoteTreeId = req.params.parentNoteTreeId;
|
||||
const browserId = utils.browserId(req);
|
||||
const note = req.body;
|
||||
|
||||
const noteId = await notes.createNewNote(parentNoteId, note, browserId);
|
||||
const { noteId, noteTreeId } = await notes.createNewNote(parentNoteTreeId, note, browserId);
|
||||
|
||||
res.send({
|
||||
'note_id': noteId
|
||||
'note_id': noteId,
|
||||
'note_tree_id': noteTreeId
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -6,27 +6,32 @@ const sql = require('../../services/sql');
|
||||
const auth = require('../../services/auth');
|
||||
const utils = require('../../services/utils');
|
||||
const sync_table = require('../../services/sync_table');
|
||||
const options = require('../../services/options');
|
||||
|
||||
router.get('', auth.checkApiAuth, async (req, res, next) => {
|
||||
res.send(await getRecentNotes());
|
||||
});
|
||||
|
||||
router.put('/:noteId', auth.checkApiAuth, async (req, res, next) => {
|
||||
router.put('/:noteTreeId', auth.checkApiAuth, async (req, res, next) => {
|
||||
const noteTreeId = req.params.noteTreeId;
|
||||
|
||||
await sql.replace('recent_notes', {
|
||||
note_id: req.params.noteId,
|
||||
note_tree_id: noteTreeId,
|
||||
date_accessed: utils.nowTimestamp(),
|
||||
is_deleted: 0
|
||||
});
|
||||
|
||||
await sync_table.addRecentNoteSync(req.params.noteId);
|
||||
await sync_table.addRecentNoteSync(noteTreeId);
|
||||
|
||||
await options.setOption('start_note_tree_id', noteTreeId);
|
||||
|
||||
res.send(await getRecentNotes());
|
||||
});
|
||||
|
||||
router.delete('/:noteId', auth.checkApiAuth, async (req, res, next) => {
|
||||
await sql.execute('UPDATE recent_notes SET is_deleted = 1 WHERE note_id = ?', [req.params.noteId]);
|
||||
router.delete('/:noteTreeId', auth.checkApiAuth, async (req, res, next) => {
|
||||
await sql.execute('UPDATE recent_notes SET is_deleted = 1 WHERE note_tree_id = ?', [req.params.noteTreeId]);
|
||||
|
||||
await sync_table.addRecentNoteSync(req.params.noteId);
|
||||
await sync_table.addRecentNoteSync(req.params.noteTreeId);
|
||||
|
||||
res.send(await getRecentNotes());
|
||||
});
|
||||
|
||||
@@ -21,28 +21,17 @@ router.get('/', auth.checkApiAuth, async (req, res, next) => {
|
||||
+ "where notes.is_deleted = 0 and notes_tree.is_deleted = 0 "
|
||||
+ "order by note_pid, note_pos");
|
||||
|
||||
const parentToNotes = {};
|
||||
const notesMap = {};
|
||||
|
||||
const dataKey = protected_session.getDataKey(req);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (!parentToNotes[note.note_pid]) {
|
||||
parentToNotes[note.note_pid] = [];
|
||||
}
|
||||
|
||||
notesMap[note.note_id] = note;
|
||||
parentToNotes[note.note_pid].push(note.note_id);
|
||||
}
|
||||
|
||||
res.send({
|
||||
notes_map: notesMap,
|
||||
parent_to_notes: parentToNotes,
|
||||
start_note_id: await options.getOption('start_node'),
|
||||
notes: notes,
|
||||
start_note_tree_id: await options.getOption('start_note_tree_id'),
|
||||
tree_load_time: utils.nowTimestamp()
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user