fix: harden discover artwork caching

This commit is contained in:
ShukeBta
2026-06-24 19:26:32 +08:00
parent d93a28f18f
commit aa506d6566
17 changed files with 658 additions and 104 deletions
+12 -2
View File
@@ -151,11 +151,21 @@ export function hlsURL(mediaId: string): string {
// imageURL converts a remote poster URL into a same-origin proxy URL so it
// can never be blocked by CORS / GFW. Empty strings pass through unchanged.
export function imageURL(remote?: string, version?: string, retryFailed = false): string {
export type ImageURLOptions =
| boolean
| {
refreshCache?: boolean
retryFailed?: boolean
}
export function imageURL(remote?: string, version?: string, options: ImageURLOptions = false): string {
if (!remote) return ''
const versionQuery = version ? `v=${encodeURIComponent(version)}` : ''
const retryFailed = typeof options === 'boolean' ? options : Boolean(options.retryFailed)
const refreshCache = typeof options === 'boolean' ? false : Boolean(options.refreshCache)
const retryQuery = retryFailed ? 'retry=1' : ''
const imageQuery = [versionQuery, retryQuery].filter(Boolean).join('&')
const refreshQuery = refreshCache ? 'refresh=1' : ''
const imageQuery = [versionQuery, retryQuery, refreshQuery].filter(Boolean).join('&')
if (remote.startsWith('/api/img')) return withQuery(withoutAuthQuery(remote), imageQuery)
if (remote.startsWith('/api/cloud/play/')) return withQuery(withoutAuthQuery(remote), imageQuery)
if (remote.startsWith('/api/')) return withQuery(withQuery(remote, tokenQuery()), imageQuery)