From 56f56d127d3cd9c3f1d1c5e5936f556ed36fb52b Mon Sep 17 00:00:00 2001 From: chenchun Date: Sun, 9 Aug 2026 04:57:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Casimir=20=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E4=B8=8A=E4=BC=A0=E5=93=8D=E5=BA=94=E7=9A=84=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=EF=BC=88data=20=E4=B8=BA=20fileUrl=20=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=EF=BC=8Cdata2=20=E4=B8=BA=20objectKey?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实测确认:upload-resource 返回 { status:ok, data: , data2: }, 此前按 data 为数组 [fileUrl,objectKey] 解析导致 fileUrl 落空、报"认证服务未返回头像地址"。 typo: 兼容 data/data2 为数组或字符串两种格式。 --- server/utils/casdoorSync.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/server/utils/casdoorSync.ts b/server/utils/casdoorSync.ts index b14e5cd..4526ea5 100644 --- a/server/utils/casdoorSync.ts +++ b/server/utils/casdoorSync.ts @@ -193,9 +193,19 @@ export async function uploadAvatarToCasdoor( 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 { - 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 { /* ignore */ } @@ -208,8 +218,15 @@ export async function uploadAvatarToCasdoor( ) } - const fileUrl = String(Array.isArray(json.data) ? json.data[0] : '') - const objectKey = String(Array.isArray(json.data) ? json.data[1] : '') + // Casimir 返回 data = fileUrl(字符串)、data2 = objectKey;兼容 data 为数组的旧格式 + 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') return { fileUrl, objectKey } }