mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 01:18:44 +02:00
compatibility with existing scripts
This commit is contained in:
parent
3670fbff49
commit
03d7ee9abb
6
package-lock.json
generated
6
package-lock.json
generated
@ -3065,9 +3065,9 @@
|
||||
}
|
||||
},
|
||||
"electron": {
|
||||
"version": "10.0.0-beta.21",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-10.0.0-beta.21.tgz",
|
||||
"integrity": "sha512-r2qIQ9lzq2FBeEpitBWJ5WO0V+TtrEvrgAXc2sUCrZqKfS1kUoJadmrDy69j4R3qNfifRrxuR2wISMmvNL2SAQ==",
|
||||
"version": "10.0.0-beta.23",
|
||||
"resolved": "https://registry.npmjs.org/electron/-/electron-10.0.0-beta.23.tgz",
|
||||
"integrity": "sha512-jMav5NXZUN8YdcCfASy0Jimms3VoFEPa2nYGZTN/19nlryEedaZksHKJM9afVX3w9AnUv8xPCWdyXUQiRg0YWA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@electron/get": "^1.0.1",
|
||||
|
@ -77,7 +77,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"cross-env": "7.0.2",
|
||||
"electron": "10.0.0-beta.21",
|
||||
"electron": "10.0.0-beta.23",
|
||||
"electron-builder": "22.8.0",
|
||||
"electron-packager": "15.0.0",
|
||||
"electron-rebuild": "1.11.0",
|
||||
|
@ -23,7 +23,7 @@ app.use(helmet({
|
||||
hidePoweredBy: false, // deactivated because electron 4.0 crashes on this right after startup
|
||||
contentSecurityPolicy: {
|
||||
directives: {
|
||||
defaultSrc: ["*", "'unsafe-inline'", "'unsafe-eval'"]
|
||||
defaultSrc: ["*", "'unsafe-inline'", "'unsafe-eval'", "img-src 'self' data:"]
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
@ -44,6 +44,7 @@ const TPL = `
|
||||
export default class SearchBoxWidget extends BasicWidget {
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.contentSized();
|
||||
|
||||
this.$searchBox = this.$widget;
|
||||
this.$closeSearchButton = this.$widget.find(".close-search-button");
|
||||
|
@ -13,7 +13,6 @@ const BUILTIN_ATTRIBUTES = [
|
||||
{ type: 'label', name: 'calendarRoot' },
|
||||
{ type: 'label', name: 'archived' },
|
||||
{ type: 'label', name: 'excludeFromExport' },
|
||||
{ type: 'label', name: 'manualTransactionHandling' },
|
||||
{ type: 'label', name: 'disableInclusion' },
|
||||
{ type: 'label', name: 'appCss' },
|
||||
{ type: 'label', name: 'appTheme' },
|
||||
|
@ -68,13 +68,6 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
*/
|
||||
this.getAttribute = repository.getAttribute;
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @param {string} imageId
|
||||
* @returns {Image|null}
|
||||
*/
|
||||
this.getImage = repository.getImage;
|
||||
|
||||
/**
|
||||
* Retrieves first entity from the SQL's result set.
|
||||
*
|
||||
@ -275,19 +268,21 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
extraOptions.content = content;
|
||||
}
|
||||
|
||||
const {note, branch} = noteService.createNewNote(extraOptions);
|
||||
sql.transactional(() => {
|
||||
const {note, branch} = noteService.createNewNote(extraOptions);
|
||||
|
||||
for (const attr of extraOptions.attributes || []) {
|
||||
attributeService.createAttribute({
|
||||
noteId: note.noteId,
|
||||
type: attr.type,
|
||||
name: attr.name,
|
||||
value: attr.value,
|
||||
isInheritable: !!attr.isInheritable
|
||||
});
|
||||
}
|
||||
for (const attr of extraOptions.attributes || []) {
|
||||
attributeService.createAttribute({
|
||||
noteId: note.noteId,
|
||||
type: attr.type,
|
||||
name: attr.name,
|
||||
value: attr.value,
|
||||
isInheritable: !!attr.isInheritable
|
||||
});
|
||||
}
|
||||
|
||||
return {note, branch};
|
||||
return {note, branch};
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -374,9 +369,6 @@ function BackendScriptApi(currentNote, apiParams) {
|
||||
* This functions wraps code which is supposed to be running in transaction. If transaction already
|
||||
* exists, then we'll use that transaction.
|
||||
*
|
||||
* This method is required only when script has label manualTransactionHandling, all other scripts are
|
||||
* transactional by default.
|
||||
*
|
||||
* @method
|
||||
* @param {function} func
|
||||
* @returns {?} result of func callback
|
||||
|
@ -4,6 +4,7 @@ const noteService = require('./notes');
|
||||
const attributeService = require('./attributes');
|
||||
const dateUtils = require('./date_utils');
|
||||
const repository = require('./repository');
|
||||
const sql = require('./sql');
|
||||
|
||||
const CALENDAR_ROOT_LABEL = 'calendarRoot';
|
||||
const YEAR_LABEL = 'yearNote';
|
||||
@ -36,17 +37,19 @@ function getRootCalendarNote() {
|
||||
let rootNote = attributeService.getNoteWithLabel(CALENDAR_ROOT_LABEL);
|
||||
|
||||
if (!rootNote) {
|
||||
rootNote = noteService.createNewNote({
|
||||
parentNoteId: 'root',
|
||||
title: 'Calendar',
|
||||
target: 'into',
|
||||
isProtected: false,
|
||||
type: 'text',
|
||||
content: ''
|
||||
}).note;
|
||||
sql.transactional(() => {
|
||||
rootNote = noteService.createNewNote({
|
||||
parentNoteId: 'root',
|
||||
title: 'Calendar',
|
||||
target: 'into',
|
||||
isProtected: false,
|
||||
type: 'text',
|
||||
content: ''
|
||||
}).note;
|
||||
|
||||
attributeService.createLabel(rootNote.noteId, CALENDAR_ROOT_LABEL);
|
||||
attributeService.createLabel(rootNote.noteId, 'sorted');
|
||||
attributeService.createLabel(rootNote.noteId, CALENDAR_ROOT_LABEL);
|
||||
attributeService.createLabel(rootNote.noteId, 'sorted');
|
||||
});
|
||||
}
|
||||
|
||||
return rootNote;
|
||||
@ -66,16 +69,18 @@ function getYearNote(dateStr, rootNote) {
|
||||
yearNote = getNoteStartingWith(rootNote.noteId, yearStr);
|
||||
|
||||
if (!yearNote) {
|
||||
yearNote = createNote(rootNote.noteId, yearStr);
|
||||
sql.transactional(() => {
|
||||
yearNote = createNote(rootNote.noteId, yearStr);
|
||||
|
||||
attributeService.createLabel(yearNote.noteId, YEAR_LABEL, yearStr);
|
||||
attributeService.createLabel(yearNote.noteId, 'sorted');
|
||||
attributeService.createLabel(yearNote.noteId, YEAR_LABEL, yearStr);
|
||||
attributeService.createLabel(yearNote.noteId, 'sorted');
|
||||
|
||||
const yearTemplateAttr = rootNote.getOwnedAttribute('relation', 'yearTemplate');
|
||||
const yearTemplateAttr = rootNote.getOwnedAttribute('relation', 'yearTemplate');
|
||||
|
||||
if (yearTemplateAttr) {
|
||||
attributeService.createRelation(yearNote.noteId, 'template', yearTemplateAttr.value);
|
||||
}
|
||||
if (yearTemplateAttr) {
|
||||
attributeService.createRelation(yearNote.noteId, 'template', yearTemplateAttr.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,16 +117,18 @@ function getMonthNote(dateStr, rootNote) {
|
||||
|
||||
const noteTitle = getMonthNoteTitle(rootNote, monthNumber, dateObj);
|
||||
|
||||
monthNote = createNote(yearNote.noteId, noteTitle);
|
||||
sql.transactional(() => {
|
||||
monthNote = createNote(yearNote.noteId, noteTitle);
|
||||
|
||||
attributeService.createLabel(monthNote.noteId, MONTH_LABEL, monthStr);
|
||||
attributeService.createLabel(monthNote.noteId, 'sorted');
|
||||
attributeService.createLabel(monthNote.noteId, MONTH_LABEL, monthStr);
|
||||
attributeService.createLabel(monthNote.noteId, 'sorted');
|
||||
|
||||
const monthTemplateAttr = rootNote.getOwnedAttribute('relation', 'monthTemplate');
|
||||
const monthTemplateAttr = rootNote.getOwnedAttribute('relation', 'monthTemplate');
|
||||
|
||||
if (monthTemplateAttr) {
|
||||
attributeService.createRelation(monthNote.noteId, 'template', monthTemplateAttr.value);
|
||||
}
|
||||
if (monthTemplateAttr) {
|
||||
attributeService.createRelation(monthNote.noteId, 'template', monthTemplateAttr.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,15 +164,17 @@ function getDateNote(dateStr) {
|
||||
|
||||
const noteTitle = getDateNoteTitle(rootNote, dayNumber, dateObj);
|
||||
|
||||
dateNote = createNote(monthNote.noteId, noteTitle);
|
||||
sql.transactional(() => {
|
||||
dateNote = createNote(monthNote.noteId, noteTitle);
|
||||
|
||||
attributeService.createLabel(dateNote.noteId, DATE_LABEL, dateStr.substr(0, 10));
|
||||
attributeService.createLabel(dateNote.noteId, DATE_LABEL, dateStr.substr(0, 10));
|
||||
|
||||
const dateTemplateAttr = rootNote.getOwnedAttribute('relation', 'dateTemplate');
|
||||
const dateTemplateAttr = rootNote.getOwnedAttribute('relation', 'dateTemplate');
|
||||
|
||||
if (dateTemplateAttr) {
|
||||
attributeService.createRelation(dateNote.noteId, 'template', dateTemplateAttr.value);
|
||||
}
|
||||
if (dateTemplateAttr) {
|
||||
attributeService.createRelation(dateNote.noteId, 'template', dateTemplateAttr.value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,35 +105,37 @@ function createNewNote(params) {
|
||||
throw new Error(`Note title must not be empty`);
|
||||
}
|
||||
|
||||
const note = new Note({
|
||||
noteId: params.noteId, // optionally can force specific noteId
|
||||
title: params.title,
|
||||
isProtected: !!params.isProtected,
|
||||
type: params.type,
|
||||
mime: deriveMime(params.type, params.mime)
|
||||
}).save();
|
||||
sql.transactional(() => {
|
||||
const note = new Note({
|
||||
noteId: params.noteId, // optionally can force specific noteId
|
||||
title: params.title,
|
||||
isProtected: !!params.isProtected,
|
||||
type: params.type,
|
||||
mime: deriveMime(params.type, params.mime)
|
||||
}).save();
|
||||
|
||||
note.setContent(params.content);
|
||||
note.setContent(params.content);
|
||||
|
||||
const branch = new Branch({
|
||||
noteId: note.noteId,
|
||||
parentNoteId: params.parentNoteId,
|
||||
notePosition: params.notePosition !== undefined ? params.notePosition : getNewNotePosition(params.parentNoteId),
|
||||
prefix: params.prefix,
|
||||
isExpanded: !!params.isExpanded
|
||||
}).save();
|
||||
const branch = new Branch({
|
||||
noteId: note.noteId,
|
||||
parentNoteId: params.parentNoteId,
|
||||
notePosition: params.notePosition !== undefined ? params.notePosition : getNewNotePosition(params.parentNoteId),
|
||||
prefix: params.prefix,
|
||||
isExpanded: !!params.isExpanded
|
||||
}).save();
|
||||
|
||||
scanForLinks(note);
|
||||
scanForLinks(note);
|
||||
|
||||
copyChildAttributes(parentNote, note);
|
||||
copyChildAttributes(parentNote, note);
|
||||
|
||||
triggerNoteTitleChanged(note);
|
||||
triggerChildNoteCreated(note, parentNote);
|
||||
triggerNoteTitleChanged(note);
|
||||
triggerChildNoteCreated(note, parentNote);
|
||||
|
||||
return {
|
||||
note,
|
||||
branch
|
||||
};
|
||||
return {
|
||||
note,
|
||||
branch
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function createNewNoteWithTarget(target, targetBranchId, params) {
|
||||
|
@ -39,12 +39,7 @@ async function executeBundle(bundle, apiParams = {}) {
|
||||
const ctx = new ScriptContext(bundle.allNotes, apiParams);
|
||||
|
||||
try {
|
||||
if (bundle.note.hasOwnedLabel('manualTransactionHandling')) {
|
||||
return execute(ctx, script);
|
||||
}
|
||||
else {
|
||||
return sql.transactional(() => execute(ctx, script));
|
||||
}
|
||||
return execute(ctx, script);
|
||||
}
|
||||
catch (e) {
|
||||
log.error(`Execution of script "${bundle.note.title}" (${bundle.note.noteId}) failed with error: ${e.message}`);
|
||||
@ -159,7 +154,7 @@ function getScriptBundle(note, root = true, scriptEnv = null, includedNoteIds =
|
||||
if (note.isJavaScript()) {
|
||||
bundle.script += `
|
||||
apiContext.modules['${note.noteId}'] = {};
|
||||
${root ? 'return ' : ''}((function(exports, module, require, api` + (modules.length > 0 ? ', ' : '') +
|
||||
${root ? 'return ' : ''}await ((async function(exports, module, require, api` + (modules.length > 0 ? ', ' : '') +
|
||||
modules.map(child => sanitizeVariableName(child.title)).join(', ') + `) {
|
||||
try {
|
||||
${note.getContent()};
|
||||
|
Loading…
x
Reference in New Issue
Block a user