mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	
		
			
	
	
		
			28 lines
		
	
	
		
			588 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
		
		
			
		
	
	
			28 lines
		
	
	
		
			588 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
|  | const log = require('./log'); | ||
|  | const protected_session = require('./protected_session'); | ||
|  | 
 | ||
|  | async function executeScript(dataKey, script, params) { | ||
|  |     log.info('Executing script: ' + script); | ||
|  | 
 | ||
|  |     const ctx = { | ||
|  |         dataKey: protected_session.getDataKey(dataKey) | ||
|  |     }; | ||
|  | 
 | ||
|  |     params.unshift(ctx); | ||
|  | 
 | ||
|  |     const paramsStr = getParams(params); | ||
|  | 
 | ||
|  |     const ret = await eval(`(${script})(${paramsStr})`); | ||
|  | 
 | ||
|  |     log.info('Execution result: ' + ret); | ||
|  | 
 | ||
|  |     return ret; | ||
|  | } | ||
|  | 
 | ||
|  | function getParams(params) { | ||
|  |     return params.map(p => JSON.stringify(p)).join(","); | ||
|  | } | ||
|  | 
 | ||
|  | module.exports = { | ||
|  |     executeScript | ||
|  | }; |