mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			61 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| "use strict";
 | |
| 
 | |
| const express = require('express');
 | |
| const router = express.Router();
 | |
| const auth = require('../../services/auth');
 | |
| const wrap = require('express-promise-wrap').wrap;
 | |
| const attributes = require('../../services/attributes');
 | |
| const script = require('../../services/script');
 | |
| const Repository = require('../../services/repository');
 | |
| 
 | |
| router.post('/exec', auth.checkApiAuth, wrap(async (req, res, next) => {
 | |
|     const ret = await script.executeScript(req, req.body.script, req.body.params, req.body.startNoteId, req.body.currentNoteId);
 | |
| 
 | |
|     res.send({
 | |
|         executionResult: ret
 | |
|     });
 | |
| }));
 | |
| 
 | |
| router.post('/run/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
 | |
|     const repository = new Repository(req);
 | |
|     const note = await repository.getNote(req.params.noteId);
 | |
| 
 | |
|     const ret = await script.executeNote(req, note);
 | |
| 
 | |
|     res.send({
 | |
|         executionResult: ret
 | |
|     });
 | |
| }));
 | |
| 
 | |
| router.get('/startup', auth.checkApiAuth, wrap(async (req, res, next) => {
 | |
|     const repository = new Repository(req);
 | |
|     const notes = await attributes.getNotesWithAttribute(repository, "run", "frontend_startup");
 | |
| 
 | |
|     const scripts = [];
 | |
| 
 | |
|     for (const note of notes) {
 | |
|         const bundle = await script.getScriptBundle(note);
 | |
| 
 | |
|         scripts.push(bundle);
 | |
|     }
 | |
| 
 | |
|     res.send(scripts);
 | |
| }));
 | |
| 
 | |
| router.get('/bundle/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
 | |
|     const repository = new Repository(req);
 | |
|     const note = await repository.getNote(req.params.noteId);
 | |
|     const bundle = await script.getScriptBundle(note);
 | |
| 
 | |
|     res.send(bundle);
 | |
| }));
 | |
| 
 | |
| router.get('/render/:noteId', auth.checkApiAuth, wrap(async (req, res, next) => {
 | |
|     const repository = new Repository(req);
 | |
|     const note = await repository.getNote(req.params.noteId);
 | |
|     const bundle = await script.getRenderScript(note);
 | |
| 
 | |
|     res.send(bundle);
 | |
| }));
 | |
| 
 | |
| module.exports = router; |