From a464745a9f311be2b6d41f9c7e5c66e0a8a8a029 Mon Sep 17 00:00:00 2001 From: zl Date: Tue, 18 Nov 2025 10:26:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=9F=B3=E4=B9=90?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD401=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将原生fetch替换为ApiClient,确保JWT Authorization头正确发送 - 修复删除音乐、重命名音乐、保存音乐功能的认证问题 - 移除不必要的用户名密码字段,依赖JWT认证 - 解决因缺少Authorization头导致的401未授权错误 Issues Fixed: - 音乐删除失败返回401错误 - 音乐操作API调用缺少认证头 --- .../selected-sounds-display.tsx | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/src/components/selected-sounds-display/selected-sounds-display.tsx b/src/components/selected-sounds-display/selected-sounds-display.tsx index be40784..7515ccc 100644 --- a/src/components/selected-sounds-display/selected-sounds-display.tsx +++ b/src/components/selected-sounds-display/selected-sounds-display.tsx @@ -130,17 +130,9 @@ export function SelectedSoundsDisplay() { if (!isAuthenticated || !user) return; try { - const response = await fetch('/api/auth/music/rename', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - musicId, - name: newName, - username: user.username, - password: sessionPassword || '', - }), + const response = await ApiClient.post('/api/auth/music/rename', { + musicId, + name: newName }); if (!response.ok) { @@ -172,16 +164,8 @@ export function SelectedSoundsDisplay() { if (!confirm('确定要删除这首音乐吗?')) return; try { - const response = await fetch('/api/auth/music/delete', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - musicId, - username: user.username, - password: sessionPassword || '', - }), + const response = await ApiClient.post('/api/auth/music/delete', { + musicId }); if (!response.ok) { @@ -296,19 +280,11 @@ export function SelectedSoundsDisplay() { volume, speed, rate, - random_effects, - username: user?.username, - password: sessionPassword || '' // 使用会话密码,如果为空则让后端处理 + random_effects }; // 调用保存API - const response = await fetch('/api/auth/music/save', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(musicData), - }); + const response = await ApiClient.post('/api/auth/music/save', musicData); if (response.ok) { const result = await response.json();