Dashboard: select-all + bulk keep/reject/reset (htmx + bulk endpoint)

This commit is contained in:
2026-08-08 09:53:58 +10:00
parent e7c0bfc584
commit 91972fe0ac
3 changed files with 133 additions and 3 deletions

View File

@@ -177,6 +177,55 @@ def reset_status(sha: str, request: Request):
return _set_status(sha, "scanned", None, request)
@app.post("/review/bulk")
async def bulk_action(request: Request):
"""Bulk keep/reject/reset for a list of sha256 values.
Body: JSON {"action": "approve"|"reject"|"reset", "shas": ["..."]}
Moves files accordingly; returns counts.
"""
import json
body = json.loads(await request.body())
action = body.get("action")
shas = body.get("shas", [])
if action not in ("approve", "reject", "reset"):
raise HTTPException(400, "action must be approve/reject/reset")
move_map = {"approve": "01_keep", "reject": "03_delete", "reset": None}
status_map = {"approve": "approved", "reject": "rejected", "reset": "scanned"}
move_to = move_map[action]
status = status_map[action]
conn = _conn()
moved = 0
missing = 0
for sha in shas:
row = conn.execute("SELECT path FROM image_hashes WHERE sha256=?", (sha,)).fetchone()
if not row:
missing += 1
continue
src = Path(row["path"])
if move_to and src.exists():
dest_dir = STAGING / move_to
dest_dir.mkdir(parents=True, exist_ok=True)
dest = dest_dir / src.name
try:
shutil.move(str(src), str(dest))
conn.execute(
"UPDATE image_hashes SET path=?, status=? WHERE sha256=?",
(str(dest), status, sha))
moved += 1
continue
except Exception:
pass
conn.execute("UPDATE image_hashes SET status=? WHERE sha256=?", (status, sha))
moved += 1
conn.commit()
conn.close()
return {"action": action, "moved": moved, "missing": missing, "total": len(shas)}
@app.get("/file/{sha}")
def full_file(sha: str):
conn = _conn()