fix(listings): 首页卡片统一接入 AuthImage 解决私有对象存储鉴权加载失败问题
This commit is contained in:
@@ -47,7 +47,16 @@ export async function fetchAdminFileBlob(key: string) {
|
||||
}
|
||||
|
||||
export async function fetchFileBlobByURL(fileURL: string) {
|
||||
const apiPath = fileURL.startsWith('/api/') ? fileURL.slice(4) : fileURL
|
||||
let apiPath = fileURL
|
||||
try {
|
||||
const parsed = new URL(fileURL, window.location.origin)
|
||||
apiPath = parsed.pathname + parsed.search
|
||||
} catch {
|
||||
// keep as is
|
||||
}
|
||||
if (apiPath.startsWith('/api/')) {
|
||||
apiPath = apiPath.slice(4)
|
||||
}
|
||||
const { data } = await apiClient.get<Blob>(apiPath, {
|
||||
responseType: 'blob',
|
||||
})
|
||||
|
||||
@@ -416,10 +416,22 @@ export function isTopTierInsurance(value: string | undefined | null): boolean {
|
||||
export function getCoinScreenshotURL(item: Listing): string {
|
||||
const groups = item.asset_summary?.screenshot_groups
|
||||
if (typeof groups === 'object' && groups !== null) {
|
||||
const coinUrls = (groups as Record<string, unknown>)['coin']
|
||||
if (Array.isArray(coinUrls)) {
|
||||
const firstCoin = coinUrls.find(url => typeof url === 'string' && Boolean(url))
|
||||
if (firstCoin) return firstCoin
|
||||
const groupRecord = groups as Record<string, unknown>
|
||||
const orderedKeys = ['coin', 'tencentSecurity', 'skin', 'gameId', 'totalAsset']
|
||||
for (const key of orderedKeys) {
|
||||
const urls = groupRecord[key]
|
||||
if (Array.isArray(urls)) {
|
||||
const found = urls.find(url => typeof url === 'string' && Boolean(url))
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
for (const key of Object.keys(groupRecord)) {
|
||||
if (orderedKeys.includes(key)) continue
|
||||
const urls = groupRecord[key]
|
||||
if (Array.isArray(urls)) {
|
||||
const found = urls.find(url => typeof url === 'string' && Boolean(url))
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
}
|
||||
return item.cover_url || item.screenshot_urls?.[0] || ''
|
||||
|
||||
Reference in New Issue
Block a user