mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
refactoring of script subtree execution
This commit is contained in:
parent
aad5ea577f
commit
a42fd9b090
@ -216,11 +216,12 @@ const noteEditor = (function() {
|
||||
|
||||
async function executeScript() {
|
||||
if (getCurrentNoteType() === 'code') {
|
||||
// we take script value directly from editor so we don't need to wait for it to be saved
|
||||
const script = codeEditor.getValue();
|
||||
// make sure note is saved so we load latest changes
|
||||
await saveNoteIfChanged();
|
||||
|
||||
const subTreeScripts = await server.get('script/subtree/' + getCurrentNoteId());
|
||||
|
||||
eval("(async function() {" + subTreeScripts + script + "})()");
|
||||
eval("(async function() {" + subTreeScripts + "})()");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,6 +61,10 @@ function formatDate(date) {
|
||||
return padNum(date.getDate()) + ". " + padNum(date.getMonth() + 1) + ". " + date.getFullYear();
|
||||
}
|
||||
|
||||
function formatDateISO(date) {
|
||||
return date.getFullYear() + "-" + padNum(date.getMonth() + 1) + "-" + padNum(date.getDate());
|
||||
}
|
||||
|
||||
function formatDateTime(date) {
|
||||
return formatDate(date) + " " + formatTime(date);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ const auth = require('../../services/auth');
|
||||
const wrap = require('express-promise-wrap').wrap;
|
||||
const log = require('../../services/log');
|
||||
const sql = require('../../services/sql');
|
||||
const notes = require('../../services/notes');
|
||||
const protected_session = require('../../services/protected_session');
|
||||
|
||||
router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
@ -21,7 +22,11 @@ router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
router.get('/subtree/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
res.send(await getSubTreeScripts(noteId, [noteId], req));
|
||||
const noteScript = (await notes.getNoteById(noteId, req)).note_text;
|
||||
|
||||
const subTreeScripts = await getSubTreeScripts(noteId, [noteId], req);
|
||||
|
||||
res.send(subTreeScripts + noteScript);
|
||||
}));
|
||||
|
||||
async function getSubTreeScripts(parentId, includedNoteIds, dataKey) {
|
||||
|
@ -2,11 +2,18 @@ const sql = require('./sql');
|
||||
const options = require('./options');
|
||||
const utils = require('./utils');
|
||||
const notes = require('./notes');
|
||||
const data_encryption = require('./data_encryption');
|
||||
const sync_table = require('./sync_table');
|
||||
const attributes = require('./attributes');
|
||||
const protected_session = require('./protected_session');
|
||||
|
||||
async function getNoteById(noteId, dataKey) {
|
||||
const note = await sql.getFirst("SELECT * FROM notes WHERE note_id = ?", [noteId]);
|
||||
|
||||
protected_session.decryptNote(dataKey, note);
|
||||
|
||||
return note;
|
||||
}
|
||||
|
||||
async function createNewNote(parentNoteId, note, sourceId) {
|
||||
const noteId = utils.newNoteId();
|
||||
const noteTreeId = utils.newNoteTreeId();
|
||||
@ -41,8 +48,8 @@ async function createNewNote(parentNoteId, note, sourceId) {
|
||||
note_title: note.note_title,
|
||||
note_text: note.note_text ? note.note_text : '',
|
||||
is_protected: note.is_protected,
|
||||
type: 'text',
|
||||
mime: 'text/html',
|
||||
type: note.type ? note.type : 'text',
|
||||
mime: note.mime ? note.mime : 'text/html',
|
||||
date_created: now,
|
||||
date_modified: now
|
||||
});
|
||||
@ -277,6 +284,7 @@ async function deleteNote(noteTreeId, sourceId) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getNoteById,
|
||||
createNewNote,
|
||||
updateNote,
|
||||
deleteNote,
|
||||
|
Loading…
x
Reference in New Issue
Block a user