feat: add durable upload job API and SSE progress

This commit is contained in:
hailt 2026-11-12 22:40:24 +07:00
parent 2b8f8551ce
commit cf1e448a65
5 changed files with 196 additions and 2 deletions

View file

@ -120,6 +120,37 @@ class ImportJob(Base):
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
class UploadJob(Base):
"""Durable browser upload batch; bytes live in object storage."""
__tablename__ = "upload_jobs"
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_uid)
project_id: Mapped[str] = mapped_column(String(32), index=True)
kind: Mapped[str] = mapped_column(String(32), default="images")
status: Mapped[str] = mapped_column(String(32), default="uploading", index=True)
total_files: Mapped[int] = mapped_column(Integer, default=0)
uploaded_files: Mapped[int] = mapped_column(Integer, default=0)
processed_files: Mapped[int] = mapped_column(Integer, default=0)
failed_files: Mapped[int] = mapped_column(Integer, default=0)
error: Mapped[str | None] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
class UploadItem(Base):
__tablename__ = "upload_items"
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_uid)
job_id: Mapped[str] = mapped_column(ForeignKey("upload_jobs.id", ondelete="CASCADE"), index=True)
project_id: Mapped[str] = mapped_column(String(32), index=True)
file_name: Mapped[str] = mapped_column(String(1024))
content_type: Mapped[str] = mapped_column(String(255), default="application/octet-stream")
size: Mapped[int] = mapped_column(Integer, default=0)
r2_key: Mapped[str] = mapped_column(String(1024))
status: Mapped[str] = mapped_column(String(32), default="pending", index=True)
image_id: Mapped[str | None] = mapped_column(String(64), nullable=True)
error: Mapped[str | None] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
class ExportJob(Base):
__tablename__ = "exports"
id: Mapped[str] = mapped_column(String(32), primary_key=True, default=_uid)