From b393213ddacd40807679b909240f6e77c73820c9 Mon Sep 17 00:00:00 2001 From: Pas <74743263+Pasithea0@users.noreply.github.com> Date: Mon, 15 Sep 2025 10:04:58 -0500 Subject: [PATCH] use FED API for token check --- src/pages/parts/settings/SetupPart.tsx | 46 ++++++++++++++++++++------ 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/pages/parts/settings/SetupPart.tsx b/src/pages/parts/settings/SetupPart.tsx index a5f9518a..215427fb 100644 --- a/src/pages/parts/settings/SetupPart.tsx +++ b/src/pages/parts/settings/SetupPart.tsx @@ -20,6 +20,30 @@ import { conf } from "@/setup/config"; import { useAuthStore } from "@/stores/auth"; import { usePreferencesStore } from "@/stores/preferences"; +const getRegion = async (): Promise => { + if (typeof window === "undefined") return null; + try { + const regionData = window.localStorage.getItem("__MW::region"); + if (!regionData) return null; + const parsed = JSON.parse(regionData); + return parsed?.state?.region || null; + } catch { + return null; + } +}; + +function getRegionHeader(region: string | null): string { + if (region === "dallas") return "east"; + if (region === "portland") return "west"; + if (region === "new-york") return "east"; + if (region === "paris") return "europe"; + if (region === "hong-kong") return "asia"; + if (region === "kansas") return "south"; + if (region === "sydney") return "asia"; + if (region === "mumbai") return "asia"; + return "east"; +} + const testUrl = "https://postman-echo.com/get"; const sleep = (ms: number): Promise => { @@ -58,13 +82,14 @@ function testProxy(url: string) { } export async function testFebboxKey(febboxKey: string | null): Promise { - const BASE_URL = "https://febbox.andresdev.org"; - const febboxApiTestUrl = `${BASE_URL}/movie/950396`; + const febboxApiTestUrl = `https://fed-api.pstream.mov/movie/tt13654226`; if (!febboxKey) { return "unset"; } + const region = await getRegion(); + let attempts = 0; const maxAttempts = 2; @@ -76,6 +101,7 @@ export async function testFebboxKey(febboxKey: string | null): Promise { const response = await fetch(febboxApiTestUrl, { headers: { "ui-token": febboxKey, + region: getRegionHeader(region), }, }); @@ -95,7 +121,7 @@ export async function testFebboxKey(febboxKey: string | null): Promise { } const data = (await response.json()) as any; - if (!data || !data.sources) { + if (!data || !data.streams) { console.error("Invalid response format from Febbox API:", data); attempts += 1; if (attempts === maxAttempts) { @@ -107,14 +133,12 @@ export async function testFebboxKey(febboxKey: string | null): Promise { continue; } - const isVIPLink = - Array.isArray(data.sources) && - data.sources.some((source: any) => { - if (typeof source?.file === "string") { - return source.file.toLowerCase().includes("vip"); - } - return false; - }); + const isVIPLink = Object.values(data.streams).some((link: any) => { + if (typeof link === "string") { + return link.toLowerCase().includes("vip"); + } + return false; + }); if (isVIPLink) { console.log("VIP link found, returning success");