Add fallback for identity detail when server crashes on /api/v1/identity/:uuid

This commit is contained in:
Warren
2026-05-20 16:15:22 +08:00
parent b8ac27f9bb
commit e96e1842a8

View File

@@ -115,9 +115,29 @@ const loadDetail = async () => {
detail.value = result
profile.value = result.profile || {}
videos.value = result.videos || []
} catch (error) {
console.error('Failed to load identity detail:', error)
alert('載入失敗: ' + error)
} catch {
// Fallback: some API servers crash on /api/v1/identity/:uuid
try {
const config = getCurrentConfig()
const result = await httpFetch<any>(`${config.api_base_url}/api/v1/identities?uuid=${identityId.value}&page_size=1`)
const identity = (result.identities || [])[0]
if (identity) {
detail.value = identity
const meta = identity.metadata || {}
profile.value = {
name: identity.name,
character_name: meta.tmdb_character,
aliases: meta.tmdb_aliases,
gender: meta.tmdb_gender === 1 ? 'Female' : meta.tmdb_gender === 2 ? 'Male' : undefined,
age: meta.tmdb_birthday ? `${new Date().getFullYear() - new Date(meta.tmdb_birthday).getFullYear()} yrs` : undefined,
}
videos.value = []
} else {
throw new Error('Identity not found')
}
} catch (fallbackError) {
console.error('Failed to load identity detail:', fallbackError)
}
} finally {
loading.value = false
}