mirror of
https://github.com/zadam/trilium.git
synced 2025-11-13 08:45:50 +01:00
backend scripts should not be async because of transaction management
This commit is contained in:
@@ -5,11 +5,11 @@ const attributeService = require('../../services/attributes');
|
||||
const becca = require('../../services/becca/becca');
|
||||
const syncService = require('../../services/sync');
|
||||
|
||||
async function exec(req) {
|
||||
function exec(req) {
|
||||
try {
|
||||
const {body} = req;
|
||||
|
||||
const result = await scriptService.executeScript(
|
||||
const result = scriptService.executeScript(
|
||||
body.script,
|
||||
body.params,
|
||||
body.startNoteId,
|
||||
@@ -29,10 +29,10 @@ async function exec(req) {
|
||||
}
|
||||
}
|
||||
|
||||
async function run(req) {
|
||||
function run(req) {
|
||||
const note = becca.getNote(req.params.noteId);
|
||||
|
||||
const result = await scriptService.executeNote(note, { originEntity: note });
|
||||
const result = scriptService.executeNote(note, { originEntity: note });
|
||||
|
||||
return { executionResult: result };
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ async function searchAndExecute(req) {
|
||||
}
|
||||
}
|
||||
|
||||
async function searchFromRelation(note, relationName) {
|
||||
function searchFromRelation(note, relationName) {
|
||||
const scriptNote = note.getRelationTarget(relationName);
|
||||
|
||||
if (!scriptNote) {
|
||||
@@ -188,7 +188,7 @@ async function searchFromRelation(note, relationName) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const result = await scriptService.executeNote(scriptNote, { originEntity: note });
|
||||
const result = scriptService.executeNote(scriptNote, { originEntity: note });
|
||||
|
||||
if (!Array.isArray(result)) {
|
||||
log.info(`Result from ${scriptNote.noteId} is not an array.`);
|
||||
|
||||
@@ -6,7 +6,7 @@ const cls = require('../services/cls');
|
||||
const sql = require("../services/sql");
|
||||
const becca = require("../services/becca/becca");
|
||||
|
||||
async function handleRequest(req, res) {
|
||||
function handleRequest(req, res) {
|
||||
// express puts content after first slash into 0 index element
|
||||
|
||||
const path = req.params.path + req.params[0];
|
||||
@@ -72,7 +72,7 @@ async function handleRequest(req, res) {
|
||||
function register(router) {
|
||||
// explicitly no CSRF middleware since it's meant to allow integration from external services
|
||||
|
||||
router.all('/custom/:path*', async (req, res, next) => {
|
||||
router.all('/custom/:path*', (req, res, next) => {
|
||||
cls.namespace.bindEmitter(req);
|
||||
cls.namespace.bindEmitter(res);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user