From 8399600e79ba030610a6f4bdc8a850906d453a5d Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 6 Jan 2026 16:29:30 +0200 Subject: [PATCH] chore(core): address some missing methods in utils --- apps/server/src/services/utils.ts | 5 +---- packages/trilium-core/src/services/keyboard_actions.ts | 2 +- packages/trilium-core/src/services/options_init.ts | 2 +- packages/trilium-core/src/services/utils/index.ts | 9 +++++++++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/apps/server/src/services/utils.ts b/apps/server/src/services/utils.ts index 861a8396f..5ad481211 100644 --- a/apps/server/src/services/utils.ts +++ b/apps/server/src/services/utils.ts @@ -33,10 +33,6 @@ export function randomString(length: number): string { return coreUtils.randomString(length); } -export function randomSecureToken(bytes = 32) { - return crypto.randomBytes(bytes).toString("base64"); -} - export function md5(content: crypto.BinaryLike) { return crypto.createHash("md5").update(content).digest("hex"); } @@ -459,6 +455,7 @@ function slugify(text: string) { export const escapeHtml = coreUtils.escapeHtml; export const unescapeHtml = coreUtils.unescapeHtml; +export const randomSecureToken = coreUtils.randomSecureToken; export default { compareVersions, diff --git a/packages/trilium-core/src/services/keyboard_actions.ts b/packages/trilium-core/src/services/keyboard_actions.ts index 0d20a886c..704a639ad 100644 --- a/packages/trilium-core/src/services/keyboard_actions.ts +++ b/packages/trilium-core/src/services/keyboard_actions.ts @@ -2,7 +2,7 @@ import optionService from "./options.js"; import { getLog } from "./log.js"; -import { isElectron, isMac } from "./utils.js"; +import { isElectron, isMac } from "./utils/index.js"; import type { ActionKeyboardShortcut, KeyboardShortcut } from "@triliumnext/commons"; import { t } from "i18next"; diff --git a/packages/trilium-core/src/services/options_init.ts b/packages/trilium-core/src/services/options_init.ts index a77727ec3..9b9ed9099 100644 --- a/packages/trilium-core/src/services/options_init.ts +++ b/packages/trilium-core/src/services/options_init.ts @@ -5,7 +5,7 @@ import dateUtils from "./utils/date.js"; import keyboardActions from "./keyboard_actions.js"; import { getLog } from "./log.js"; import optionService from "./options.js"; -import { isWindows, randomSecureToken } from "./utils.js"; +import { isWindows, randomSecureToken } from "./utils/index.js"; function initDocumentOptions() { optionService.createOption("documentId", randomSecureToken(16), false); diff --git a/packages/trilium-core/src/services/utils/index.ts b/packages/trilium-core/src/services/utils/index.ts index f33ccb039..e966f7237 100644 --- a/packages/trilium-core/src/services/utils/index.ts +++ b/packages/trilium-core/src/services/utils/index.ts @@ -5,6 +5,11 @@ import mimeTypes from "mime-types"; import escape from "escape-html"; import unescape from "unescape"; +// TODO: Implement platform detection. +export const isElectron = false; +export const isMac = false; +export const isWindows = false; + // render and book are string note in the sense that they are expected to contain empty string const STRING_NOTE_TYPES = new Set(["text", "code", "relationMap", "search", "render", "book", "mermaid", "canvas", "webView"]); const STRING_MIME_TYPES = new Set(["application/javascript", "application/x-javascript", "application/json", "application/x-sql", "image/svg+xml"]); @@ -117,3 +122,7 @@ export function toMap>(list: T[], key: keyof T) { export const escapeHtml = escape; export const unescapeHtml = unescape; + +export function randomSecureToken(bytes = 32) { + return encodeBase64(getCrypto().randomBytes(32)); +}