refactor: split modules and harden scraping workflows

This commit is contained in:
ShukeBta
2026-06-24 11:59:18 +08:00
parent efca3cbe69
commit 192f35d9fa
470 changed files with 47957 additions and 33839 deletions
+20 -4
View File
@@ -151,11 +151,13 @@ 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): string {
export function imageURL(remote?: string, version?: string): string {
if (!remote) return ''
if (remote.startsWith('/api/img')) return remote
if (remote.startsWith('/api/')) return withQuery(remote, tokenQuery())
return `/api/img?url=${encodeURIComponent(remote)}&${tokenQuery()}`
const versionQuery = version ? `v=${encodeURIComponent(version)}` : ''
if (remote.startsWith('/api/img')) return withQuery(withoutAuthQuery(remote), versionQuery)
if (remote.startsWith('/api/cloud/play/')) return withQuery(withoutAuthQuery(remote), versionQuery)
if (remote.startsWith('/api/')) return withQuery(withQuery(remote, tokenQuery()), versionQuery)
return withQuery(`/api/img?url=${encodeURIComponent(remote)}`, versionQuery)
}
function withQuery(url: string, query: string): string {
@@ -163,6 +165,20 @@ function withQuery(url: string, query: string): string {
return `${url}${url.includes('?') ? '&' : '?'}${query}`
}
function withoutAuthQuery(url: string): string {
const hashIndex = url.indexOf('#')
const beforeHash = hashIndex >= 0 ? url.slice(0, hashIndex) : url
const hash = hashIndex >= 0 ? url.slice(hashIndex) : ''
const queryIndex = beforeHash.indexOf('?')
if (queryIndex < 0) return url
const path = beforeHash.slice(0, queryIndex)
const params = new URLSearchParams(beforeHash.slice(queryIndex + 1))
;['token', 'api_key', 'apiKey', 'ApiKey'].forEach((key) => params.delete(key))
const query = params.toString()
return `${path}${query ? `?${query}` : ''}${hash}`
}
// getToken returns the current auth token
export function getToken(): string | null {
return useAuthStore.getState().token