⚡ perf(webdav): 偏移写入分片并取消整文件落盘合并
This commit is contained in:
1 parent
6d825e5fbc
commit
32298bfdeb
12 files changed
+690
-53
No files matched your search
+11
-1
@@ -1050,7 +1050,10 @@ class OpenDALFileStorage(FileStorageInterface):
|
||||
return False
|
||||
|
||||
|
||||
class WebDAVFileStorage(FileStorageInterface):
|
||||
from core.webdav_chunks import WebDAVOffsetMixin
|
||||
|
||||
|
||||
class WebDAVFileStorage(WebDAVOffsetMixin, FileStorageInterface):
|
||||
_instance: Optional["WebDAVFileStorage"] = None
|
||||
|
||||
def __init__(self):
|
||||
@@ -1255,6 +1258,9 @@ class WebDAVFileStorage(FileStorageInterface):
|
||||
|
||||
async def save_chunk(self, upload_id: str, chunk_index: int, chunk_data: bytes, chunk_hash: str, save_path: str):
|
||||
"""保存分片到 WebDAV"""
|
||||
info = await self._offset_session(upload_id)
|
||||
if info is not None:
|
||||
return await self.save_offset_chunk(info, chunk_index, chunk_data)
|
||||
chunk_dir = str(Path(save_path).parent / "chunks" / upload_id)
|
||||
chunk_path = f"{chunk_dir}/{chunk_index}.part"
|
||||
|
||||
@@ -1276,6 +1282,8 @@ class WebDAVFileStorage(FileStorageInterface):
|
||||
合并 WebDAV 上的分片文件
|
||||
使用临时文件避免内存问题
|
||||
"""
|
||||
if chunk_info.storage_mode == "webdav-offset":
|
||||
return await self.finish_offset_upload(chunk_info, save_path)
|
||||
file_sha256 = hashlib.sha256()
|
||||
chunk_dir = str(Path(save_path).parent / "chunks" / upload_id)
|
||||
|
||||
@@ -1346,6 +1354,8 @@ class WebDAVFileStorage(FileStorageInterface):
|
||||
:param upload_id: 上传会话ID
|
||||
:param save_path: 文件保存路径
|
||||
"""
|
||||
if await self._offset_session(upload_id) is not None:
|
||||
return await self.clean_offset_upload(upload_id, save_path)
|
||||
chunk_dir = str(Path(save_path).parent / "chunks" / upload_id)
|
||||
chunk_dir_url = self._build_url(chunk_dir)
|
||||
async with aiohttp.ClientSession(auth=self.auth) as session:
|
||||
|
||||
Reference in new issue
Block a user