From f05e8fb19e3a4b8d49c65bf191fd76a9595546d9 Mon Sep 17 00:00:00 2001 From: Pas <74743263+Pasithea0@users.noreply.github.com> Date: Wed, 16 Apr 2025 20:45:15 -0600 Subject: [PATCH] get fed region --- src/providers/embeds/fedapi.ts | 37 +++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/providers/embeds/fedapi.ts b/src/providers/embeds/fedapi.ts index ec34b69..04f66d6 100644 --- a/src/providers/embeds/fedapi.ts +++ b/src/providers/embeds/fedapi.ts @@ -1,13 +1,40 @@ /* eslint-disable no-console */ + +// Thanks Nemo for this API! import { flags } from '@/entrypoint/utils/targets'; import { EmbedOutput, makeEmbed } from '@/providers/base'; import { NotFoundError } from '@/utils/errors'; import { Caption } from '../captions'; -// Thanks Nemo for this API! -const BASE_URL = 'https://fed-api.pstream.org'; -const CACHE_URL = 'https://fed-api.pstream.org/cache'; +const getRegion = (): string | null => { + try { + return typeof window !== 'undefined' ? window.localStorage.getItem('__MW::region') : null; + } catch (e) { + console.warn('Unable to access localStorage:', e); + return null; + } +}; + +const getBaseUrl = (): string => { + const region = getRegion(); + switch (region) { + case 'us-east': + return 'https://fed-api-east.pstream.org'; + case 'us-west': + return 'https://fed-api-west.pstream.org'; + case 'south-america': + return 'https://fed-api-south.pstream.org'; + case 'asia': + return 'https://fed-api-asia.pstream.org'; + case 'europe': + return 'https://fed-api-europe.pstream.org'; + default: + return 'https://fed-api-east.pstream.org'; + } +}; + +const BASE_URL = getBaseUrl(); // Language mapping for subtitles const languageMap: Record = { @@ -81,8 +108,8 @@ function embed(provider: { // Cache URL format apiUrl = query.type === 'movie' - ? `${CACHE_URL}/${query.imdbId}` - : `${CACHE_URL}/${query.imdbId}/${query.season}/${query.episode}`; + ? `${BASE_URL}/cache/${query.imdbId}` + : `${BASE_URL}/cache/${query.imdbId}/${query.season}/${query.episode}`; } else { // Standard API URL format apiUrl =