Spaces:
Sleeping
Sleeping
Add upload probe endpoint
Browse files
app.py
CHANGED
|
@@ -406,6 +406,23 @@ async def create_job(
|
|
| 406 |
return JSONResponse(_snapshot(job))
|
| 407 |
|
| 408 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 409 |
@app.get("/api/jobs/{job_id}")
|
| 410 |
def get_job(job_id: str) -> JSONResponse:
|
| 411 |
with JOBS_LOCK:
|
|
|
|
| 406 |
return JSONResponse(_snapshot(job))
|
| 407 |
|
| 408 |
|
| 409 |
+
@app.post("/api/probe-upload")
|
| 410 |
+
async def probe_upload(file: Annotated[UploadFile | None, File()] = None) -> JSONResponse:
|
| 411 |
+
if file is None:
|
| 412 |
+
raise HTTPException(status_code=400, detail="Choose a video file first.")
|
| 413 |
+
total = 0
|
| 414 |
+
while chunk := await file.read(1024 * 1024):
|
| 415 |
+
total += len(chunk)
|
| 416 |
+
return JSONResponse(
|
| 417 |
+
{
|
| 418 |
+
"ok": True,
|
| 419 |
+
"filename": file.filename or "upload.mp4",
|
| 420 |
+
"content_type": file.content_type or "",
|
| 421 |
+
"bytes": total,
|
| 422 |
+
}
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
|
| 426 |
@app.get("/api/jobs/{job_id}")
|
| 427 |
def get_job(job_id: str) -> JSONResponse:
|
| 428 |
with JOBS_LOCK:
|