mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	various script fixes, including for electron
This commit is contained in:
		| @@ -36,7 +36,9 @@ const server = (function() { | |||||||
|             script = script.toString(); |             script = script.toString(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return await post('script/exec/noteId', { script: script, params: params }); |         const ret = await post('script/exec', { script: script, params: params }); | ||||||
|  |  | ||||||
|  |         return ret.executionResult; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let i = 1; |     let i = 1; | ||||||
|   | |||||||
| @@ -237,6 +237,7 @@ div.ui-tooltip { | |||||||
|  |  | ||||||
| .CodeMirror { | .CodeMirror { | ||||||
|     height: 100%; |     height: 100%; | ||||||
|  |     font-family: "Liberation Mono", "Lucida Console", monospace; | ||||||
| } | } | ||||||
|  |  | ||||||
| #note-id-display { | #note-id-display { | ||||||
|   | |||||||
| @@ -9,12 +9,12 @@ const attributes = require('../../services/attributes'); | |||||||
| const script = require('../../services/script'); | const script = require('../../services/script'); | ||||||
| const Repository = require('../../services/repository'); | const Repository = require('../../services/repository'); | ||||||
|  |  | ||||||
| router.post('/exec/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => { | router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => { | ||||||
|     const noteId = req.params.noteId; |     const ret = await script.executeScript(req, req.body.script, req.body.params); | ||||||
|  |  | ||||||
|     const ret = await script.executeScript(noteId, req, req.body.script, req.body.params); |     res.send({ | ||||||
|  |         executionResult: ret | ||||||
|     res.send(ret); |     }); | ||||||
| })); | })); | ||||||
|  |  | ||||||
| router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => { | router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => { | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ class Repository { | |||||||
|             entity.beforeSaving(); |             entity.beforeSaving(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         const clone = {...entity}; |         const clone = Object.assign({}, entity); | ||||||
|  |  | ||||||
|         delete clone.dataKey; |         delete clone.dataKey; | ||||||
|         delete clone.jsonContent; |         delete clone.jsonContent; | ||||||
|   | |||||||
| @@ -2,10 +2,10 @@ const log = require('./log'); | |||||||
| const sql = require('./sql'); | const sql = require('./sql'); | ||||||
| const ScriptContext = require('./script_context'); | const ScriptContext = require('./script_context'); | ||||||
|  |  | ||||||
| async function executeScript(noteId, dataKey, script, params) { | async function executeScript(dataKey, script, params) { | ||||||
|     log.info('Executing script: ' + script); |     log.info('Executing script: ' + script); | ||||||
|  |  | ||||||
|     const ctx = new ScriptContext(noteId, dataKey); |     const ctx = new ScriptContext(dataKey); | ||||||
|  |  | ||||||
|     const paramsStr = getParams(params); |     const paramsStr = getParams(params); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,7 +6,6 @@ const date_notes = require('./date_notes'); | |||||||
| const Repository = require('./repository'); | const Repository = require('./repository'); | ||||||
|  |  | ||||||
| function ScriptContext(noteId, dataKey) { | function ScriptContext(noteId, dataKey) { | ||||||
|     this.scriptNoteId = noteId; |  | ||||||
|     this.dataKey = protected_session.getDataKey(dataKey); |     this.dataKey = protected_session.getDataKey(dataKey); | ||||||
|     this.repository = new Repository(dataKey); |     this.repository = new Repository(dataKey); | ||||||
|  |  | ||||||
| @@ -58,7 +57,7 @@ function ScriptContext(noteId, dataKey) { | |||||||
|     this.updateEntity = this.repository.updateEntity; |     this.updateEntity = this.repository.updateEntity; | ||||||
|  |  | ||||||
|     this.log = function(message) { |     this.log = function(message) { | ||||||
|         log.info(`Script ${this.scriptNoteId}: ${message}`); |         log.info(`Script: ${message}`); | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     this.getDateNoteId = date_notes.getDateNoteId; |     this.getDateNoteId = date_notes.getDateNoteId; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user