mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
correct handling of inclusion of dependencies
This commit is contained in:
parent
ddc885066e
commit
fda4146150
@ -23,6 +23,10 @@ class Note extends Entity {
|
||||
return this.type === "code" && this.mime === "application/json";
|
||||
}
|
||||
|
||||
isJavaScript() {
|
||||
return this.type === "code" && this.mime === "application/javascript";
|
||||
}
|
||||
|
||||
async getAttributes() {
|
||||
return this.repository.getEntities("SELECT * FROM attributes WHERE noteId = ? AND isDeleted = 0", [this.noteId]);
|
||||
}
|
||||
|
@ -116,8 +116,7 @@ async function stopWatch(what, func) {
|
||||
}
|
||||
|
||||
function executeScript(script) {
|
||||
// last \r\n is necessary if script contains line comment on its last line
|
||||
eval("(async function() {" + script + "\r\n})()");
|
||||
eval(script);
|
||||
}
|
||||
|
||||
function formatValueWithWhitespace(val) {
|
||||
|
@ -31,26 +31,28 @@ router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
}));
|
||||
|
||||
router.get('/subtree/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
|
||||
const repository = new Repository(req);
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
const repository = new Repository(req);
|
||||
|
||||
const noteScript = (await repository.getNote(noteId)).content;
|
||||
|
||||
const subTreeScripts = await getSubTreeScripts(noteId, [noteId], repository);
|
||||
|
||||
res.send(subTreeScripts + noteScript);
|
||||
res.send(await getNoteWithSubtreeScript(noteId, repository));
|
||||
}));
|
||||
|
||||
async function getNoteWithSubtreeScript(noteId, repository) {
|
||||
const noteScript = (await repository.getNote(noteId)).content;
|
||||
const note = await repository.getNote(noteId);
|
||||
|
||||
const subTreeScripts = await getSubTreeScripts(noteId, [noteId], repository);
|
||||
let noteScript = note.content;
|
||||
|
||||
if (note.isJavaScript()) {
|
||||
// last \r\n is necessary if script contains line comment on its last line
|
||||
noteScript = "(async function() {" + noteScript + "\r\n})()";
|
||||
}
|
||||
|
||||
const subTreeScripts = await getSubTreeScripts(noteId, [noteId], repository, note.isJavaScript());
|
||||
|
||||
return subTreeScripts + noteScript;
|
||||
}
|
||||
|
||||
async function getSubTreeScripts(parentId, includedNoteIds, repository) {
|
||||
async function getSubTreeScripts(parentId, includedNoteIds, repository, isJavaScript) {
|
||||
const children = await repository.getEntities(`
|
||||
SELECT notes.*
|
||||
FROM notes JOIN note_tree USING(noteId)
|
||||
@ -69,7 +71,7 @@ async function getSubTreeScripts(parentId, includedNoteIds, repository) {
|
||||
|
||||
script += await getSubTreeScripts(child.noteId, includedNoteIds, repository);
|
||||
|
||||
if (child.mime === 'application/javascript') {
|
||||
if (!isJavaScript && child.mime === 'application/javascript') {
|
||||
child.content = '<script>' + child.content + '</script>';
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user