favicons
This commit is contained in:
@@ -13,7 +13,7 @@ import socket
|
||||
import json
|
||||
import psutil
|
||||
import xml.etree.ElementTree as ET
|
||||
from flask import Blueprint, jsonify, request, abort, send_file
|
||||
from flask import Blueprint, jsonify, request, abort, send_file, redirect
|
||||
from ..config import DB_PATH, JOBS_RETENTION_DAYS, SMART_QUEUE_HISTORY_RETENTION_DAYS, WORKERS
|
||||
from ..db import connect, utcnow
|
||||
from ..services.auth import current_user_id as default_user_id, current_user, list_users, save_user, delete_user, login_user, logout_user, enabled as auth_enabled, require_profile_write
|
||||
@@ -494,7 +494,9 @@ def trackers_summary():
|
||||
# Note: Tracker summary uses the local torrent snapshot and refreshes only a small cache batch per request.
|
||||
scan_limit = min(250, max(0, int(request.args.get("scan_limit") or 80)))
|
||||
hashes = [t.get("hash") for t in torrent_cache.snapshot(profile["id"]) if t.get("hash")]
|
||||
summary = tracker_cache.summary(profile, hashes, lambda h: rtorrent.torrent_trackers(profile, h), scan_limit=scan_limit)
|
||||
prefs = preferences.get_preferences()
|
||||
include_favicons = bool(prefs and prefs.get("tracker_favicons_enabled"))
|
||||
summary = tracker_cache.summary(profile, hashes, lambda h: rtorrent.torrent_trackers(profile, h), scan_limit=scan_limit, include_favicons=include_favicons)
|
||||
return ok({"summary": summary})
|
||||
except Exception as exc:
|
||||
return ok({"summary": {"hashes": {}, "trackers": [], "errors": [{"error": str(exc)}], "scanned": 0, "pending": 0}, "error": str(exc)})
|
||||
@@ -504,10 +506,11 @@ def trackers_summary():
|
||||
def tracker_favicon(domain: str):
|
||||
prefs = preferences.get_preferences()
|
||||
enabled = bool(prefs and prefs.get("tracker_favicons_enabled"))
|
||||
path, mime = tracker_cache.favicon_path(domain, enabled=enabled)
|
||||
if not path:
|
||||
abort(404)
|
||||
return send_file(path, mimetype=mime or "image/x-icon", max_age=7 * 24 * 60 * 60)
|
||||
static_url = tracker_cache.favicon_public_url(domain, enabled=enabled, create=True)
|
||||
if static_url:
|
||||
# Note: The API only discovers/cache-warms the icon; the browser receives the file from /static/data/tracker_favicons/.
|
||||
return redirect(static_url, code=302)
|
||||
abort(404)
|
||||
|
||||
@bp.get("/torrent-stats")
|
||||
def torrent_stats_get():
|
||||
|
||||
Reference in New Issue
Block a user