Files
JKVideo/utils/imageUrl.ts

26 lines
825 B
TypeScript
Raw Permalink Normal View History

import { Platform } from 'react-native';
/**
* Web B站图片 CDN URL Referer
* Native URLApp axios
*/
export function proxyImageUrl(url: string): string {
2026-03-12 21:21:01 +08:00
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://');
}
2026-03-19 16:34:56 +08:00
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;
}