chore(core): address some missing methods in utils

This commit is contained in:
Elian Doran 2026-01-06 16:29:30 +02:00
parent edac58f3fa
commit 8399600e79
No known key found for this signature in database
4 changed files with 12 additions and 6 deletions

View File

@ -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,

View File

@ -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";

View File

@ -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);

View File

@ -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<T extends Record<string, any>>(list: T[], key: keyof T) {
export const escapeHtml = escape;
export const unescapeHtml = unescape;
export function randomSecureToken(bytes = 32) {
return encodeBase64(getCrypto().randomBytes(32));
}