config for logs and filters
This commit is contained in:
@@ -125,7 +125,7 @@ def record_cache_diff(profile_id: int, added: list[dict], removed: list[str], up
|
||||
record(profile_id, "torrent_completed", f"Torrent completed: {old.get('name') or h}", source="poller", torrent_hash=h, torrent_name=old.get("name"), details={"ratio": patch.get("ratio", old.get("ratio")), "size": old.get("size"), "path": old.get("path")})
|
||||
|
||||
|
||||
def list_logs(profile_id: int, *, limit: int = 200, offset: int = 0, event_type: str = "", q: str = "") -> dict:
|
||||
def list_logs(profile_id: int, *, limit: int = 200, offset: int = 0, event_type: str = "", q: str = "", hide_jobs: bool = False) -> dict:
|
||||
limit = max(1, min(int(limit or 200), 1000))
|
||||
offset = max(0, int(offset or 0))
|
||||
where = ["(profile_id=? OR profile_id IS NULL)"]
|
||||
@@ -133,6 +133,9 @@ def list_logs(profile_id: int, *, limit: int = 200, offset: int = 0, event_type:
|
||||
if event_type:
|
||||
where.append("event_type=?")
|
||||
params.append(event_type)
|
||||
if hide_jobs:
|
||||
# Note: Job-originated rows include torrent_added/torrent_removed events, so source is the reliable filter.
|
||||
where.append("COALESCE(source, '') <> 'job'")
|
||||
if q:
|
||||
where.append("(message LIKE ? OR torrent_name LIKE ? OR torrent_hash LIKE ? OR action LIKE ?)")
|
||||
like = f"%{q}%"
|
||||
@@ -155,6 +158,17 @@ def stats(profile_id: int) -> dict:
|
||||
return {"total": int(total or 0), "by_type": by_type, "by_day": by_day, "by_month": by_month, "top_actions": top_actions, "settings": get_settings(profile_id)}
|
||||
|
||||
|
||||
|
||||
def retention_label(settings: dict) -> str:
|
||||
mode = settings.get("retention_mode") or "days"
|
||||
if mode == "manual":
|
||||
return "manual cleanup only"
|
||||
if mode == "lines":
|
||||
return f"retention {settings.get('retention_lines') or DEFAULT_SETTINGS['retention_lines']} lines"
|
||||
if mode == "both":
|
||||
return f"retention {settings.get('retention_days') or DEFAULT_SETTINGS['retention_days']} days and {settings.get('retention_lines') or DEFAULT_SETTINGS['retention_lines']} lines"
|
||||
return f"retention {settings.get('retention_days') or DEFAULT_SETTINGS['retention_days']} days"
|
||||
|
||||
def clear(profile_id: int, *, event_type: str = "") -> int:
|
||||
where = ["(profile_id=? OR profile_id IS NULL)"]
|
||||
params: list[Any] = [int(profile_id or 0)]
|
||||
|
||||
Reference in New Issue
Block a user