mirror of
https://github.com/p-stream/p-stream.git
synced 2026-03-11 17:55:33 +00:00
use FED API for token check
This commit is contained in:
parent
fa2693c9b2
commit
b393213dda
1 changed files with 35 additions and 11 deletions
|
|
@ -20,6 +20,30 @@ import { conf } from "@/setup/config";
|
|||
import { useAuthStore } from "@/stores/auth";
|
||||
import { usePreferencesStore } from "@/stores/preferences";
|
||||
|
||||
const getRegion = async (): Promise<string | null> => {
|
||||
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<void> => {
|
||||
|
|
@ -58,13 +82,14 @@ function testProxy(url: string) {
|
|||
}
|
||||
|
||||
export async function testFebboxKey(febboxKey: string | null): Promise<Status> {
|
||||
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<Status> {
|
|||
const response = await fetch(febboxApiTestUrl, {
|
||||
headers: {
|
||||
"ui-token": febboxKey,
|
||||
region: getRegionHeader(region),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -95,7 +121,7 @@ export async function testFebboxKey(febboxKey: string | null): Promise<Status> {
|
|||
}
|
||||
|
||||
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<Status> {
|
|||
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");
|
||||
|
|
|
|||
Loading…
Reference in a new issue