fix: 修复 Casimir 头像上传响应的解析(data 为 fileUrl 字符串,data2 为 objectKey)
实测确认:upload-resource 返回 { status:ok, data: <fileUrl字符串>, data2: <objectKey> },
此前按 data 为数组 [fileUrl,objectKey] 解析导致 fileUrl 落空、报"认证服务未返回头像地址"。
typo: 兼容 data/data2 为数组或字符串两种格式。
This commit is contained in:
@@ -193,9 +193,19 @@ export async function uploadAvatarToCasdoor(
|
|||||||
throw new CasdoorSyncError('连接认证服务失败,请稍后重试', 'NETWORK')
|
throw new CasdoorSyncError('连接认证服务失败,请稍后重试', 'NETWORK')
|
||||||
}
|
}
|
||||||
|
|
||||||
let json: { status?: string; msg?: string; data?: unknown[] } | null = null
|
let json: {
|
||||||
|
status?: string
|
||||||
|
msg?: string
|
||||||
|
data?: unknown
|
||||||
|
data2?: unknown
|
||||||
|
} | null = null
|
||||||
try {
|
try {
|
||||||
json = (await res.json()) as { status?: string; msg?: string; data?: unknown[] }
|
json = (await res.json()) as {
|
||||||
|
status?: string
|
||||||
|
msg?: string
|
||||||
|
data?: unknown
|
||||||
|
data2?: unknown
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
/* ignore */
|
/* ignore */
|
||||||
}
|
}
|
||||||
@@ -208,8 +218,15 @@ export async function uploadAvatarToCasdoor(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileUrl = String(Array.isArray(json.data) ? json.data[0] : '')
|
// Casimir 返回 data = fileUrl(字符串)、data2 = objectKey;兼容 data 为数组的旧格式
|
||||||
const objectKey = String(Array.isArray(json.data) ? json.data[1] : '')
|
const fileUrl = Array.isArray(json.data) ? String(json.data[0] || '') : String(json.data || '')
|
||||||
|
const objectKey = Array.isArray(json.data2)
|
||||||
|
? String(json.data2[0] || '')
|
||||||
|
: json.data2 !== undefined
|
||||||
|
? String(json.data2 || '')
|
||||||
|
: Array.isArray(json.data)
|
||||||
|
? String(json.data[1] || '')
|
||||||
|
: ''
|
||||||
if (!fileUrl) throw new CasdoorSyncError('认证服务未返回头像地址', 'UNKNOWN')
|
if (!fileUrl) throw new CasdoorSyncError('认证服务未返回头像地址', 'UNKNOWN')
|
||||||
return { fileUrl, objectKey }
|
return { fileUrl, objectKey }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user