auto-save 2026-05-13 23:29 (~5)

This commit is contained in:
2026-05-13 23:29:35 +08:00
parent 38091d318b
commit 03770b1ed8
5 changed files with 108 additions and 7 deletions

View File

@@ -850,6 +850,53 @@ def health() -> dict:
}
class JobSummary(BaseModel):
id: str
url: str
status: JobStatus
progress: int = 0
message: str = ""
duration: float = 0.0
width: int = 0
height: int = 0
video_url: str = ""
frame_count: int = 0
video_count: int = 0
thumbnail: str = ""
error: str = ""
mtime: float = 0.0
@app.get("/jobs", response_model=list[JobSummary])
def list_jobs(limit: int | None = None) -> list[JobSummary]:
"""所有 job 的精简列表,按磁盘 state.json mtime 倒序(最新优先)。前端无 ?job= 时用它回填历史。"""
items: list[JobSummary] = []
for job_id, job in JOBS.items():
state_path = JOBS_DIR / job_id / "state.json"
mtime = state_path.stat().st_mtime if state_path.exists() else 0.0
thumb = f"/jobs/{job_id}/frames/{job.frames[0].index}.jpg" if job.frames else ""
items.append(JobSummary(
id=job.id,
url=job.url,
status=job.status,
progress=job.progress,
message=job.message,
duration=job.duration,
width=job.width,
height=job.height,
video_url=job.video_url,
frame_count=len(job.frames),
video_count=len(job.generated_videos),
thumbnail=thumb,
error=job.error,
mtime=mtime,
))
items.sort(key=lambda s: s.mtime, reverse=True)
if limit is not None and limit > 0:
items = items[:limit]
return items
@app.post("/jobs", response_model=Job)
async def create_job(req: CreateJobReq, bg: BackgroundTasks) -> Job:
if not req.url.strip():