mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	compatibility with existing scripts
This commit is contained in:
		
							
								
								
									
										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,6 +268,7 @@ function BackendScriptApi(currentNote, apiParams) { | ||||
|             extraOptions.content = content; | ||||
|         } | ||||
|  | ||||
|         sql.transactional(() => { | ||||
|             const {note, branch} = noteService.createNewNote(extraOptions); | ||||
|  | ||||
|             for (const attr of extraOptions.attributes || []) { | ||||
| @@ -288,6 +282,7 @@ function BackendScriptApi(currentNote, apiParams) { | ||||
|             } | ||||
|  | ||||
|             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,6 +37,7 @@ function getRootCalendarNote() { | ||||
|     let rootNote = attributeService.getNoteWithLabel(CALENDAR_ROOT_LABEL); | ||||
|  | ||||
|     if (!rootNote) { | ||||
|         sql.transactional(() => { | ||||
|             rootNote = noteService.createNewNote({ | ||||
|                 parentNoteId: 'root', | ||||
|                 title: 'Calendar', | ||||
| @@ -47,6 +49,7 @@ function getRootCalendarNote() { | ||||
|  | ||||
|             attributeService.createLabel(rootNote.noteId, CALENDAR_ROOT_LABEL); | ||||
|             attributeService.createLabel(rootNote.noteId, 'sorted'); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     return rootNote; | ||||
| @@ -66,6 +69,7 @@ function getYearNote(dateStr, rootNote) { | ||||
|         yearNote = getNoteStartingWith(rootNote.noteId, yearStr); | ||||
|  | ||||
|         if (!yearNote) { | ||||
|             sql.transactional(() => { | ||||
|                 yearNote = createNote(rootNote.noteId, yearStr); | ||||
|  | ||||
|                 attributeService.createLabel(yearNote.noteId, YEAR_LABEL, yearStr); | ||||
| @@ -76,6 +80,7 @@ function getYearNote(dateStr, rootNote) { | ||||
|                 if (yearTemplateAttr) { | ||||
|                     attributeService.createRelation(yearNote.noteId, 'template', yearTemplateAttr.value); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -112,6 +117,7 @@ function getMonthNote(dateStr, rootNote) { | ||||
|  | ||||
|             const noteTitle = getMonthNoteTitle(rootNote, monthNumber, dateObj); | ||||
|  | ||||
|             sql.transactional(() => { | ||||
|                 monthNote = createNote(yearNote.noteId, noteTitle); | ||||
|  | ||||
|                 attributeService.createLabel(monthNote.noteId, MONTH_LABEL, monthStr); | ||||
| @@ -122,6 +128,7 @@ function getMonthNote(dateStr, rootNote) { | ||||
|                 if (monthTemplateAttr) { | ||||
|                     attributeService.createRelation(monthNote.noteId, 'template', monthTemplateAttr.value); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -157,6 +164,7 @@ function getDateNote(dateStr) { | ||||
|  | ||||
|             const noteTitle = getDateNoteTitle(rootNote, dayNumber, dateObj); | ||||
|  | ||||
|             sql.transactional(() => { | ||||
|                 dateNote = createNote(monthNote.noteId, noteTitle); | ||||
|  | ||||
|                 attributeService.createLabel(dateNote.noteId, DATE_LABEL, dateStr.substr(0, 10)); | ||||
| @@ -166,6 +174,7 @@ function getDateNote(dateStr) { | ||||
|                 if (dateTemplateAttr) { | ||||
|                     attributeService.createRelation(dateNote.noteId, 'template', dateTemplateAttr.value); | ||||
|                 } | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -105,6 +105,7 @@ function createNewNote(params) { | ||||
|         throw new Error(`Note title must not be empty`); | ||||
|     } | ||||
|  | ||||
|     sql.transactional(() => { | ||||
|         const note = new Note({ | ||||
|             noteId: params.noteId, // optionally can force specific noteId | ||||
|             title: params.title, | ||||
| @@ -134,6 +135,7 @@ function createNewNote(params) { | ||||
|             note, | ||||
|             branch | ||||
|         }; | ||||
|     }); | ||||
| } | ||||
|  | ||||
| function createNewNoteWithTarget(target, targetBranchId, params) { | ||||
|   | ||||
| @@ -39,13 +39,8 @@ 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)); | ||||
|         } | ||||
|     } | ||||
|     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()}; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user