Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(electron): use regions
Elian Doranfb87c07a45a4
diff --git a/apps/server/src/services/shell_validators.spec.ts b/apps/server/src/services/shell_validators.spec.tsindex d73ae2dea7..ca40c0946c 100644--- a/apps/server/src/services/shell_validators.spec.ts+++ b/apps/server/src/services/shell_validators.spec.ts@@ -11,9 +11,7 @@ import {validateOpenPath} from "./shell_validators.js";-// ============================================================================-// validateOpenCustomPath-// ============================================================================+//#region validateOpenCustomPathdescribe("validateOpenCustomPath", () => {let tmpDir: string;@@ -87,9 +85,9 @@ describe("validateOpenCustomPath", () => {);});-// ============================================================================-// validateOpenPath-// ============================================================================+//#endregion++//#region validateOpenPathdescribe("validateOpenPath", () => {let dataDir: string;@@ -189,9 +187,9 @@ describe("validateOpenPath", () => {);});-// ============================================================================-// validateOpenExternalUrl-// ============================================================================+//#endregion++//#region validateOpenExternalUrldescribe("validateOpenExternalUrl", () => {it("rejects malformed input", () => {@@ -262,9 +260,9 @@ describe("validateOpenExternalUrl", () => {});});-// ============================================================================-// validateOpenFileUrl-// ============================================================================+//#endregion++//#region validateOpenFileUrldescribe("validateOpenFileUrl", () => {it("rejects malformed input", () => {@@ -312,9 +310,9 @@ describe("validateOpenFileUrl", () => {);});-// ============================================================================-// validateDownloadUrl-// ============================================================================+//#endregion++//#region validateDownloadUrl// Trilium's desktop renderer is served via a custom protocol whose origin is// opaque per the WHATWG URL spec; this is the realistic page URL in production.@@ -388,3 +386,5 @@ describe("validateDownloadUrl", () => {.toBe("http://localhost:8080/api/notes/abc/download");});});++//#endregiondiff --git a/apps/server/src/services/shell_validators.ts b/apps/server/src/services/shell_validators.tsindex c47142322c..a0da59e455 100644--- a/apps/server/src/services/shell_validators.ts+++ b/apps/server/src/services/shell_validators.ts@@ -13,9 +13,7 @@ import { SHELL_OPEN_EXTERNAL_PROTOCOLS } from "@triliumnext/commons";* functions before invoking the underlying electron.shell / WebContents APIs.*/-// ============================================================================-// Shared helpers-// ============================================================================+//#region Shared helpers/** Windows filesystems are case-insensitive, POSIX are case-sensitive. */function normalizeForCompare(p: string): string {@@ -34,9 +32,9 @@ function isUnderOrEquals(resolved: string, root: string): boolean {|| isStrictlyUnder(resolved, root);}-// ============================================================================-// open-custom — sandbox to Trilium's tmp dir + existence check-// ============================================================================+//#endregion++//#region open-custom — sandbox to Trilium's tmp dir + existence check/*** Validates a path for the "open-custom" IPC channel (renderer asks the main@@ -61,9 +59,9 @@ export function validateOpenCustomPath(filePath: unknown, tmpDir: string): strinreturn resolved;}-// ============================================================================-// open-path — sandbox to Trilium's data dir ∪ tmp dir + existence check-// ============================================================================+//#endregion++//#region open-path — sandbox to Trilium's data dir ∪ tmp dir + existence check/*** Validates a path for the "open-path" IPC channel (Open Note Externally,@@ -92,9 +90,9 @@ export function validateOpenPath(input: unknown, dataDir: string, tmpDir: stringreturn resolved;}-// ============================================================================-// open-external — scheme allowlist-// ============================================================================+//#endregion++//#region open-external — scheme allowlist/*** Validates a URL for the "open-external" IPC channel (electron.shell.openExternal,@@ -124,9 +122,9 @@ export function validateOpenExternalUrl(input: unknown): URL {return parsed;}-// ============================================================================-// open-file-url — block UNC paths-// ============================================================================+//#endregion++//#region open-file-url — block UNC paths/*** Validates a URL for the "open-file-url" IPC channel and returns the@@ -163,9 +161,9 @@ export function validateOpenFileUrl(input: unknown): string {return url.fileURLToPath(parsed);}-// ============================================================================-// download-url — same-origin lock-// ============================================================================+//#endregion++//#region download-url — same-origin lock/*** Validates a URL for the "download-url" IPC channel (WebContents.downloadURL,@@ -217,3 +215,5 @@ export function validateDownloadUrl(input: unknown, allowedOrigin: string): URLreturn parsed;}++//#endregion