From 55df6e6692ef8cad421cf5a600b1ba4a01eaf7ed Mon Sep 17 00:00:00 2001 From: Fijxu Date: Mon, 3 Feb 2025 16:28:16 -0300 Subject: [PATCH] feat: add env variable for verify_requests --- src/routes/invidious_routes/dashManifest.ts | 17 ++++++++++++----- src/routes/invidious_routes/latestVersion.ts | 10 +++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/routes/invidious_routes/dashManifest.ts b/src/routes/invidious_routes/dashManifest.ts index 1ea1d14..305b01f 100644 --- a/src/routes/invidious_routes/dashManifest.ts +++ b/src/routes/invidious_routes/dashManifest.ts @@ -22,13 +22,17 @@ dashManifest.get("/:videoId", async (c) => { Record >; - const maxDashResolution = Deno.env.get("SERVER_MAX_DASH_RESOLUTION") || konfigStore.get("server.max_dash_resolution") as number; + const maxDashResolution = Deno.env.get("SERVER_MAX_DASH_RESOLUTION") || + konfigStore.get("server.max_dash_resolution") as number; - if (konfigStore.get("server.verify_requests") && check == undefined) { + const verifyRequests = Deno.env.get("VERIFY_REQUESTS") || + konfigStore.get("server.verify_requests"); + + if (verifyRequests && check == undefined) { throw new HTTPException(400, { res: new Response("No check ID."), }); - } else if (konfigStore.get("server.verify_requests") && check) { + } else if (verifyRequests && check) { if (verifyRequest(check, videoId, konfigStore) === false) { throw new HTTPException(400, { res: new Response("ID incorrect."), @@ -96,8 +100,11 @@ dashManifest.get("/:videoId", async (c) => { let dashUrl = url; if (local) { // Can't create URL type without host part - dashUrl = (konfigStore.get("networking.external_videoplayback_proxy") as string ?? "") + (dashUrl.pathname + dashUrl.search + "&host=" + - dashUrl.host) as unknown as URL; + dashUrl = (konfigStore.get( + "networking.external_videoplayback_proxy", + ) as string ?? "") + + (dashUrl.pathname + dashUrl.search + "&host=" + + dashUrl.host) as unknown as URL; if (konfigStore.get("networking.ump") as boolean) { dashUrl = dashUrl + "&ump=1" as unknown as URL; } diff --git a/src/routes/invidious_routes/latestVersion.ts b/src/routes/invidious_routes/latestVersion.ts index b033aec..8232e86 100644 --- a/src/routes/invidious_routes/latestVersion.ts +++ b/src/routes/invidious_routes/latestVersion.ts @@ -26,12 +26,14 @@ latestVersion.get("/", async (c) => { const konfigStore = await c.get("konfigStore") as Store< Record >; + const verifyRequests = Deno.env.get("VERIFY_REQUESTS") || + konfigStore.get("server.verify_requests"); - if (konfigStore.get("server.verify_requests") && check == undefined) { + if (verifyRequests && check == undefined) { throw new HTTPException(400, { res: new Response("No check ID."), }); - } else if (konfigStore.get("server.verify_requests") && check) { + } else if (verifyRequests && check) { if (verifyRequest(check, id, konfigStore) === false) { throw new HTTPException(400, { res: new Response("ID incorrect."), @@ -69,7 +71,9 @@ latestVersion.get("/", async (c) => { const itagUrlParsed = new URL(itagUrl); let urlToRedirect = itagUrlParsed.toString(); if (local) { - urlToRedirect = (konfigStore.get("networking.external_videoplayback_proxy") as string ?? "") + + urlToRedirect = (konfigStore.get( + "networking.external_videoplayback_proxy", + ) as string ?? "") + itagUrlParsed.pathname + itagUrlParsed.search + "&host=" + itagUrlParsed.host; }