Tester un clip .mp4 — il sera traité comme un vrai passage (LPR + couleur + frames)
+ +diff --git a/app/main.py b/app/main.py index 324d1de..0e2db1c 100644 --- a/app/main.py +++ b/app/main.py @@ -2,9 +2,11 @@ import os import glob import logging import threading +import tempfile +import asyncio from contextlib import asynccontextmanager -from fastapi import FastAPI, Request, Query, HTTPException -from fastapi.responses import HTMLResponse +from fastapi import FastAPI, Request, Query, HTTPException, UploadFile, File +from fastapi.responses import HTMLResponse, RedirectResponse from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates from datetime import datetime @@ -134,6 +136,25 @@ async def api_events( return {"events": events, "total": total} +@app.post("/upload") +async def upload_clip(file: UploadFile = File(...)): + if not file.filename.lower().endswith(".mp4"): + raise HTTPException(status_code=400, detail="Seuls les fichiers .mp4 sont acceptés") + + with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp: + content = await file.read() + tmp.write(content) + tmp_path = tmp.name + + try: + loop = asyncio.get_event_loop() + event_id = await loop.run_in_executor(None, watcher.process_uploaded_clip, tmp_path) + finally: + os.unlink(tmp_path) + + return RedirectResponse(f"/event/{event_id}", status_code=303) + + @app.get("/health") async def health(): return {"status": "ok"} diff --git a/app/templates/index.html b/app/templates/index.html index 293f94f..a270bf0 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -16,6 +16,11 @@ .btn:hover { background: #1d4ed8; } .btn-ghost { background: #1e293b; border: 1px solid #475569; color: #94a3b8; } .btn-ghost:hover { background: #334155; color: #e2e8f0; } + .btn-upload { background: #1e293b; border: 1px solid #475569; color: #94a3b8; border-radius: 6px; padding: 6px 14px; font-size: 0.85rem; cursor: pointer; } + .btn-upload:hover { background: #334155; color: #e2e8f0; } + #upload-panel { display:none; background:#1e293b; border:1px solid #334155; border-radius:10px; padding:16px; margin-bottom:16px; } + #upload-panel.open { display:block; } + #upload-progress { display:none; }
@@ -26,11 +31,30 @@ CamWatch - {{ total }} passage{{ 's' if total != 1 else '' }} +Tester un clip .mp4 — il sera traité comme un vrai passage (LPR + couleur + frames)
+ +