fix: proxy bangumi images

This commit is contained in:
jxxghp
2026-05-30 08:53:50 +08:00
parent 3387067636
commit ad6a664cbe
8 changed files with 51 additions and 50 deletions

View File

@@ -80,6 +80,39 @@ export function getLogoUrl(logoName: string): string {
return logoMap[logoName] || ''
}
/**
* 判断是否为需要强制走后端代理的 Bangumi 图片。
* @param url 图片地址
* @returns 是否为 Bangumi 图片地址
*/
export function isBangumiImageUrl(url: string): boolean {
if (!url) return false
try {
const hostname = new URL(url).hostname.toLowerCase()
return hostname === 'lain.bgm.tv' || hostname.endsWith('.lain.bgm.tv')
} catch {
return url.includes('lain.bgm.tv')
}
}
/**
* 将远程图片地址转换为前端可直接展示的地址。
* @param url 原始图片地址
* @param useCache 是否使用后端图片缓存
* @returns 转换后的图片地址
*/
export function getDisplayImageUrl(url: string, useCache = false): string {
if (!url || !/^https?:\/\//i.test(url)) return url
const encodedUrl = encodeURIComponent(url)
if (isBangumiImageUrl(url))
return `${import.meta.env.VITE_API_BASE_URL}system/img/1?imgurl=${encodedUrl}${useCache ? '&cache=true' : ''}`
if (useCache)
return `${import.meta.env.VITE_API_BASE_URL}system/cache/image?url=${encodedUrl}`
if (url.includes('doubanio.com'))
return `${import.meta.env.VITE_API_BASE_URL}system/img/0?imgurl=${encodedUrl}`
return url
}
/**
* 获取所有可用的图标名称
* @returns 图标名称数组