diff --git a/pytorrent/services/automation_rules.py b/pytorrent/services/automation_rules.py index 7e9e8fc..ce73eaf 100644 --- a/pytorrent/services/automation_rules.py +++ b/pytorrent/services/automation_rules.py @@ -113,8 +113,8 @@ def _conditions_match(conn, rule: dict[str, Any], profile_id: int, t: dict[str, for cond in rule.get('conditions') or []: raw_ok = _condition_true(t, cond) negated = bool(cond.get('negate')) + # Note: Negation is applied in the backend, so UI and API only store the condition flag. ok = (not raw_ok) if negated else raw_ok - # Note: Conditions can now be negated in automation rules. Timed no-seeds keeps its old delayed behavior only for the positive condition, so old rules do not change. if cond.get('type') == 'no_seeds' and int(cond.get('minutes') or 0) > 0 and not negated: row = conn.execute('SELECT condition_since_at FROM automation_rule_state WHERE rule_id=? AND profile_id=? AND torrent_hash=?', (rule['id'], profile_id, h)).fetchone() if ok: @@ -128,33 +128,59 @@ def _conditions_match(conn, rule: dict[str, Any], profile_id: int, t: dict[str, return immediate_ok and delayed_ok -def _cooldown_ok(conn, rule: dict[str, Any], profile_id: int, torrent_hash: str) -> bool: +def _cooldown_ok(conn, rule: dict[str, Any], profile_id: int, torrent_hash: str = '__rule__') -> bool: cooldown = int(rule.get('cooldown_minutes') or 0) + if cooldown <= 0: return True row = conn.execute('SELECT last_applied_at FROM automation_rule_state WHERE rule_id=? AND profile_id=? AND torrent_hash=?', (rule['id'], profile_id, torrent_hash)).fetchone() if not row or not row.get('last_applied_at'): return True return _now_ts() - _ts(row['last_applied_at']) >= cooldown * 60 -def _apply_effects(c: Any, profile: dict[str, Any], torrent: dict[str, Any], effects: list[dict[str, Any]]) -> list[dict[str, Any]]: - h = str(torrent.get('hash') or ''); labels = _label_names(torrent.get('label')); applied = [] +def _mark_rule_cooldown(conn, rule: dict[str, Any], profile_id: int, now: str) -> None: + # Note: Cooldown is rule-level, so one batch execution blocks the whole automation until the cooldown expires. + conn.execute('INSERT INTO automation_rule_state(rule_id,profile_id,torrent_hash,last_applied_at,updated_at) VALUES(?,?,?,?,?) ON CONFLICT(rule_id,profile_id,torrent_hash) DO UPDATE SET last_applied_at=excluded.last_applied_at, updated_at=excluded.updated_at', (rule['id'], profile_id, '__rule__', now, now)) + + +def _apply_effects_bulk(c: Any, profile: dict[str, Any], torrents: list[dict[str, Any]], effects: list[dict[str, Any]]) -> list[dict[str, Any]]: + hashes = [str(t.get('hash') or '') for t in torrents if str(t.get('hash') or '')] + labels_by_hash = {str(t.get('hash') or ''): _label_names(t.get('label')) for t in torrents} + applied: list[dict[str, Any]] = [] + if not hashes: return applied for eff in effects: typ = str(eff.get('type') or '') if typ == 'move': - # Note: Automation move-to-path now uses the same move implementation as the main app action. path = str(eff.get('path') or '').strip() or rtorrent.default_download_path(profile) - move_payload = {'path': path, 'move_data': bool(eff.get('move_data')), 'recheck': bool(eff.get('recheck', eff.get('move_data'))), 'keep_seeding': bool(eff.get('keep_seeding'))} - result = rtorrent.move_torrents(profile, [h], move_payload) if path else None - if path: applied.append({'type': 'move', 'path': path, 'move_data': bool(eff.get('move_data')), 'recheck': bool(move_payload['recheck']), 'keep_seeding': bool(eff.get('keep_seeding')), 'result': result}) + payload = { + 'path': path, + 'move_data': bool(eff.get('move_data')), + 'recheck': bool(eff.get('recheck', eff.get('move_data'))), + 'keep_seeding': bool(eff.get('keep_seeding')), + } + result = rtorrent.action(profile, hashes, 'move', payload) + applied.append({'type': 'move', 'path': path, 'count': len(hashes), 'move_data': payload['move_data'], 'recheck': payload['recheck'], 'keep_seeding': payload['keep_seeding'], 'result': result}) elif typ == 'add_label': label = str(eff.get('label') or '').strip() - if label and label not in labels: labels.append(label); c.call('d.custom1.set', h, _label_value(labels)) - if label: applied.append({'type': 'add_label', 'label': label}) + if label: + for h in hashes: + labels = labels_by_hash.setdefault(h, []) + if label not in labels: + labels.append(label); c.call('d.custom1.set', h, _label_value(labels)) + applied.append({'type': 'add_label', 'label': label, 'count': len(hashes)}) elif typ == 'remove_label': - label = str(eff.get('label') or '').strip(); labels = [x for x in labels if x != label]; c.call('d.custom1.set', h, _label_value(labels)); applied.append({'type': 'remove_label', 'label': label}) + label = str(eff.get('label') or '').strip() + if label: + for h in hashes: + labels = [x for x in labels_by_hash.get(h, []) if x != label] + labels_by_hash[h] = labels; c.call('d.custom1.set', h, _label_value(labels)) + applied.append({'type': 'remove_label', 'label': label, 'count': len(hashes)}) elif typ == 'set_labels': - value = _label_value(_label_names(eff.get('labels'))); c.call('d.custom1.set', h, value); labels = _label_names(value); applied.append({'type': 'set_labels', 'labels': value}) + value = _label_value(_label_names(eff.get('labels'))) + for h in hashes: + labels_by_hash[h] = _label_names(value); c.call('d.custom1.set', h, value) + applied.append({'type': 'set_labels', 'labels': value, 'count': len(hashes)}) elif typ in {'pause', 'stop', 'start', 'resume', 'recheck'}: - method = {'pause':'d.pause','stop':'d.stop','start':'d.start','resume':'d.resume','recheck':'d.check_hash'}[typ]; c.call(method, h); applied.append({'type': typ}) + result = rtorrent.action(profile, hashes, typ, {}) + applied.append({'type': typ, 'count': len(hashes), 'result': result}) return applied @@ -163,17 +189,30 @@ def check(profile: dict | None = None, user_id: int | None = None, force: bool = if not profile: return {'ok': False, 'error': 'No active rTorrent profile'} user_id = user_id or default_user_id(); profile_id = int(profile['id']) rules = [r for r in list_rules(profile_id, user_id) if force or int(r.get('enabled') or 0)] - if not rules: return {'ok': True, 'checked': 0, 'applied': [], 'rules': 0} - torrents = rtorrent.list_torrents(profile); c = rtorrent.client_for(profile); applied = []; now = utcnow() + if not rules: return {'ok': True, 'checked': 0, 'applied': [], 'batches': [], 'rules': 0} + torrents = rtorrent.list_torrents(profile); c = rtorrent.client_for(profile); applied = []; batches = []; now = utcnow() with connect() as conn: for rule in rules: - for t in torrents: + # Note: Automations now execute as one batch per rule, not as one independent action per torrent. + if not force and not _cooldown_ok(conn, rule, profile_id): + continue + matched = [t for t in torrents if _conditions_match(conn, rule, profile_id, t)] + if not matched: + continue + hashes = [str(t.get('hash') or '') for t in matched if str(t.get('hash') or '')] + if not hashes: + continue + try: + actions = _apply_effects_bulk(c, profile, matched, rule.get('effects') or []) + except Exception as exc: + actions = [{'error': str(exc), 'count': len(hashes)}] + for t in matched: h = str(t.get('hash') or '') - if not _conditions_match(conn, rule, profile_id, t): continue - if not force and not _cooldown_ok(conn, rule, profile_id, h): continue - try: actions = _apply_effects(c, profile, t, rule.get('effects') or []) - except Exception as exc: actions = [{'error': str(exc)}] conn.execute('INSERT INTO automation_rule_state(rule_id,profile_id,torrent_hash,last_matched_at,last_applied_at,updated_at) VALUES(?,?,?,?,?,?) ON CONFLICT(rule_id,profile_id,torrent_hash) DO UPDATE SET last_matched_at=excluded.last_matched_at, last_applied_at=excluded.last_applied_at, updated_at=excluded.updated_at', (rule['id'], profile_id, h, now, now, now)) - conn.execute('INSERT INTO automation_history(user_id,profile_id,rule_id,torrent_hash,torrent_name,rule_name,actions_json,created_at) VALUES(?,?,?,?,?,?,?,?)', (user_id, profile_id, rule['id'], h, str(t.get('name') or ''), str(rule.get('name') or ''), json.dumps(actions), now)) - applied.append({'rule_id': rule['id'], 'rule_name': rule.get('name'), 'hash': h, 'name': t.get('name'), 'actions': actions}) - return {'ok': True, 'checked': len(torrents), 'rules': len(rules), 'applied': applied} + applied.append({'rule_id': rule['id'], 'rule_name': rule.get('name'), 'hash': h, 'name': t.get('name'), 'actions': [{'type': a.get('type', 'error'), 'count': a.get('count', len(hashes))} for a in actions]}) + _mark_rule_cooldown(conn, rule, profile_id, now) + torrent_name = str(matched[0].get('name') or '') if len(matched) == 1 else f'{len(matched)} torrents' + torrent_hash = hashes[0] if len(hashes) == 1 else f'batch:{rule["id"]}:{now}' + conn.execute('INSERT INTO automation_history(user_id,profile_id,rule_id,torrent_hash,torrent_name,rule_name,actions_json,created_at) VALUES(?,?,?,?,?,?,?,?)', (user_id, profile_id, rule['id'], torrent_hash, torrent_name, str(rule.get('name') or ''), json.dumps(actions), now)) + batches.append({'rule_id': rule['id'], 'rule_name': rule.get('name'), 'count': len(hashes), 'actions': actions}) + return {'ok': True, 'checked': len(torrents), 'rules': len(rules), 'applied': applied, 'batches': batches} diff --git a/pytorrent/services/rtorrent.py b/pytorrent/services/rtorrent.py index 68632f8..b853464 100644 --- a/pytorrent/services/rtorrent.py +++ b/pytorrent/services/rtorrent.py @@ -1274,73 +1274,6 @@ def start_or_resume_hash(c: ScgiRtorrentClient, torrent_hash: str) -> dict: result['ok'] = result.get('ok', True) return result - -def move_torrents(profile: dict, torrent_hashes: list[str], payload: dict | None = None) -> dict: - # Note: Shared move implementation keeps API move and automation move-to-path identical. - payload = payload or {} - c = client_for(profile) - path = _remote_clean_path(payload.get("path") or "") - move_data = bool(payload.get("move_data")) - recheck = bool(payload.get("recheck", move_data)) - keep_seeding = bool(payload.get("keep_seeding")) - # Note: keep_seeding lets automation move completed data to another path and force the torrent back into seeding. - if not path: - raise ValueError("Missing path") - results = [] - if move_data: - _rt_execute_allow_timeout(c, "execute.throw", "mkdir", "-p", path) - for h in torrent_hashes: - item = {"hash": h, "path": path, "move_data": move_data, "keep_seeding": keep_seeding} - try: - was_state = int(c.call("d.state", h) or 0) - except Exception: - was_state = 0 - try: - was_active = int(c.call("d.is_active", h) or 0) - except Exception: - was_active = was_state - if move_data: - src = _remote_clean_path(_torrent_data_path(c, h)) - if not src: - raise ValueError(f"Cannot determine source path for {h}") - dst = _remote_join(path, posixpath.basename(src.rstrip("/"))) - if src != dst: - try: - c.call("d.stop", h) - except Exception: - pass - try: - c.call("d.close", h) - except Exception: - pass - _run_remote_move(c, src, dst) - item["moved_from"] = src - item["moved_to"] = dst - else: - item["skipped"] = "source and destination are the same" - c.call("d.directory.set", h, path) - if recheck: - try: - c.call("d.check_hash", h) - except Exception as exc: - item["recheck_error"] = str(exc) - if keep_seeding or was_state or was_active: - try: - c.call("d.start", h) - item["started_after_move"] = True - except Exception as exc: - item["start_error"] = str(exc) - else: - c.call("d.directory.set", h, path) - if keep_seeding: - try: - c.call("d.start", h) - item["started_after_path_change"] = True - except Exception as exc: - item["start_error"] = str(exc) - results.append(item) - return {"ok": True, "count": len(torrent_hashes), "move_data": move_data, "keep_seeding": keep_seeding, "results": results} - def action(profile: dict, torrent_hashes: list[str], name: str, payload: dict | None = None) -> dict: payload = payload or {} c = client_for(profile) @@ -1361,8 +1294,61 @@ def action(profile: dict, torrent_hashes: list[str], name: str, payload: dict | c.call("d.custom.set", h, "py_ratio_group", group) return {"ok": True, "count": len(torrent_hashes), "ratio_group": group} if name == "move": - # Note: Main move delegates to the shared helper used by automations. - return move_torrents(profile, torrent_hashes, payload) + path = _remote_clean_path(payload.get("path") or "") + move_data = bool(payload.get("move_data")) + recheck = bool(payload.get("recheck", move_data)) + keep_seeding = bool(payload.get("keep_seeding")) + # Note: Automations can force seeding after a physical move even if the torrent was not active before. + if not path: + raise ValueError("Missing path") + results = [] + if move_data: + _rt_execute_allow_timeout(c, "execute.throw", "mkdir", "-p", path) + for h in torrent_hashes: + item = {"hash": h, "path": path, "move_data": move_data, "keep_seeding": keep_seeding} + try: + was_state = int(c.call("d.state", h) or 0) + except Exception: + was_state = 0 + try: + was_active = int(c.call("d.is_active", h) or 0) + except Exception: + was_active = was_state + if move_data: + src = _remote_clean_path(_torrent_data_path(c, h)) + if not src: + raise ValueError(f"Cannot determine source path for {h}") + dst = _remote_join(path, posixpath.basename(src.rstrip("/"))) + if src != dst: + try: + c.call("d.stop", h) + except Exception: + pass + try: + c.call("d.close", h) + except Exception: + pass + _run_remote_move(c, src, dst) + item["moved_from"] = src + item["moved_to"] = dst + else: + item["skipped"] = "source and destination are the same" + c.call("d.directory.set", h, path) + if recheck: + try: + c.call("d.check_hash", h) + except Exception as exc: + item["recheck_error"] = str(exc) + if keep_seeding or was_state or was_active: + try: + c.call("d.start", h) + item["started_after_move"] = True + except Exception as exc: + item["start_after_move_error"] = str(exc) + else: + c.call("d.directory.set", h, path) + results.append(item) + return {"ok": True, "count": len(torrent_hashes), "move_data": move_data, "keep_seeding": keep_seeding, "results": results} if name == "pause": # Note: The app pause action is now a pure d.pause so later resume works without stop/start. results = [pause_hash(c, h) for h in torrent_hashes] diff --git a/pytorrent/services/smart_queue.py b/pytorrent/services/smart_queue.py index 1779ee3..a8d64e8 100644 --- a/pytorrent/services/smart_queue.py +++ b/pytorrent/services/smart_queue.py @@ -132,39 +132,6 @@ def _excluded_hashes(profile_id: int, user_id: int) -> set[str]: return {r['torrent_hash'] for r in list_exclusions(profile_id, user_id)} -def _label_names(value: str | None) -> list[str]: - names: list[str] = [] - for part in str(value or '').replace(';', ',').replace('|', ',').split(','): - label = part.strip() - if label and label not in names: - names.append(label) - return names - - -def _label_value(labels: list[str]) -> str: - out: list[str] = [] - for label in labels: - label = str(label or '').strip() - if label and label not in out: - out.append(label) - return ', '.join(out) - - -def _has_smart_queue_label(value: str | None) -> bool: - return SMART_QUEUE_LABEL in _label_names(value) - - -def _without_smart_queue_label(value: str | None) -> str: - return _label_value([label for label in _label_names(value) if label != SMART_QUEUE_LABEL]) - - -def _with_smart_queue_label(value: str | None) -> str: - labels = _label_names(value) - if SMART_QUEUE_LABEL not in labels: - labels.append(SMART_QUEUE_LABEL) - return _label_value(labels) - - def _remember_auto_label(profile_id: int, torrent_hash: str, previous_label: str) -> None: now = utcnow() with connect() as conn: @@ -198,18 +165,21 @@ def _restore_auto_label(client: Any, profile_id: int, torrent_hash: str, current (profile_id, torrent_hash), ).fetchone() live_label = _read_label(client, torrent_hash, current_label or '') - if not row and not _has_smart_queue_label(live_label): - return False - restored = _without_smart_queue_label(live_label) - previous = _without_smart_queue_label((row or {}).get('previous_label') or '') - if not restored and previous: - restored = previous + if not row: + if live_label != SMART_QUEUE_LABEL: + return False + try: + # Note: Clear the Smart Queue label even when the torrent was marked earlier but no previous-label entry remains. + client.call('d.custom1.set', torrent_hash, '') + return True + except Exception: + return False + previous = row.get('previous_label') or '' try: - # Note: Smart Queue now removes only its technical label, preserving labels added manually while the torrent was waiting in the queue. - if _has_smart_queue_label(live_label) or current_label is None: - client.call('d.custom1.set', torrent_hash, restored) - if row: - conn.execute('DELETE FROM smart_queue_auto_labels WHERE profile_id=? AND torrent_hash=?', (profile_id, torrent_hash)) + # Note: On resume, Smart Queue restores the previous label only while it still sees its own technical label. + if live_label == SMART_QUEUE_LABEL or current_label is None: + client.call('d.custom1.set', torrent_hash, previous) + conn.execute('DELETE FROM smart_queue_auto_labels WHERE profile_id=? AND torrent_hash=?', (profile_id, torrent_hash)) return True except Exception: return False @@ -312,12 +282,10 @@ def _read_live_start_state(client: Any, torrent_hash: str) -> dict[str, Any]: result['started'] = bool(int(result.get('active') or 0)) return result -def _set_smart_queue_label(client: Any, torrent_hash: str, current_label: str | None = None, attempts: int = 3) -> bool: - # Note: The queue label is appended as a technical label instead of replacing the user's labels. - target = _with_smart_queue_label(current_label if current_label is not None else _read_label(client, torrent_hash, '')) +def _set_smart_queue_label(client: Any, torrent_hash: str, attempts: int = 3) -> bool: for attempt in range(max(1, attempts)): try: - client.call('d.custom1.set', torrent_hash, target) + client.call('d.custom1.set', torrent_hash, SMART_QUEUE_LABEL) return True except Exception: if attempt < attempts - 1: @@ -330,15 +298,15 @@ def _mark_auto_paused(client: Any, profile_id: int, torrent: dict[str, Any]) -> if not torrent_hash: return False previous = str(torrent.get('label') or '') - if not _has_smart_queue_label(previous): - _remember_auto_label(profile_id, torrent_hash, _without_smart_queue_label(previous)) - return _set_smart_queue_label(client, torrent_hash, previous) + if previous != SMART_QUEUE_LABEL: + _remember_auto_label(profile_id, torrent_hash, previous) + return _set_smart_queue_label(client, torrent_hash) def _is_smart_queue_hold(torrent: dict[str, Any] | None, manage_stopped: bool = True) -> bool: if not torrent or int(torrent.get('complete') or 0): return False - if _has_smart_queue_label(torrent.get('label')): + if str(torrent.get('label') or '') == SMART_QUEUE_LABEL: return True # Note: Paused in rTorrent usually has state=1 and active=0, so state=0 must not be required. # This lets Smart Queue treat paused torrents as pending and fill the queue target later. @@ -351,11 +319,11 @@ def _is_smart_queue_hold(torrent: dict[str, Any] | None, manage_stopped: bool = def _clear_untracked_smart_queue_label(client: Any, torrent_hash: str, current_label: str) -> bool: - if not _has_smart_queue_label(current_label): + if current_label != SMART_QUEUE_LABEL: return False try: - # Note: Orphan cleanup removes only the Smart Queue technical label and keeps manual labels intact. - client.call('d.custom1.set', torrent_hash, _without_smart_queue_label(current_label)) + # Note: Clear an orphaned Smart Queue label when no previous-label entry exists in the database. + client.call('d.custom1.set', torrent_hash, '') return True except Exception: return False @@ -378,7 +346,7 @@ def _cleanup_auto_labels(client: Any, profile_id: int, torrents: list[dict[str, if _restore_auto_label(client, profile_id, h, None if t is None else current_label): restored.append(h) continue - if not _has_smart_queue_label(current_label): + if current_label != SMART_QUEUE_LABEL: _set_smart_queue_label(client, h) for h, t in by_hash.items(): @@ -395,7 +363,7 @@ def _is_running_download_slot(t: dict[str, Any]) -> bool: # Paused can have state=1/open=1, so a slot is counted only after d.is_active=1. if int(t.get('complete') or 0): return False - if _has_smart_queue_label(t.get('label')): + if str(t.get('label') or '') == SMART_QUEUE_LABEL: return False status = str(t.get('status') or '').lower() if status == 'checking' or status == 'paused' or bool(t.get('paused')): @@ -407,7 +375,7 @@ def _is_waiting_download_candidate(t: dict[str, Any], manage_stopped: bool) -> b """Return True for paused/held torrents Smart Queue may resume later.""" if int(t.get('complete') or 0): return False - if _has_smart_queue_label(t.get('label')): + if str(t.get('label') or '') == SMART_QUEUE_LABEL: return True # Note: Paused items are the primary source for filling the queue, regardless of manage_stopped. if bool(t.get('paused')) or str(t.get('status') or '').lower() == 'paused': @@ -438,7 +406,7 @@ def check(profile: dict | None = None, user_id: int | None = None, force: bool = excluded = _excluded_hashes(profile_id, user_id) manage_stopped = bool(settings.get('manage_stopped')) def is_managed_hold(t: dict[str, Any]) -> bool: - return _has_smart_queue_label(t.get('label')) + return str(t.get('label') or '') == SMART_QUEUE_LABEL # Note: Count Smart Queue slots by d.is_active because Paused can have state=1/open=1 and must not occupy the limit. downloading = [ @@ -570,7 +538,7 @@ def check(profile: dict | None = None, user_id: int | None = None, force: bool = keep_labels = ( set(paused) | {str(t.get('hash') or '') for t in to_label_waiting} - | {str(t.get('hash') or '') for t in stopped if _has_smart_queue_label(t.get('label')) and str(t.get('hash') or '') not in set(resumed)} + | {str(t.get('hash') or '') for t in stopped if str(t.get('label') or '') == SMART_QUEUE_LABEL and str(t.get('hash') or '') not in set(resumed)} ) restored = _cleanup_auto_labels(c, profile_id, torrents, keep_labels, manage_stopped) details = {'excluded': len(excluded), 'enabled': bool(settings.get('enabled')), 'auto_label': SMART_QUEUE_LABEL, 'labels_restored': restored, 'labels_failed': label_failed, 'start_failed': start_failed, 'start_no_effect': start_no_effect, 'start_results': start_results, 'resume_requested': resume_requested, 'active_verified': active_verified, 'waiting_labeled': len(to_label_waiting), 'manage_stopped': manage_stopped, 'max_active_downloads': max_active, 'active_before': len(downloading), 'active_after_expected': active_after_pause + len(resumed), 'paused_planned': len(to_pause), 'resumed_planned': len(to_resume), 'rtorrent_cap': rtorrent_cap} diff --git a/pytorrent/static/app.js b/pytorrent/static/app.js index 717a176..e0ff916 100644 --- a/pytorrent/static/app.js +++ b/pytorrent/static/app.js @@ -525,25 +525,134 @@ function syncMobileMode(){ const auto=window.matchMedia&&window.matchMedia("(max-width: 900px)").matches; document.body.classList.toggle("mobile-mode", auto || document.body.classList.contains("mobile-mode-manual")); scheduleRender(true); } - // Note: Builder queues allow many conditions and many ordered actions in one automation without changing old single-step saves. - let automationConditionQueue=[]; - let automationEffectQueue=[]; - let automationRulesCache=new Map(); - let editingAutomationId=null; - function automationCondition(){ const type=$('autoConditionType')?.value||'completed'; const cond={type}; if($('autoCondNegate')?.checked) cond.negate=true; if(type==='no_seeds'){cond.seeds=Number($('autoCondSeeds')?.value||0);cond.minutes=Number($('autoCondMinutes')?.value||0);} if(type==='ratio_gte')cond.ratio=Number($('autoCondRatio')?.value||1); if(type==='label_missing'||type==='label_has')cond.label=$('autoCondLabel')?.value||''; if(type==='status')cond.status=$('autoCondStatus')?.value||'Seeding'; if(type==='path_contains')cond.text=$('autoCondText')?.value||''; return cond; } - function automationEffect(){ const type=$('autoEffectType')?.value||'add_label'; const eff={type}; if(type==='move'){eff.path=$('autoEffectPath')?.value||''; eff.move_data=!!($('autoMoveDataPhysical')?.checked); eff.recheck=!!($('autoMoveRecheck')?.checked); eff.keep_seeding=!!($('autoMoveKeepSeeding')?.checked);} if(type==='add_label'||type==='remove_label')eff.label=$('autoEffectLabel')?.value||''; if(type==='set_labels')eff.labels=$('autoEffectLabels')?.value||''; return eff; } - function updateAutomationForm(){ const ct=$('autoConditionType')?.value||''; document.querySelectorAll('[data-auto-cond]').forEach(el=>el.classList.toggle('d-none', !el.dataset.autoCond.split(',').includes(ct))); const et=$('autoEffectType')?.value||''; document.querySelectorAll('[data-auto-effect]').forEach(el=>el.classList.toggle('d-none', !el.dataset.autoEffect.split(',').includes(et))); } - function conditionSummary(c){ const base=c.type==='no_seeds'?`no seeds <=${c.seeds||0} for ${c.minutes||0} min`:c.type==='ratio_gte'?`ratio >= ${c.ratio}`:c.type==='label_missing'?`missing label ${c.label||''}`:c.type==='label_has'?`has label ${c.label||''}`:c.type==='status'?`status ${c.status||''}`:c.type==='path_contains'?`path contains ${c.text||''}`:'completed'; return c.negate?`NOT (${base})`:base; } - function effectSummary(e){ return e.type==='move'?`move to ${e.path||'default path'}${e.move_data?' + data move':''}${e.keep_seeding?' + keep seeding':''}${e.recheck?' + recheck':''}`:e.type==='add_label'?`add label ${e.label||''}`:e.type==='remove_label'?`remove label ${e.label||''}`:e.type==='set_labels'?`set labels ${e.labels||''}`:e.type; } - function renderAutomationBuilder(){ const cbox=$('autoConditionsList'), ebox=$('autoEffectsList'); if(cbox) cbox.innerHTML=automationConditionQueue.length?automationConditionQueue.map((c,i)=>`
${details}