mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
script API changes
This commit is contained in:
parent
4ab763e295
commit
55d8ef7e81
@ -68,8 +68,6 @@ async function getSubTreeScripts(parentId, includedNoteIds, dataKey) {
|
||||
|
||||
script += await getSubTreeScripts(child.note_id, includedNoteIds, dataKey);
|
||||
|
||||
console.log('MIME: ', child.mime);
|
||||
|
||||
if (child.mime === 'application/javascript') {
|
||||
child.note_text = '<script>' + child.note_text + '</script>';
|
||||
}
|
||||
|
@ -14,17 +14,29 @@ async function getNoteIdWithAttribute(name, value) {
|
||||
WHERE notes.is_deleted = 0 AND attributes.name = ? AND attributes.value = ?`, [name, value]);
|
||||
}
|
||||
|
||||
async function getNoteWithAttribute(dataKey, name, value) {
|
||||
const note = await sql.getFirst(`SELECT notes.* FROM notes JOIN attributes USING(note_id)
|
||||
WHERE notes.is_deleted = 0 AND attributes.name = ? AND attributes.value = ?`, [name, value]);
|
||||
async function getNotesWithAttribute(dataKey, name, value) {
|
||||
let notes;
|
||||
|
||||
if (!note) {
|
||||
return note;
|
||||
if (value !== undefined) {
|
||||
notes = await sql.getAll(`SELECT notes.* FROM notes JOIN attributes USING(note_id)
|
||||
WHERE notes.is_deleted = 0 AND attributes.name = ? AND attributes.value = ?`, [name, value]);
|
||||
}
|
||||
else {
|
||||
notes = await sql.getAll(`SELECT notes.* FROM notes JOIN attributes USING(note_id)
|
||||
WHERE notes.is_deleted = 0 AND attributes.name = ?`, [name]);
|
||||
}
|
||||
|
||||
protected_session.decryptNote(dataKey, note);
|
||||
for (const note of notes) {
|
||||
protected_session.decryptNote(dataKey, note);
|
||||
}
|
||||
|
||||
return note;
|
||||
return notes;
|
||||
}
|
||||
|
||||
async function getNoteWithAttribute(dataKey, name, value) {
|
||||
const notes = getNotesWithAttribute(dataKey, name, value);
|
||||
|
||||
return notes.length > 0 ? notes[0] : null;
|
||||
}
|
||||
|
||||
async function getNoteIdsWithAttribute(name) {
|
||||
@ -51,6 +63,7 @@ async function createAttribute(noteId, name, value = null, sourceId = null) {
|
||||
module.exports = {
|
||||
getNoteAttributeMap,
|
||||
getNoteIdWithAttribute,
|
||||
getNotesWithAttribute,
|
||||
getNoteWithAttribute,
|
||||
getNoteIdsWithAttribute,
|
||||
createAttribute
|
||||
|
@ -11,7 +11,7 @@ function ScriptContext(noteId, dataKey) {
|
||||
this.dataKey = protected_session.getDataKey(dataKey);
|
||||
|
||||
function deserializePayload(note) {
|
||||
if (note.type === "code" && note.mime === "application/json") {
|
||||
if (note && note.type === "code" && note.mime === "application/json") {
|
||||
note.payload = JSON.parse(note.note_text);
|
||||
}
|
||||
}
|
||||
@ -28,12 +28,20 @@ function ScriptContext(noteId, dataKey) {
|
||||
return note;
|
||||
};
|
||||
|
||||
this.getNotesWithAttribute = async function (attrName, attrValue) {
|
||||
const notes = await attributes.getNotesWithAttribute(this.dataKey, attrName, attrValue);
|
||||
|
||||
for (const note of notes) {
|
||||
deserializePayload(note);
|
||||
}
|
||||
|
||||
return notes;
|
||||
};
|
||||
|
||||
this.getNoteWithAttribute = async function (attrName, attrValue) {
|
||||
const note = await attributes.getNoteWithAttribute(this.dataKey, attrName, attrValue);
|
||||
const notes = this.getNotesWithAttribute(attrName, attrValue);
|
||||
|
||||
deserializePayload(note);
|
||||
|
||||
return note;
|
||||
return notes.length > 0 ? notes[0] : null;
|
||||
};
|
||||
|
||||
this.createNote = async function (parentNoteId, name, payload, extraOptions = {}) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user