Spaces:
Running

subrato1's picture
feat: enhance channel management and UI responsiveness
bf79491
Raw History Blame Contribute Delete
1.55 kB
import { Match, Channel } from '../types';
/**
* Dynamically resolves the correct backend API base URL based on environment.
* When running on Vercel or other production platforms, it automatically paths
* requests to the persistent, continuous Hugging Face container backend.
*/
export function getBackendBaseUrl(): string {
// 1. Check for explicit environment variable override
if (import.meta.env.VITE_STREAM_PROXY_URL) {
return import.meta.env.VITE_STREAM_PROXY_URL.replace(/\/$/, '');
}
// 2. Automagic host detection:
if (typeof window !== 'undefined') {
const hostname = window.location.hostname;
const isLocalDev = hostname === 'localhost' || hostname === '127.0.0.1';
const isAISHub = hostname.includes('run.app'); // AI Studio development environment
const isHFSpace = hostname.includes('hf.space'); // The HF Space itself
// If we are on Vercel or any other host, fall back to Hugging Face space backend
if (!isLocalDev && !isAISHub && !isHFSpace) {
return 'https://subrato1-kheladekhboweb.hf.space';
}
}
return '';
}
/**
* Determines the target watch path for a Live Match based on its assigned channels
*/
export function getMatchWatchUrl(match: Match, channels: Channel[]): string {
if (match.channelIds && match.channelIds.length > 0) {
const firstAssigned = channels.find(c => match.channelIds?.includes(c.id) && c.enabled !== false && c.hidden !== true);
if (firstAssigned) {
return `/player/${firstAssigned.id}`;
}
}
return '/live-tv';
}