fix: adopt legacy multipart uploads

This commit is contained in:
hailt 2026-11-12 23:19:19 +07:00
parent 35ce96fb56
commit fd488e3e9b

View file

@ -32,6 +32,13 @@ class MultipartParts(BaseModel):
numbers: list[int] = Field(max_length=1000)
class MultipartAdopt(BaseModel):
fileName: str
contentType: str = "application/octet-stream"
key: str
uploadId: str
class PartETag(BaseModel):
ETag: str
PartNumber: int
@ -91,6 +98,29 @@ async def part_urls(project_id: str, body: MultipartParts,
return {"urls": urls}
@router.post("/multipart/adopt")
async def adopt_multipart(project_id: str, body: MultipartAdopt,
db: AsyncSession = Depends(get_session)):
"""Attach a multipart created by an older FE to a durable upload job."""
await _project_slug(project_id, db)
item = (await db.execute(select(UploadItem).where(
UploadItem.project_id == project_id,
UploadItem.r2_key == body.key,
UploadItem.multipart_upload_id == body.uploadId
))).scalar_one_or_none()
if item is not None:
return {"jobId": item.job_id, "itemId": item.id}
job = UploadJob(project_id=project_id, kind="zip", total_files=1)
db.add(job)
await db.flush()
item = UploadItem(project_id=project_id, job_id=job.id,
file_name=body.fileName, content_type=body.contentType,
r2_key=body.key, multipart_upload_id=body.uploadId)
db.add(item)
await db.commit()
return {"jobId": job.id, "itemId": item.id}
@router.post("/multipart/complete")
async def complete_multipart(project_id: str, body: MultipartComplete,
db: AsyncSession = Depends(get_session)):