clean up vesktop:// protocol handler
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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("/");
|
||||
|
||||
if (channel === "assets") {
|
||||
return handleVesktopAssetsProtocol(path, req);
|
||||
}
|
||||
if (channel === "static") {
|
||||
return handleVesktopStaticProtocol(path, req);
|
||||
}
|
||||
const url = new URL(req.url);
|
||||
|
||||
switch (url.hostname) {
|
||||
case "assets":
|
||||
return handleVesktopAssetsProtocol(url.pathname, req);
|
||||
case "static":
|
||||
return handleVesktopStaticProtocol(url.pathname, req);
|
||||
default:
|
||||
return new Response(null, { status: 404 });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user