new functions

This commit is contained in:
Mateusz Gruszczyński
2026-05-05 08:00:32 +02:00
parent 4b236c21f8
commit fa0d2f13fe
8 changed files with 304 additions and 6 deletions

View File

@@ -16,7 +16,7 @@ import xml.etree.ElementTree as ET
from flask import Blueprint, jsonify, request
from ..config import DB_PATH, JOBS_RETENTION_DAYS, SMART_QUEUE_HISTORY_RETENTION_DAYS, WORKERS
from ..db import default_user_id, connect, utcnow
from ..services import preferences, rtorrent
from ..services import preferences, rtorrent, torrent_stats
from ..services.torrent_cache import torrent_cache
from ..services.torrent_summary import cached_summary
from ..services.workers import enqueue, list_jobs, cancel_job, retry_job, clear_jobs, emergency_clear_jobs
@@ -410,6 +410,17 @@ def torrents():
})
@bp.get("/torrent-stats")
def torrent_stats_get():
profile = preferences.active_profile()
force = str(request.args.get("force") or "").lower() in {"1", "true", "yes"}
try:
# Note: Heavy file metadata is served from a 15-minute DB cache unless the user explicitly refreshes it.
return ok({"stats": torrent_stats.get(profile, force=force)})
except Exception as exc:
return jsonify({"ok": False, "error": str(exc)}), 500
@bp.get("/torrents/<torrent_hash>/files")
def torrent_files(torrent_hash: str):
profile = preferences.active_profile()