Files
JKVideo/utils/imageUrl.ts
2026-03-19 16:34:56 +08:00

26 lines
825 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Platform } from 'react-native';
/**
* Web 端将 B站图片 CDN URL 转为本地代理地址,注入正确 Referer 绕过防盗链。
* Native 端直接返回原 URLApp 请求头由 axios 拦截器统一设置)。
*/
export function proxyImageUrl(url: string): string {
if (!url) return url;
if (Platform.OS === 'web') {
return url.replace(
/^https?:\/\/([a-z0-9]+\.hdslb\.com)/,
'http://localhost:3001/bilibili-img/$1',
);
}
// Native: force HTTPS so Release APK doesn't block cleartext HTTP
return url.replace(/^http:\/\//, 'https://');
}
export function coverImageUrl(url: string, quality: 'hd' | 'normal'): string {
const base = proxyImageUrl(url);
if (quality === 'normal' && base) {
return base.replace(/(@[\w]+)?$/, '@320w_180h_1c.webp');
}
return base;
}