automatyzacje-comit7

This commit is contained in:
Mateusz Gruszczyński
2026-05-07 13:30:23 +02:00
parent 8334aa97e2
commit 91dcd1c5db
3 changed files with 66 additions and 16 deletions

View File

@@ -926,17 +926,23 @@ def tracker_action(profile: dict, torrent_hash: str, action_name: str, payload:
("d.tracker.insert", (torrent_hash, 0, url)),
("d.tracker.insert", ("", torrent_hash, "", url)),
])
if action_name == "edit":
url = str(payload.get("url") or "").strip()
if action_name in {"delete", "remove"}:
# Note: Deleting trackers is guarded to keep at least one tracker attached to the torrent.
index = int(payload.get("index", -1))
if index < 0:
raise ValueError("Invalid tracker index")
if not url:
raise ValueError("Missing tracker URL")
target = _tracker_target(torrent_hash, index)
total = _tracker_int(_safe_tracker_call(c, "d.tracker_size", torrent_hash, 0), 0) or len(torrent_trackers(profile, torrent_hash))
if total <= 1:
raise ValueError("Cannot delete the last tracker")
if index >= total:
raise ValueError("Invalid tracker index")
return _call_first(c, [
("t.url.set", (target, url)),
("t.url.set", ("", target, url)),
("d.tracker.remove", (torrent_hash, index)),
("d.tracker.remove", (torrent_hash, "", index)),
("d.tracker.erase", (torrent_hash, index)),
("d.tracker.erase", (torrent_hash, "", index)),
("d.tracker.delete", (torrent_hash, index)),
("d.tracker.delete", (torrent_hash, "", index)),
])
raise ValueError(f"Unknown tracker action: {action_name}")