⚡️ perf: 使用 CloudDrive 原生分片写入避免整文件重传
* 保留 90MiB 浏览器分片并按 1MiB 原生请求写入同一文件 * 持久化文件句柄并恢复响应丢失、重复分片和完成状态 * 完整校验后发布,取消和过期清理等待远端写入结束 * 保持旧会话兼容并验证真实 gRPC 和 WebDAV 上传生命周期
This commit is contained in:
1 parent
2ba7bace02
commit
a887a8acd5
10 files changed
+774
-8
No files matched your search
+6
-6
@@ -576,7 +576,7 @@ async def upload_chunk(
|
||||
existing_chunk = await UploadChunk.filter(
|
||||
upload_id=upload_id, chunk_index=chunk_index, completed=True
|
||||
).first()
|
||||
if existing_chunk and chunk_info.storage_mode not in {"webdav-offset", "webdav-stream"}:
|
||||
if existing_chunk and chunk_info.storage_mode not in {"webdav-offset", "webdav-stream", "clouddrive-native"}:
|
||||
return APIResponse(
|
||||
detail={"chunk_hash": existing_chunk.chunk_hash, "skipped": True}
|
||||
)
|
||||
@@ -610,7 +610,7 @@ async def upload_chunk(
|
||||
expected_size = min(chunk_info.chunk_size, chunk_info.file_size-chunk_index*chunk_info.chunk_size)
|
||||
if chunk_size != expected_size:
|
||||
raise HTTPException(400, "分片大小与声明值不一致")
|
||||
if chunk_info.storage_mode in {"webdav-offset", "webdav-stream"}:
|
||||
if chunk_info.storage_mode in {"webdav-offset", "webdav-stream", "clouddrive-native"}:
|
||||
if existing_chunk:
|
||||
if existing_chunk.chunk_hash != chunk_hash:
|
||||
raise HTTPException(409, "重传分片内容不一致")
|
||||
@@ -709,7 +709,7 @@ async def _cancel_upload(upload_id):
|
||||
try:
|
||||
await storage.clean_chunks(upload_id, save_path)
|
||||
except Exception as e:
|
||||
if chunk_info.storage_mode in {"webdav-offset", "webdav-stream"}:
|
||||
if chunk_info.storage_mode in {"webdav-offset", "webdav-stream", "clouddrive-native"}:
|
||||
raise
|
||||
pass
|
||||
|
||||
@@ -762,7 +762,7 @@ async def complete_upload(
|
||||
info = await UploadChunk.filter(upload_id=upload_id, chunk_index=-1).first()
|
||||
if is_cancelling(upload_id):
|
||||
raise HTTPException(409, "上传正在取消")
|
||||
if info is None or info.storage_mode not in {"webdav-offset", "webdav-stream"}:
|
||||
if info is None or info.storage_mode not in {"webdav-offset", "webdav-stream", "clouddrive-native"}:
|
||||
return await _complete_upload(upload_id, data, ip)
|
||||
task = completion_task(upload_id)
|
||||
if task is None:
|
||||
@@ -808,7 +808,7 @@ async def _complete_upload(upload_id, data, ip):
|
||||
try:
|
||||
await storage.clean_chunks(upload_id, save_path)
|
||||
except Exception:
|
||||
if chunk_info.storage_mode in {"webdav-offset", "webdav-stream"}:
|
||||
if chunk_info.storage_mode in {"webdav-offset", "webdav-stream", "clouddrive-native"}:
|
||||
raise
|
||||
pass
|
||||
await UploadChunk.filter(upload_id=upload_id).delete()
|
||||
@@ -857,7 +857,7 @@ async def _complete_upload(upload_id, data, ip):
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
if chunk_info.storage_mode in {"webdav-offset", "webdav-stream"}:
|
||||
if chunk_info.storage_mode in {"webdav-offset", "webdav-stream", "clouddrive-native"}:
|
||||
raise HTTPException(500, "上传完成状态保存失败,请重试完成上传") from e
|
||||
# 合并失败时清理临时文件
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user