mirror of
https://github.com/zadam/trilium.git
synced 2026-05-07 16:07:04 +02:00
chore(core): integrate scripting routes
This commit is contained in:
@@ -28,7 +28,6 @@ import loginApiRoute from "./api/login.js";
|
||||
import metricsRoute from "./api/metrics.js";
|
||||
import passwordApiRoute from "./api/password.js";
|
||||
import recoveryCodes from './api/recovery_codes.js';
|
||||
import scriptRoute from "./api/script.js";
|
||||
import senderRoute from "./api/sender.js";
|
||||
import systemInfoRoute from "./api/system_info.js";
|
||||
import totp from './api/totp.js';
|
||||
@@ -177,14 +176,6 @@ function register(app: express.Application) {
|
||||
|
||||
apiRoute(GET, "/api/database/check-integrity", databaseRoute.checkIntegrity);
|
||||
|
||||
asyncRoute(PST, "/api/script/exec", [auth.checkApiAuth, csrfMiddleware], scriptRoute.exec, apiResultHandler);
|
||||
|
||||
apiRoute(PST, "/api/script/run/:noteId", scriptRoute.run);
|
||||
apiRoute(GET, "/api/script/startup", scriptRoute.getStartupBundles);
|
||||
apiRoute(GET, "/api/script/widgets", scriptRoute.getWidgetBundles);
|
||||
apiRoute(PST, "/api/script/bundle/:noteId", scriptRoute.getBundle);
|
||||
apiRoute(GET, "/api/script/relation/:noteId/:relationName", scriptRoute.getRelationBundles);
|
||||
|
||||
// no CSRF since this is called from android app
|
||||
route(PST, "/api/sender/login", [loginRateLimiter], loginApiRoute.token, apiResultHandler);
|
||||
asyncRoute(PST, "/api/sender/image", [auth.checkEtapiToken, uploadMiddlewareWithErrorHandling], senderRoute.uploadImage, apiResultHandler);
|
||||
|
||||
@@ -5,9 +5,9 @@ import type { Request } from "express";
|
||||
import becca from "../../becca/becca.js";
|
||||
import attributeService from "../../services/attributes.js";
|
||||
import scriptService, { type Bundle } from "../../services/script.js";
|
||||
import sql from "../../services/sql.js";
|
||||
import syncService from "../../services/sync.js";
|
||||
import { safeExtractMessageAndStackFromError } from "../../services/utils.js";
|
||||
import { safeExtractMessageAndStackFromError } from "../../services/utils/index.js";
|
||||
import { getSql } from "../../services/sql/index.js";
|
||||
|
||||
interface ScriptBody {
|
||||
script: string;
|
||||
@@ -28,7 +28,7 @@ async function exec(req: Request) {
|
||||
|
||||
const execute = (body: ScriptBody) => scriptService.executeScript(body.script, body.params, body.startNoteId, body.currentNoteId, body.originEntityName, body.originEntityId);
|
||||
|
||||
const result = body.transactional ? sql.transactional(() => execute(body)) : await execute(body);
|
||||
const result = body.transactional ? getSql().transactional(() => execute(body)) : await execute(body);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
@@ -72,20 +72,20 @@ function getStartupBundles(req: Request) {
|
||||
if (!process.env.TRILIUM_SAFE_MODE) {
|
||||
if (req.query.mobile === "true") {
|
||||
return getBundlesWithLabel("run", "mobileStartup");
|
||||
}
|
||||
}
|
||||
return getBundlesWithLabel("run", "frontendStartup");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return [];
|
||||
|
||||
|
||||
}
|
||||
|
||||
function getWidgetBundles() {
|
||||
if (!process.env.TRILIUM_SAFE_MODE) {
|
||||
return getBundlesWithLabel("widget");
|
||||
}
|
||||
}
|
||||
return [];
|
||||
|
||||
|
||||
}
|
||||
|
||||
function getRelationBundles(req: Request<{ noteId: string, relationName: string }>) {
|
||||
@@ -27,6 +27,7 @@ import setupApiRoute from "./api/setup";
|
||||
import filesRoute from "./api/files";
|
||||
import importRoute from "./api/import";
|
||||
import exportRoute from "./api/export";
|
||||
import scriptRoute from "./api/script";
|
||||
|
||||
// TODO: Deduplicate with routes.ts
|
||||
const GET = "get",
|
||||
@@ -217,6 +218,16 @@ export function buildSharedApiRoutes({ route, asyncRoute, apiRoute, asyncApiRout
|
||||
// this "hacky" path is used for easier referencing of CSS resources
|
||||
route(GET, "/api/attachments/download/:attachmentId", [checkApiAuthOrElectron], filesRoute.downloadAttachment);
|
||||
//#endregion
|
||||
|
||||
//#region Export
|
||||
asyncRoute(PST, "/api/script/exec", [checkApiAuth, csrfMiddleware], scriptRoute.exec, apiResultHandler);
|
||||
|
||||
apiRoute(PST, "/api/script/run/:noteId", scriptRoute.run);
|
||||
apiRoute(GET, "/api/script/startup", scriptRoute.getStartupBundles);
|
||||
apiRoute(GET, "/api/script/widgets", scriptRoute.getWidgetBundles);
|
||||
apiRoute(PST, "/api/script/bundle/:noteId", scriptRoute.getBundle);
|
||||
apiRoute(GET, "/api/script/relation/:noteId/:relationName", scriptRoute.getRelationBundles);
|
||||
//#endregion
|
||||
}
|
||||
|
||||
/** Handling common patterns. If entity is not caught, serialization to JSON will fail */
|
||||
|
||||
Reference in New Issue
Block a user