clean up vesktop:// protocol handler

This commit is contained in:
Vendicated
2025-10-19 03:14:33 +02:00
parent fa23c630cb
commit d232797889
3 changed files with 10 additions and 14 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ export async function resolveAssetPath(asset: UserAssetType) {
} }
export async function handleVesktopAssetsProtocol(path: string, req: Request) { 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 // @ts-expect-error dumb types
if (!CUSTOMIZABLE_ASSETS.includes(asset)) { if (!CUSTOMIZABLE_ASSETS.includes(asset)) {
+8 -10
View File
@@ -11,17 +11,15 @@ import { handleVesktopStaticProtocol } from "./vesktopStatic";
app.whenReady().then(() => { app.whenReady().then(() => {
protocol.handle("vesktop", async req => { protocol.handle("vesktop", async req => {
const url = decodeURI(req.url).slice("vesktop://".length); const url = new URL(req.url);
const [channel, ...pathParts] = url.split("/");
const path = pathParts.join("/");
if (channel === "assets") { switch (url.hostname) {
return handleVesktopAssetsProtocol(path, req); 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 });
}); });
}); });
+1 -3
View File
@@ -13,9 +13,7 @@ import { isPathInDirectory } from "./utils/isPathInDirectory";
const STATIC_DIR = join(__dirname, "..", "..", "static"); const STATIC_DIR = join(__dirname, "..", "..", "static");
export async function handleVesktopStaticProtocol(path: string, req: Request) { export async function handleVesktopStaticProtocol(path: string, req: Request) {
const staticPath = new URL(path, "vesktop://").pathname; const fullPath = join(STATIC_DIR, path);
const fullPath = join(STATIC_DIR, staticPath);
if (!isPathInDirectory(fullPath, STATIC_DIR)) { if (!isPathInDirectory(fullPath, STATIC_DIR)) {
return new Response(null, { status: 404 }); return new Response(null, { status: 404 });
} }