mirror of
https://github.com/yusufipk/YTChatHub.git
synced 2026-09-11 19:06:14 +00:00
28 lines
781 B
TypeScript
28 lines
781 B
TypeScript
const BACKEND_URL = process.env.NEXT_PUBLIC_BACKEND_URL ?? 'http://localhost:4100';
|
|
|
|
/**
|
|
* Converts a YouTube CDN image URL to use our backend proxy
|
|
* This prevents 429 rate limit errors from YouTube's CDN
|
|
*/
|
|
export function proxyImageUrl(url: string | undefined): string | undefined {
|
|
if (!url) return undefined;
|
|
|
|
// Check if it's a YouTube CDN URL
|
|
const youtubeCdnDomains = ['yt3.ggpht.com', 'yt4.ggpht.com', 'i.ytimg.com'];
|
|
|
|
try {
|
|
const urlObj = new URL(url);
|
|
if (youtubeCdnDomains.includes(urlObj.hostname)) {
|
|
// Proxy through our backend
|
|
return `${BACKEND_URL}/proxy/image?url=${encodeURIComponent(url)}`;
|
|
}
|
|
} catch {
|
|
// If URL parsing fails, return as-is
|
|
return url;
|
|
}
|
|
|
|
// Return non-YouTube URLs as-is
|
|
return url;
|
|
}
|
|
|