From d232797889c39572ad9311bc912a30937f914099 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sun, 19 Oct 2025 03:14:33 +0200 Subject: [PATCH] clean up vesktop:// protocol handler --- src/main/userAssets.ts | 2 +- src/main/vesktopProtocol.ts | 18 ++++++++---------- src/main/vesktopStatic.ts | 4 +--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/userAssets.ts b/src/main/userAssets.ts index 6a39338..5fb0d4b 100644 --- a/src/main/userAssets.ts +++ b/src/main/userAssets.ts @@ -42,7 +42,7 @@ export async function resolveAssetPath(asset: UserAssetType) { } export async function handleVesktopAssetsProtocol(path: string, req: Request) { - const asset = path.replace(/\?v=\d+$/, "").replace(/\/+$/, ""); + const asset = path.slice(1); // @ts-expect-error dumb types if (!CUSTOMIZABLE_ASSETS.includes(asset)) { diff --git a/src/main/vesktopProtocol.ts b/src/main/vesktopProtocol.ts index 553692c..c05f5fe 100644 --- a/src/main/vesktopProtocol.ts +++ b/src/main/vesktopProtocol.ts @@ -11,17 +11,15 @@ import { handleVesktopStaticProtocol } from "./vesktopStatic"; app.whenReady().then(() => { protocol.handle("vesktop", async req => { - const url = decodeURI(req.url).slice("vesktop://".length); - const [channel, ...pathParts] = url.split("/"); - const path = pathParts.join("/"); + const url = new URL(req.url); - if (channel === "assets") { - return handleVesktopAssetsProtocol(path, req); + switch (url.hostname) { + case "assets": + return handleVesktopAssetsProtocol(url.pathname, req); + case "static": + return handleVesktopStaticProtocol(url.pathname, req); + default: + return new Response(null, { status: 404 }); } - if (channel === "static") { - return handleVesktopStaticProtocol(path, req); - } - - return new Response(null, { status: 404 }); }); }); diff --git a/src/main/vesktopStatic.ts b/src/main/vesktopStatic.ts index c2658f3..d5b4c47 100644 --- a/src/main/vesktopStatic.ts +++ b/src/main/vesktopStatic.ts @@ -13,9 +13,7 @@ import { isPathInDirectory } from "./utils/isPathInDirectory"; const STATIC_DIR = join(__dirname, "..", "..", "static"); export async function handleVesktopStaticProtocol(path: string, req: Request) { - const staticPath = new URL(path, "vesktop://").pathname; - - const fullPath = join(STATIC_DIR, staticPath); + const fullPath = join(STATIC_DIR, path); if (!isPathInDirectory(fullPath, STATIC_DIR)) { return new Response(null, { status: 404 }); }