chore(core) integrate options route

This commit is contained in:
Elian Doran 2026-01-06 20:12:03 +02:00
parent cbd2fc3966
commit b60501dd3f
No known key found for this signature in database
12 changed files with 81 additions and 51 deletions

View File

@ -35,6 +35,7 @@
"@triliumnext/highlightjs": "workspace:*",
"@triliumnext/share-theme": "workspace:*",
"@triliumnext/split.js": "workspace:*",
"@triliumnext/core": "workspace:*",
"@zumer/snapdom": "2.0.1",
"autocomplete.js": "0.38.1",
"bootstrap": "5.3.8",

View File

@ -2,7 +2,9 @@
// This will eventually import your core server and DB provider.
// import { createCoreServer } from "@trilium/core"; (bundled)
import { resizeMultipleElements } from '@excalidraw/excalidraw/element/resizeElements';
import sqlite3InitModule from '@sqlite.org/sqlite-wasm';
import { routes } from "@triliumnext/core";
const encoder = new TextEncoder();
@ -148,6 +150,20 @@ async function dispatch(request) {
return handleBootstrap();
}
if (request.method === "GET" && url.pathname === "/api/options") {
// console.log("Options route", routes);
// console.log("Got options request");
// try {
// // console.log(routes.optionsApiRoute.getOptions());
// // return jsonResponse(routes.optionsApiRoute.getOptions());
// } catch (e) {
// return jsonResponse({ ok: true, method: request.method, url: request.url });
// }
// console.log("Got ", routes.optionsApiRoute.getOptions());
// // return routes.optionsApiRoute.getOptions();
return jsonResponse("Hi");
}
if (url.pathname.startsWith("/api/echo")) {
return jsonResponse({ ok: true, method: request.method, url: request.url });
}

View File

@ -1,5 +1,5 @@
// public/sw.js
const VERSION = "localserver-v1.3";
const VERSION = "localserver-v1.4";
const STATIC_CACHE = `static-${VERSION}`;
// Check if running in dev mode (passed via URL parameter)

View File

