File size: 777 Bytes
4bea261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const IMAGE_BASE_URL = 'https://phimimg.com';

/**
 * Hàm định dạng URL ảnh thành URL tuyệt đối (chạy được trên cả Client và Server)
 */
export const formatImageUrl = (url) => {
  if (!url) return '';
  let finalUrl = url;
  if (!url.startsWith('http')) {
    const cleanUrl = url.startsWith('/') ? url : `/${url}`;
    finalUrl = `${IMAGE_BASE_URL}${cleanUrl}`;
  }
  if (finalUrl.includes('phim1280') || finalUrl.includes('s2.phim1280.tv') || finalUrl.includes('img.ophim.tv')) {
    const cloudflareProxy = import.meta.env.PUBLIC_CLOUDFLARE_PROXY_URL;
    if (cloudflareProxy) {
      return `${cloudflareProxy}/?url=${encodeURIComponent(finalUrl)}`;
    }
    return `/api/proxy-media?url=${encodeURIComponent(finalUrl)}`;
  }
  return finalUrl;
};