From 136ea5830f1347e9818d2c4718c675b9e09055a9 Mon Sep 17 00:00:00 2001 From: Lan Date: Fri, 25 Apr 2025 22:31:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=80=82=E9=85=8Dwebdav=E5=9C=A8window?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E4=B8=8B=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/storage.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/core/storage.py b/core/storage.py index 39a7642..f4e2356 100644 --- a/core/storage.py +++ b/core/storage.py @@ -571,7 +571,7 @@ class WebDAVFileStorage(FileStorageInterface): self._initialized = True def _build_url(self, path: str) -> str: - encoded_path = quote(str(path).lstrip("/")) + encoded_path = quote(str(path.replace("\\", "/").lstrip("/")).lstrip("/")) return f"{self.base_url}{encoded_path}" async def _mkdir_p(self, directory_path: str): @@ -630,11 +630,9 @@ class WebDAVFileStorage(FileStorageInterface): # 分离文件名和目录路径 path_obj = Path(save_path) directory_path = str(path_obj.parent) - try: # 先创建目录结构 await self._mkdir_p(directory_path) - # 上传文件 url = self._build_url(save_path) async with aiohttp.ClientSession(auth=self.auth) as session: @@ -690,7 +688,7 @@ class WebDAVFileStorage(FileStorageInterface): if resp.status != 200: raise HTTPException( status_code=resp.status, - detail=f"文件获取失败: {await resp.text()}", + detail=f"文件获取失败{resp.status}: {await resp.text()}", ) # 读取内容到内存 content = await resp.read() @@ -708,8 +706,7 @@ class WebDAVFileStorage(FileStorageInterface): status_code=503, detail=f"WebDAV连接异常: {str(e)}") async def save_chunk(self, upload_id: str, chunk_index: int, chunk_data: bytes, chunk_hash: str, save_path: str): - chunk_path = str(Path(save_path).parent / "chunks" / - upload_id / f"{chunk_index}.part") + chunk_path = str(Path(save_path).parent / "chunks" / upload_id / f"{chunk_index}.part") chunk_url = self._build_url(chunk_path) async with aiohttp.ClientSession(auth=self.auth) as session: await session.put(chunk_url, data=chunk_data)