播放器更新

This commit is contained in:
YGC
2026-07-14 18:43:40 +08:00
parent e2e7cf85b1
commit a57b66189c
43 changed files with 5908 additions and 529 deletions
+30 -2
View File
@@ -1,10 +1,38 @@
import request, { getServerApiURL } from './request'
import { cache } from 'react'
export interface PublicConfigItem {
configKey: string
configValue: string
}
export function getPublicConfig() {
return request.get('/config/public')
}
export async function fetchPublicConfigForServer(init?: Parameters<typeof fetch>[1]) {
const response = await fetch(getServerApiURL('/config/public'), init)
return response.json()
try {
const response = await fetch(getServerApiURL('/config/public'), {
...init,
// 容错超时防刷屏
signal: AbortSignal.timeout(3000)
})
if (!response.ok) {
return { code: response.status, data: [] }
}
return await response.json()
} catch {
// 静默兜底,避免打印庞大的 Socket 异常日志
return { code: 500, data: [] }
}
}
export const getPublicConfigSnapshot = cache(async (): Promise<PublicConfigItem[]> => {
const payload = await fetchPublicConfigForServer({ next: { revalidate: 10 } })
if (payload.code !== 200 || !Array.isArray(payload.data)) return []
return payload.data.filter((item: unknown): item is PublicConfigItem => {
if (!item || typeof item !== 'object') return false
const candidate = item as Partial<PublicConfigItem>
return typeof candidate.configKey === 'string' && typeof candidate.configValue === 'string'
})
})