diff --git a/backend/app/api/admin.py b/backend/app/api/admin.py index a5e0f6c..cefc181 100644 --- a/backend/app/api/admin.py +++ b/backend/app/api/admin.py @@ -179,3 +179,22 @@ async def tag_usage_count(tag_id: int): ) ) return jsonify({"count": count}) + + +@admin_bp.route("/tags/prune-unused", methods=["POST"]) +async def tags_prune_unused(): + """Tier-A: dry-run preview list IS the prompt. UI calls with + dry_run=true first, shows the list, operator clicks button to + re-call with dry_run=false.""" + from ..services.cleanup_service import prune_unused_tags + + body = await request.get_json(silent=True) or {} + dry_run = bool(body.get("dry_run", False)) + + async with get_session() as session: + result = await session.run_sync( + lambda sync_sess: prune_unused_tags( + sync_sess, dry_run=dry_run, + ) + ) + return jsonify(result)