@ -1,3 +1,4 @@
import { routes } from "@triliumnext/core";
import { createPartialContentHandler } from "@triliumnext/express-partial-content";
import express from "express";
import rateLimit from "express-rate-limit";
@ -41,7 +42,6 @@ import noteMapRoute from "./api/note_map.js";
import notesApiRoute from "./api/notes.js";
import ollamaRoute from "./api/ollama.js";
import openaiRoute from "./api/openai.js";
import optionsApiRoute from "./api/options.js";
import otherRoute from "./api/other.js";
import passwordApiRoute from "./api/password.js";
import recentChangesApiRoute from "./api/recent_changes.js";
@ -211,6 +211,7 @@ function register(app: express.Application) {
route(GET, "/api/images/:noteId/:filename", [auth.checkApiAuthOrElectron], imageRoute.returnImageFromNote);
route(PUT, "/api/images/:noteId", [auth.checkApiAuthOrElectron, uploadMiddlewareWithErrorHandling, csrfMiddleware], imageRoute.updateImage, apiResultHandler);
const { optionsApiRoute } = routes;
apiRoute(GET, "/api/options", optionsApiRoute.getOptions);
// FIXME: possibly change to sending value in the body to avoid host of HTTP server issues with slashes
apiRoute(PUT, "/api/options/:name/:value", optionsApiRoute.updateOption);

View File

@ -1,10 +1,11 @@
import { type Dayjs, dayjs, type Locale, type LOCALE_IDS,LOCALES, setDayjsLocale } from "@triliumnext/commons";
import i18next from "i18next";
import { join } from "path";
import hidden_subtree from "./hidden_subtree.js";
import options from "./options.js";
import sql_init from "./sql_init.js";
import { join } from "path";
import { getResourceDir } from "./utils.js";
import hidden_subtree from "./hidden_subtree.js";
import { dayjs, LOCALES, setDayjsLocale, type Dayjs, type Locale, type LOCALE_IDS } from "@triliumnext/commons";
export async function initializeTranslations() {
const resourceDir = getResourceDir();

View File

@ -54,6 +54,7 @@ export type { NotePojo } from "./becca/becca-interface";
export { default as NoteSet } from "./services/search/note_set";
export { default as note_service, NoteParams } from "./services/notes";
export * as sanitize from "./services/sanitizer";
export * as routes from "./routes";
export function initializeCore({ dbConfig, executionContext, crypto }: {
dbConfig: SqlServiceParams,

View File

@ -1,14 +1,14 @@
import type { OptionNames } from "@triliumnext/commons";
import { ValidationError } from "@triliumnext/core";
import type { Request } from "express";
import config from "../../services/config.js";
import { changeLanguage, getLocales } from "../../services/i18n.js";
import log from "../../services/log.js";
import { getLog } from "../../services/log.js";
import optionService from "../../services/options.js";
import searchService from "../../services/search/services/search.js";
import { ValidationError } from "../../errors.js";
interface UserTheme {
val: string; // value of the theme, used in the URL
@ -122,6 +122,7 @@ const ALLOWED_OPTIONS = new Set<OptionNames>([
]);
function getOptions() {
console.log("Got opts");
const optionMap = optionService.getOptionMap();
const resultMap: Record<string, string> = {};
@ -166,7 +167,7 @@ function update(name: string, value: string) {
}
if (name !== "openNoteContexts") {
log.info(`Updating option '${name}' to '${value}'`);
getLog().info(`Updating option '${name}' to '${value}'`);
}
optionService.setOption(name as OptionNames, value);

View File

@ -0,0 +1 @@
export { default as optionsApiRoute } from "./api/options";

View File

@ -0,0 +1,6 @@
// TODO: Real implementation.
export default {
General: {
readOnly: false
}
};

View File

@ -0,0 +1,10 @@
import { LOCALES } from "@triliumnext/commons";
// TODO: Real impl.
export function changeLanguage(languageCode: string) {
console.log("Got request to change language", languageCode);
}
export function getLocales() {
return LOCALES;
}

View File

@ -5,7 +5,7 @@ export default {
console.warn("Ignore search ", note.title);
},
searchNotes(searchString: string) {
searchNotes(searchString: string, opts: {}): BNote[] {
console.warn("Ignore search", searchString);
return [];
}

76
pnpm-lock.yaml generated
View File

@ -205,6 +205,9 @@ importers:
'@triliumnext/commons':
specifier: workspace:*
version: link:../../packages/commons
'@triliumnext/core':
specifier: workspace:*
version: link:../../packages/trilium-core
'@triliumnext/highlightjs':
specifier: workspace:*
version: link:../../packages/highlightjs
@ -516,9 +519,6 @@ importers:
'@anthropic-ai/sdk':
specifier: 0.71.2
version: 0.71.2(zod@4.1.12)
'@braintree/sanitize-url':
specifier: 7.1.1
version: 7.1.1
'@electron/remote':
specifier: 2.1.3
version: 2.1.3(electron@39.2.7)
@ -561,9 +561,6 @@ importers:
'@types/ejs':
specifier: 3.1.5
version: 3.1.5
'@types/escape-html':
specifier: 1.0.4
version: 1.0.4
'@types/express-http-proxy':
specifier: 1.6.7
version: 1.6.7
@ -579,18 +576,12 @@ importers:
'@types/ini':
specifier: 4.1.1
version: 4.1.1
'@types/mime-types':
specifier: 3.0.1
version: 3.0.1
'@types/multer':
specifier: 2.0.0
version: 2.0.0
'@types/safe-compare':
specifier: 1.1.2
version: 1.1.2
'@types/sanitize-html':
specifier: 2.16.0
version: 2.16.0
'@types/sax':
specifier: 1.2.7
version: 1.2.7
@ -672,9 +663,6 @@ importers:
electron-window-state:
specifier: 5.0.3
version: 5.0.3
escape-html:
specifier: 1.0.3
version: 1.0.3
express:
specifier: 5.2.1
version: 5.2.1
@ -738,9 +726,6 @@ importers:
marked:
specifier: 17.0.1
version: 17.0.1
mime-types:
specifier: 3.0.2
version: 3.0.2
multer:
specifier: 2.0.2
version: 2.0.2
@ -759,12 +744,6 @@ importers:
safe-compare:
specifier: 1.1.4
version: 1.1.4
sanitize-filename:
specifier: 1.6.3
version: 1.6.3
sanitize-html:
specifier: 2.17.0
version: 2.17.0
sax:
specifier: 1.4.3
version: 1.4.3
@ -795,9 +774,6 @@ importers:
turndown:
specifier: 7.2.2
version: 7.2.2
unescape:
specifier: 1.0.1
version: 1.0.1
vite:
specifier: 7.3.0
version: 7.3.0(@types/node@24.10.4)(jiti@2.6.1)(less@4.1.3)(lightningcss@1.30.1)(sass-embedded@1.91.0)(sass@1.91.0)(terser@5.44.0)(tsx@4.21.0)(yaml@2.8.1)
@ -1449,9 +1425,37 @@ importers:
packages/trilium-core:
dependencies:
'@braintree/sanitize-url':
specifier: 7.1.1
version: 7.1.1
'@triliumnext/commons':
specifier: workspace:*
version: link:../commons
escape-html:
specifier: 1.0.3
version: 1.0.3
mime-types:
specifier: 3.0.2
version: 3.0.2
sanitize-filename:
specifier: 1.6.3
version: 1.6.3
sanitize-html:
specifier: 2.17.0
version: 2.17.0
unescape:
specifier: 1.0.1
version: 1.0.1
devDependencies:
'@types/escape-html':
specifier: 1.0.4
version: 1.0.4
'@types/mime-types':
specifier: 3.0.1
version: 3.0.1
'@types/sanitize-html':
specifier: 2.16.0
version: 2.16.0
packages/turndown-plugin-gfm:
devDependencies:
@ -11860,10 +11864,6 @@ packages:
resolution: {integrity: sha512-OCVPnIObs4N29kxTjzLfUryOkvZEq+pf8jTF0lg8E7uETuWHA+v7j3c/xJmiqpX450191LlmZfUKkXxkTry7nA==}
engines: {node: ^10 || ^12 || >=14}
postcss@8.5.3:
resolution: {integrity: sha512-dle9A3yYxlBSrt8Fu+IpjGT8SY8hN0mlaA6GY8t0P5PjIOZemULz/E2Bnm/2dcUOena75OTNkHI76uZBNUUq3A==}
engines: {node: ^10 || ^12 || >=14}
postcss@8.5.6:
resolution: {integrity: sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==}
engines: {node: ^10 || ^12 || >=14}
@ -15444,8 +15444,6 @@ snapshots:
'@ckeditor/ckeditor5-utils': 47.3.0
'@ckeditor/ckeditor5-watchdog': 47.3.0
es-toolkit: 1.39.5
transitivePeerDependencies:
- supports-color
'@ckeditor/ckeditor5-dev-build-tools@54.2.3(@swc/helpers@0.5.17)(tslib@2.8.1)(typescript@5.9.3)':
dependencies:
@ -15571,8 +15569,6 @@ snapshots:
'@ckeditor/ckeditor5-utils': 47.3.0
ckeditor5: 47.3.0
es-toolkit: 1.39.5
transitivePeerDependencies:
- supports-color
'@ckeditor/ckeditor5-editor-classic@47.3.0':
dependencies:
@ -16111,6 +16107,8 @@ snapshots:
'@ckeditor/ckeditor5-ui': 47.3.0
'@ckeditor/ckeditor5-utils': 47.3.0
ckeditor5: 47.3.0
transitivePeerDependencies:
- supports-color
'@ckeditor/ckeditor5-restricted-editing@47.3.0':
dependencies:
@ -28168,12 +28166,6 @@ snapshots:
picocolors: 1.1.1
source-map-js: 1.2.1
postcss@8.5.3:
dependencies:
nanoid: 3.3.11
picocolors: 1.1.1
source-map-js: 1.2.1
postcss@8.5.6:
dependencies:
nanoid: 3.3.11
@ -28974,7 +28966,7 @@ snapshots:
htmlparser2: 8.0.2
is-plain-object: 5.0.0
parse-srcset: 1.0.2
postcss: 8.5.3
postcss: 8.5.6
sass-embedded-all-unknown@1.91.0:
dependencies: