修复讲解详情接口并展示展厅统计
This commit is contained in:
@@ -131,9 +131,16 @@ const requestJson = <T>(url: string): Promise<T> => new Promise((resolve, reject
|
||||
})
|
||||
})
|
||||
|
||||
let guideAudioApiUnavailable = false
|
||||
const unavailableAudioApiEndpoints = new Set<'stopInfo' | 'playInfo' | 'textInfo'>()
|
||||
|
||||
const normalizeBaseUrl = (baseUrl: string) => baseUrl.replace(/\/+$/, '')
|
||||
const normalizeBaseUrl = (baseUrl: string) => {
|
||||
const trimmed = baseUrl.trim().replace(/\/+$/, '')
|
||||
if (!trimmed || /^https?:\/\//i.test(trimmed) || trimmed.startsWith('/')) {
|
||||
return trimmed
|
||||
}
|
||||
|
||||
return `/${trimmed}`
|
||||
}
|
||||
|
||||
const resolveAudioApiBaseUrl = () => {
|
||||
const baseUrl = normalizeBaseUrl(dataSourceConfig.audioApiBaseUrl)
|
||||
@@ -160,9 +167,12 @@ const isMissingRouteResponse = (response: { code: number; msg?: string }) => (
|
||||
response.code === 404 && /请求地址不存在/.test(response.msg || '')
|
||||
)
|
||||
|
||||
const markGuideAudioApiUnavailable = (response: { code: number; msg?: string }) => {
|
||||
const markGuideAudioApiUnavailable = (
|
||||
endpoint: 'stopInfo' | 'playInfo' | 'textInfo',
|
||||
response: { code: number; msg?: string }
|
||||
) => {
|
||||
if (isMissingRouteResponse(response)) {
|
||||
guideAudioApiUnavailable = true
|
||||
unavailableAudioApiEndpoints.add(endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +186,7 @@ export class DefaultAudioPlayInfoRepository implements AudioPlayInfoRepository {
|
||||
private readonly textCache = new Map<string, AudioTextInfo>()
|
||||
|
||||
async getStopInfo(request: GuideStopInfoRequest): Promise<GuideStopInfo> {
|
||||
if (guideAudioApiUnavailable) {
|
||||
if (unavailableAudioApiEndpoints.has('stopInfo')) {
|
||||
throw new Error('讲解展示信息接口暂不可用')
|
||||
}
|
||||
|
||||
@@ -201,7 +211,7 @@ export class DefaultAudioPlayInfoRepository implements AudioPlayInfoRepository {
|
||||
const response = await requestJson<GuideStopInfoResponse>(url)
|
||||
|
||||
if (response.code !== 0 || !response.data) {
|
||||
markGuideAudioApiUnavailable(response)
|
||||
markGuideAudioApiUnavailable('stopInfo', response)
|
||||
throw new Error(response.msg || '讲解点展示信息加载失败')
|
||||
}
|
||||
|
||||
@@ -217,7 +227,7 @@ export class DefaultAudioPlayInfoRepository implements AudioPlayInfoRepository {
|
||||
lang: request.lang || (dataSourceConfig.audioLanguage as AudioLanguage)
|
||||
}
|
||||
const key = audioKey(normalizedRequest)
|
||||
if (guideAudioApiUnavailable) {
|
||||
if (unavailableAudioApiEndpoints.has('playInfo')) {
|
||||
return {
|
||||
playable: false,
|
||||
targetType: normalizedRequest.targetType,
|
||||
@@ -242,7 +252,7 @@ export class DefaultAudioPlayInfoRepository implements AudioPlayInfoRepository {
|
||||
const response = await requestJson<AudioPlayInfoResponse>(url)
|
||||
|
||||
if (response.code !== 0 || !response.data) {
|
||||
markGuideAudioApiUnavailable(response)
|
||||
markGuideAudioApiUnavailable('playInfo', response)
|
||||
throw new Error(response.msg || '语音播放解析失败')
|
||||
}
|
||||
|
||||
@@ -262,7 +272,7 @@ export class DefaultAudioPlayInfoRepository implements AudioPlayInfoRepository {
|
||||
lang: request.lang || (dataSourceConfig.audioLanguage as AudioLanguage)
|
||||
}
|
||||
const key = audioTextKey(normalizedRequest)
|
||||
if (guideAudioApiUnavailable) {
|
||||
if (unavailableAudioApiEndpoints.has('textInfo')) {
|
||||
return {
|
||||
available: false,
|
||||
targetType: normalizedRequest.targetType,
|
||||
@@ -287,7 +297,7 @@ export class DefaultAudioPlayInfoRepository implements AudioPlayInfoRepository {
|
||||
const response = await requestJson<AudioTextInfoResponse>(url)
|
||||
|
||||
if (response.code !== 0 || !response.data) {
|
||||
markGuideAudioApiUnavailable(response)
|
||||
markGuideAudioApiUnavailable('textInfo', response)
|
||||
throw new Error(response.msg || '讲解词正文解析失败')
|
||||
}
|
||||
|
||||
@@ -303,7 +313,7 @@ export class DefaultAudioPlayInfoRepository implements AudioPlayInfoRepository {
|
||||
this.stopInfoCache.clear()
|
||||
this.cache.clear()
|
||||
this.textCache.clear()
|
||||
guideAudioApiUnavailable = false
|
||||
unavailableAudioApiEndpoints.clear()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user