From e51d243324f1afa54d75aa2de74e9b616cfd01bb Mon Sep 17 00:00:00 2001 From: mofeng-git Date: Fri, 1 May 2026 21:27:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20MSD=20=E8=99=9A?= =?UTF-8?q?=E6=8B=9F=E7=9B=98=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E7=BC=96?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/api/index.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/web/src/api/index.ts b/web/src/api/index.ts index c8f485fd..58c726fa 100644 --- a/web/src/api/index.ts +++ b/web/src/api/index.ts @@ -560,15 +560,15 @@ export const msdApi = { }, downloadDriveFile: (path: string) => - `${API_BASE}/msd/drive/files${path.startsWith('/') ? path : '/' + path}`, + `${API_BASE}/msd/drive/files${encodeDrivePath(path)}`, deleteDriveFile: (path: string) => - request<{ success: boolean }>(`/msd/drive/files${path.startsWith('/') ? path : '/' + path}`, { + request<{ success: boolean }>(`/msd/drive/files${encodeDrivePath(path)}`, { method: 'DELETE', }), createDirectory: (path: string) => - request<{ success: boolean }>(`/msd/drive/mkdir${path.startsWith('/') ? path : '/' + path}`, { + request<{ success: boolean }>(`/msd/drive/mkdir${encodeDrivePath(path)}`, { method: 'POST', }), @@ -599,6 +599,22 @@ interface SerialDeviceOption { name: string } +function encodeDrivePath(path: string): string { + if (path === '' || path === '/') { + return '/' + } + + const hasLeadingSlash = path.startsWith('/') + const hasTrailingSlash = path.endsWith('/') + const encodedSegments = path + .split('/') + .filter(Boolean) + .map(segment => encodeURIComponent(segment)) + .join('/') + + return `${hasLeadingSlash ? '/' : ''}${encodedSegments}${hasTrailingSlash ? '/' : ''}` +} + function getSerialDevicePriority(path: string): number { if (/^\/dev\/ttyUSB/i.test(path)) return 0 if (/^\/dev\/(ttyS|S)/i.test(path)) return 2