fix: adopt legacy multipart uploads
This commit is contained in:
parent
35ce96fb56
commit
fd488e3e9b
1 changed files with 30 additions and 0 deletions
|
|
@ -32,6 +32,13 @@ class MultipartParts(BaseModel):
|
||||||
numbers: list[int] = Field(max_length=1000)
|
numbers: list[int] = Field(max_length=1000)
|
||||||
|
|
||||||
|
|
||||||
|
class MultipartAdopt(BaseModel):
|
||||||
|
fileName: str
|
||||||
|
contentType: str = "application/octet-stream"
|
||||||
|
key: str
|
||||||
|
uploadId: str
|
||||||
|
|
||||||
|
|
||||||
class PartETag(BaseModel):
|
class PartETag(BaseModel):
|
||||||
ETag: str
|
ETag: str
|
||||||
PartNumber: int
|
PartNumber: int
|
||||||
|
|
@ -91,6 +98,29 @@ async def part_urls(project_id: str, body: MultipartParts,
|
||||||
return {"urls": urls}
|
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")
|
@router.post("/multipart/complete")
|
||||||
async def complete_multipart(project_id: str, body: MultipartComplete,
|
async def complete_multipart(project_id: str, body: MultipartComplete,
|
||||||
db: AsyncSession = Depends(get_session)):
|
db: AsyncSession = Depends(get_session)):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue