✨ 新增回收站审计与八位取件码
This commit is contained in:
1 parent
c25c495657
commit
4ee06e2d29
15 files changed
+534
-132
No files matched your search
@@ -42,6 +42,10 @@ class FileStorageInterface:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
async def move_file(self, file_code: FileCodes, target_path: str) -> None:
|
||||
"""将现有文件移动到目标路径,供回收站使用。"""
|
||||
raise NotImplementedError
|
||||
|
||||
async def get_file_url(self, file_code: FileCodes):
|
||||
"""
|
||||
获取文件分享的url
|
||||
@@ -147,6 +151,14 @@ class SystemFileStorage(FileStorageInterface):
|
||||
if save_path.exists():
|
||||
save_path.unlink()
|
||||
|
||||
async def move_file(self, file_code: FileCodes, target_path: str) -> None:
|
||||
source_path = self._resolve_safe_path(await file_code.get_file_path())
|
||||
destination_path = self._resolve_safe_path(target_path)
|
||||
destination_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not source_path.exists():
|
||||
raise FileNotFoundError("回收站源文件不存在")
|
||||
await asyncio.to_thread(source_path.replace, destination_path)
|
||||
|
||||
async def get_file_url(self, file_code: FileCodes):
|
||||
return await get_file_url(file_code.code)
|
||||
|
||||
@@ -1164,6 +1176,23 @@ class WebDAVFileStorage(FileStorageInterface):
|
||||
raise HTTPException(
|
||||
status_code=503, detail=f"WebDAV连接异常: {str(e)}")
|
||||
|
||||
async def move_file(self, file_code: FileCodes, target_path: str) -> None:
|
||||
source_path = await file_code.get_file_path()
|
||||
source_url = self._build_url(source_path)
|
||||
target_url = self._build_url(target_path)
|
||||
await self._mkdir_p(str(Path(target_path).parent))
|
||||
try:
|
||||
async with aiohttp.ClientSession(auth=self.auth) as session:
|
||||
async with session.request("MOVE", source_url, headers={"Destination": target_url, "Overwrite": "F"}) as response:
|
||||
if response.status not in (201, 204):
|
||||
content = await response.text()
|
||||
raise HTTPException(
|
||||
status_code=response.status,
|
||||
detail=f"WebDAV移动到回收站失败: {content[:200]}",
|
||||
)
|
||||
except aiohttp.ClientError as e:
|
||||
raise HTTPException(status_code=503, detail=f"WebDAV连接异常: {str(e)}")
|
||||
|
||||
async def get_file_url(self, file_code: FileCodes):
|
||||
return await get_file_url(file_code.code)
|
||||
|
||||
|
||||
Reference in new issue
Block a user