取消上传并清理临时文件
(upload_id: str)
| 505 | |
| 506 | @chunk_api.delete("/upload/{upload_id}", dependencies=[Depends(share_required_login)]) |
| 507 | async def cancel_upload(upload_id: str): |
| 508 | """取消上传并清理临时文件""" |
| 509 | chunk_info = await UploadChunk.filter(upload_id=upload_id, chunk_index=-1).first() |
| 510 | if not chunk_info: |
| 511 | raise HTTPException(status.HTTP_404_NOT_FOUND, detail="上传会话不存在") |
| 512 | |
| 513 | save_path = chunk_info.save_path |
| 514 | |
| 515 | # 清理存储中的临时文件 |
| 516 | storage = storages[settings.file_storage]() |
| 517 | if save_path: |
| 518 | try: |
| 519 | await storage.clean_chunks(upload_id, save_path) |
| 520 | except Exception as e: |
| 521 | pass |
| 522 | |
| 523 | # 清理数据库记录 |
| 524 | await UploadChunk.filter(upload_id=upload_id).delete() |
| 525 | |
| 526 | return APIResponse(detail={"message": "上传已取消"}) |
| 527 | |
| 528 | |
| 529 | @chunk_api.get( |
nothing calls this directly
no test coverage detected