feat: return upload job items for resume

This commit is contained in:
hailt 2026-11-12 22:42:11 +07:00
parent cf1e448a65
commit a82dc33f23
2 changed files with 12 additions and 1 deletions

View file

@ -38,7 +38,7 @@ async def create(project_id: str, body: CreateUploadJobIn,
@router.get("/{job_id}") @router.get("/{job_id}")
async def get(project_id: str, job_id: str, db: AsyncSession = Depends(get_session)): async def get(project_id: str, job_id: str, db: AsyncSession = Depends(get_session)):
data = await svc.get_job(job_id, db) data = await svc.get_job_detail(job_id, db)
if data["projectId"] != project_id: if data["projectId"] != project_id:
from fastapi import HTTPException from fastapi import HTTPException
raise HTTPException(404, "upload job not found") raise HTTPException(404, "upload job not found")

View file

@ -58,6 +58,17 @@ async def get_job(job_id: str, db: AsyncSession) -> dict:
return _job_dict(job) return _job_dict(job)
async def get_job_detail(job_id: str, db: AsyncSession) -> dict:
job = await db.get(UploadJob, job_id)
if job is None:
raise HTTPException(404, "upload job not found")
rows = (await db.execute(select(UploadItem).where(
UploadItem.job_id == job_id).order_by(UploadItem.created_at, UploadItem.id))).scalars().all()
items = [_item_dict(item, r2.presign_put(item.r2_key, item.content_type)
if item.status == "pending" else None) for item in rows]
return {**_job_dict(job), "items": items}
async def complete_item(job_id: str, item_id: str, width: int, height: int, async def complete_item(job_id: str, item_id: str, width: int, height: int,
db: AsyncSession) -> dict: db: AsyncSession) -> dict:
item = await db.get(UploadItem, item_id) item = await db.get(UploadItem, item_id)