Compare commits

..
Author SHA1 Message Date
Rephl3x 87971d1ff0 Expose issue portal navigation
Magent CI/CD / verify (push) Successful in 10m8s
Magent CI/CD / deploy-prod (push) Failing after 1m32s
2026-06-18 21:45:03 +12:00
Rephl3x 8f03e315b8 Fix request detail load failures
Magent CI/CD / verify (push) Failing after 11m3s
Magent CI/CD / deploy-prod (push) Has been skipped
2026-06-18 21:10:56 +12:00
Rephl3x a8aa8e38e2 Add Gitea CI/CD pipeline for beta and prod
Magent CI/CD / verify (push) Has been cancelled
Magent CI/CD / deploy-prod (push) Has been cancelled
2026-05-24 17:07:27 +12:00
Rephl3x 329884b789 Clarify qBittorrent status and fix status pill contrast 2026-05-24 17:03:45 +12:00
Rephl3x 0700d37469 Fix requests cache migration on legacy databases 2026-05-24 16:55:18 +12:00
Rephl3x 2d28047ad7 Merge latest beta with verified auth hardening 2026-05-23 21:14:03 +12:00
Rephl3x cbac743026 Merge security hardening from dev-1.4 2026-05-23 21:12:59 +12:00
Rephl3x 1ce01ec348 Harden auth and outbound admin surfaces 2026-05-23 21:12:45 +12:00
Rephl3x cc26ed9b2c hardening 2026-05-16 10:44:20 +00:00
Rephl3x d9ac54a2ff Process 1 build 0803262237 2026-03-08 22:38:31 +13:00
Rephl3x 3609f44607 Process 1 build 0803262229 2026-03-08 22:30:49 +13:00
Rephl3x f830fc1296 Process 1 build 0803262216 2026-03-08 22:17:33 +13:00
Rephl3x 3989e90a9a Process 1 build 0803262038 2026-03-08 20:40:18 +13:00
Rephl3x 4e2b902760 Process 1 build 0703261729 2026-03-07 17:30:58 +13:00
Rephl3x 494b79ed26 Process 1 build 0403261902 2026-03-04 19:03:52 +13:00
Rephl3x d30a2473ce Improve email deliverability headers and SMTP identity 2026-03-04 17:37:51 +13:00
Rephl3x 4e64f79e64 Fix admin user email visibility 2026-03-04 13:22:26 +13:00
Rephl3x c6bc31f27e Harden auth flows and add backend quality gate 2026-03-04 12:57:42 +13:00
Rephl3x 1ad4823830 Fix email branding with inline logo and reliable MIME transport 2026-03-03 18:42:08 +13:00
Rephl3x caa6aa76d6 Fix email template rendering for Outlook-safe branded content 2026-03-03 17:20:19 +13:00
Rephl3x d80b1e5e4f Update all email templates with uniform branded graphics 2026-03-03 17:02:38 +13:00
Rephl3x 1ff54690fc Add branded HTML email templates 2026-03-03 16:30:02 +13:00
Rephl3x 4f2b5e0922 Add SMTP receipt logging for Exchange relay tracing 2026-03-03 16:12:13 +13:00
Rephl3x 96333c0d85 Fix shared request access and Jellyfin-ready pipeline status 2026-03-03 16:01:36 +13:00
Rephl3x bac96c7db3 Process 1 build 0303261507 2026-03-03 15:07:35 +13:00
Rephl3x dda17a20a5 Improve SQLite batching and diagnostics visibility 2026-03-03 15:03:23 +13:00
Rephl3x e582ff4ef7 Add login page visibility controls 2026-03-03 14:13:39 +13:00
Rephl3x 42d4caa474 Hotfix: expand landing-page search to all requests 2026-03-03 13:24:25 +13:00
Rephl3x 5f2dc52771 Hotfix: add logged-out password reset flow 2026-03-02 20:44:58 +13:00
Rephl3x 9c69d9fd17 Process 1 build 0203261953 2026-03-02 19:54:14 +13:00
Rephl3x b0ef455498 Process 1 build 0203261610 2026-03-02 16:10:40 +13:00
Rephl3x 821f518bb3 Process 1 build 0203261608 2026-03-02 16:08:38 +13:00
Rephl3x eeba143b41 Add dedicated profile invites page and fix mobile admin layout 2026-03-02 15:12:38 +13:00
Rephl3x b068a6066e Persist Seerr media failure suppression and reduce sync error noise 2026-03-01 22:53:38 +13:00
Rephl3x aae2c3d418 Add repository line ending policy 2026-03-01 22:36:49 +13:00
Rephl3x d1c9acbb8d Finalize diagnostics, logging controls, and email test support 2026-03-01 22:34:07 +13:00
Rephl3x 12d3777e76 Add invite email templates and delivery workflow 2026-03-01 15:44:46 +13:00
Rephl3x c205df4367 Finalize dev-1.3 upgrades and Seerr updates 2026-02-28 21:41:16 +13:00
Rephl3x 05a3d1e3b0 admin docs and layout refresh, build 2702261314 2026-02-27 13:17:50 +13:00
Rephl3x b84c27c698 Build 2702261153: fix jellyfin sync user visibility 2026-02-27 11:55:00 +13:00
Rephl3x 744b213fa0 Build 2602262241: live request page updates 2026-02-26 22:42:38 +13:00
Rephl3x f362676c4e Build 2602262204 2026-02-26 22:05:17 +13:00
Rephl3x 7257d32d6c Build 2602262159: restore jellyfin-first user source 2026-02-26 22:00:19 +13:00
Rephl3x 1c6b8255c1 Build 2602262049: split magent settings and harden local login 2026-02-26 20:50:38 +13:00
Rephl3x 0b73d9f4ee Build 2602262030: add magent settings and hardening 2026-02-26 20:31:26 +13:00
Rephl3x b215e8030c Build 2602261731: fix user resync after nuclear wipe 2026-02-26 17:32:48 +13:00
Rephl3x 6a5d2c4310 Build 2602261717: master invite policy and self-service invite controls 2026-02-26 17:18:40 +13:00
Rephl3x 23c57da3cc Build 2602261636: self-service invites and count fixes 2026-02-26 16:37:58 +13:00
Rephl3x 1b1a3e233b Build 2602261605: invite trace and cross-system user lifecycle 2026-02-26 16:06:09 +13:00
Rephl3x bd3c0bdade Build 2602261536: refine invite layouts and tighten UI 2026-02-26 15:37:34 +13:00
Rephl3x 50be0b6b57 Build 2602261523: live updates, invite cleanup and nuclear resync 2026-02-26 15:24:10 +13:00
Rephl3x 5dfe614d15 Build 2602261442: tidy users and invite layouts 2026-02-26 14:42:49 +13:00
Rephl3x ec408df2a1 Build 2602261409: unify invite management controls 2026-02-26 14:10:18 +13:00
Rephl3x f78382c019 Build 2602260214: invites profiles and expiry admin controls 2026-02-26 02:15:21 +13:00
Rephl3x 9be0ec75ec Build 2602260022: enterprise UI refresh and users bulk auto-search 2026-02-26 00:23:41 +13:00
Rephl3x be7b899837 Build 2502262321: fix auto-search quality and per-user toggle 2026-02-25 23:22:33 +13:00
Rephl3x d045dd0b07 Build 0202261541: allow FQDN service URLs 2026-02-02 15:43:08 +13:00
Rephl3x 138069590b Build 3001262148: single container 2026-01-30 21:54:25 +13:00
Rephl3x 8125b766c7 Build 2901262244: format changelog 2026-01-29 22:46:02 +13:00
Rephl3x d53e2917aa Build 2901262240: cache users 2026-01-29 22:42:00 +13:00
Rephl3x d7847652db Tidy full changelog 2026-01-29 22:13:04 +13:00
Rephl3x 24ac54d606 Update full changelog 2026-01-29 22:08:17 +13:00
Rephl3x 62f392ad37 Bake build number and changelog 2026-01-29 22:03:12 +13:00
Rephl3x e42ae8585d Hardcode build number in backend 2026-01-29 21:49:01 +13:00
Rephl3x 06e0797722 release: 2901262102 2026-01-29 21:03:32 +13:00
Rephl3x 914f478178 release: 2901262044 2026-01-29 20:45:20 +13:00
Rephl3x fb65d646f2 release: 2901262036 2026-01-29 20:38:37 +13:00
Rephl3x 3493bf715e Hydrate missing artwork from Jellyseerr (build 271261539) 2026-01-27 15:40:36 +13:00
Rephl3x b98239ab3e Fallback to TMDB when artwork cache fails (build 271261524) 2026-01-27 15:26:10 +13:00
Rephl3x 40dc46c0c5 Add service test buttons (build 271261335) 2026-01-27 13:36:35 +13:00
Rephl3x d23d84ea42 Bump build number (process 2) 271261322 2026-01-27 13:24:35 +13:00
Rephl3x 7d6cdcbe02 Add cache load spinner (build 271261238) 2026-01-27 12:39:51 +13:00
Rephl3x 0e95f94025 Fix snapshot title fallback (build 271261228) 2026-01-27 12:30:04 +13:00
Rephl3x 8b1a09fbd4 Fix request titles in snapshots (build 271261219) 2026-01-27 12:20:12 +13:00
Rephl3x fe0c108363 Bump build number to 271261202 2026-01-27 12:04:42 +13:00
Rephl3x 9e8d22ba85 Clarify request sync settings (build 271261159) 2026-01-27 12:00:32 +13:00
Rephl3x 7863658a19 Fix backend cache stats import (build 271261149) 2026-01-27 11:51:01 +13:00
Rephl3x 7c97934bb9 Improve cache stats performance (build 271261145) 2026-01-27 11:46:50 +13:00
Rephl3x 3f51e24181 Add cache control artwork stats 2026-01-27 11:27:26 +13:00
Rephl3x ab27ebfadf Fix sync progress bar animation 2026-01-26 14:21:18 +13:00
Rephl3x b93b41713a Fix cache title hydration 2026-01-26 14:01:06 +13:00
Rephl3x ceb8c1c9eb Build 2501262041 2026-01-25 20:43:14 +13:00
Rephl3x 86ca3bdeb2 Harden request cache titles and cache-only reads 2026-01-25 19:38:31 +13:00
Rephl3x 22f90b7e07 Serve bundled branding assets by default 2026-01-25 18:20:30 +13:00
Rephl3x 57a4883931 Seed branding logo from bundled assets 2026-01-25 18:01:54 +13:00
Rephl3x 6ba41b854b Tidy request sync controls 2026-01-25 17:52:33 +13:00
Rephl3x 580b335268 Add Jellyfin login cache and admin-only stats 2026-01-25 17:47:03 +13:00
Rephl3x 23549f1e45 Add user stats and activity tracking 2026-01-25 17:04:24 +13:00
Rephl3x 2c45dd0065 Move account actions into avatar menu 2026-01-25 16:48:38 +13:00
Rephl3x 92959d80ab Improve mobile header layout 2026-01-25 16:36:29 +13:00
Rephl3x 615c4c1c29 Automate build number tagging and sync 2026-01-25 14:52:38 +13:00
Rephl3x 38eee2407b Add site banner, build number, and changelog 2026-01-25 14:28:16 +13:00
Rephl3x cf4277d10c Improve request handling and qBittorrent categories 2026-01-24 21:48:55 +13:00
Rephl3x 030480410b Map Prowlarr releases to Arr indexers for manual grab 2026-01-24 19:21:40 +13:00
Rephl3x 3d414b4aeb Clarify how-it-works steps and fixes 2026-01-24 19:15:43 +13:00
Rephl3x 18bbcbf660 Document fix buttons in how-it-works 2026-01-24 19:09:05 +13:00
Rephl3x 5fa3aa6665 Route grabs through Sonarr/Radarr only 2026-01-24 19:06:40 +13:00
Rephl3x 52e3d680f7 Use backend branding assets for logo and favicon 2026-01-23 20:27:12 +13:00
Rephl3x 00bccfa8b6 Copy public assets into frontend image 2026-01-23 20:22:50 +13:00
Rephl3x aa3532dd83 Fix backend Dockerfile paths for root context 2026-01-23 20:17:42 +13:00
Rephl3x 4ec2351241 Add Docker Hub compose override 2026-01-23 20:16:59 +13:00
Rephl3x 6480478167 Remove password fields from users page 2026-01-23 20:16:19 +13:00
Rephl3x 3739e11016 Use bundled branding assets 2026-01-23 20:07:17 +13:00
Rephl3x 132e02e06e Add default branding assets when missing 2026-01-23 20:02:36 +13:00
Rephl3x cc79685eaf Show available status on landing when in Jellyfin 2026-01-23 19:39:26 +13:00
Rephl3x b20cf0a9d2 Fix cache titles and move feedback link 2026-01-23 19:31:31 +13:00
Rephl3x eab212ea8d Add feedback form and webhook 2026-01-23 19:24:45 +13:00
Rephl3x 24685a5371 Hide header actions when signed out 2026-01-23 19:16:17 +13:00
Rephl3x 49e9ee771f Fallback manual grab to qBittorrent 2026-01-23 18:15:36 +13:00
Rephl3x 69dc7febe2 Split search actions and improve download options 2026-01-23 18:05:17 +13:00
Rephl3x 7b8fc1d99b Fix cache titles via Jellyseerr media lookup 2026-01-23 11:35:59 +13:00
Rephl3x 7a7d570852 Update README with Docker-first guide 2026-01-22 22:55:35 +13:00
Rephl3x 3eb4b3f09f Update README 2026-01-22 22:54:13 +13:00
Rephl3x 6425345c69 Ignore build artifacts 2026-01-22 22:50:27 +13:00
Rephl3x fe43a81175 Initial commit 2026-01-22 22:49:57 +13:00
60 changed files with 2071 additions and 16195 deletions
-31
View File
@@ -71,34 +71,3 @@ jobs:
DEPLOY_PATH: ${{ secrets.PROD_DEPLOY_PATH }}
DEPLOY_SSH_OPTS: -o StrictHostKeyChecking=accept-new
run: bash scripts/deploy_ams_dev01.sh
deploy-beta:
if: github.ref_name == 'beta'
needs: verify
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure SSH key
env:
PROD_SSH_PRIVATE_KEY: ${{ secrets.PROD_SSH_PRIVATE_KEY }}
PROD_SSH_KNOWN_HOSTS: ${{ secrets.PROD_SSH_KNOWN_HOSTS }}
run: |
set -euo pipefail
mkdir -p ~/.ssh
chmod 700 ~/.ssh
printf '%s' "$PROD_SSH_PRIVATE_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
if [ -n "${PROD_SSH_KNOWN_HOSTS:-}" ]; then
printf '%s\n' "$PROD_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
fi
- name: Deploy beta to AMS-DEV01
env:
DEPLOY_HOST: ${{ secrets.PROD_SSH_HOST }}
DEPLOY_USER: ${{ secrets.PROD_SSH_USER }}
PROD_DEPLOY_PATH: ${{ secrets.PROD_DEPLOY_PATH }}
DEPLOY_SSH_OPTS: -o StrictHostKeyChecking=accept-new
run: bash scripts/deploy_beta_ams_dev01.sh
+10 -313
View File
@@ -4,249 +4,6 @@ import time
import httpx
from ..logging_config import sanitize_headers, sanitize_value
from ..services.operation_progress import finish_remote_call, start_remote_call
_SERVICE_NAMES = {
"JellyseerrClient": "Seerr",
"SonarrClient": "Sonarr",
"RadarrClient": "Radarr",
"BazarrClient": "Bazarr",
"ProwlarrClient": "Prowlarr",
"JellyfinClient": "Jellyfin",
"QBittorrentClient": "qBittorrent",
}
def _result_items(result: Any, *keys: str) -> list[Any]:
if isinstance(result, list):
return result
if not isinstance(result, dict):
return []
for key in keys:
value = result.get(key)
if isinstance(value, list):
return value
return []
def _result_title(result: Any, payload: Optional[Dict[str, Any]] = None) -> Optional[str]:
candidates = result if isinstance(result, list) else [result]
for candidate in candidates:
if not isinstance(candidate, dict):
continue
title = str(candidate.get("title") or candidate.get("name") or "").strip()
if title:
return title
if isinstance(payload, dict):
title = str(payload.get("title") or payload.get("name") or "").strip()
if title:
return title
return None
def _count_message(count: int, singular: str, plural: Optional[str] = None) -> str:
noun = singular if count == 1 else (plural or f"{singular}s")
return f"{count} {noun}"
def _queue_result_message(service: str, result: Any) -> str:
records = _result_items(result, "records", "items")
total = result.get("totalRecords") if isinstance(result, dict) else None
count = int(total) if isinstance(total, int) else len(records)
if count == 0:
return f"{service} has no matching downloads in its queue."
first = next((item for item in records if isinstance(item, dict)), None)
progress_text = ""
if first:
size = first.get("size")
size_left = first.get("sizeleft")
if isinstance(size, (int, float)) and size > 0 and isinstance(size_left, (int, float)):
progress = max(0, min(100, round((1 - (size_left / size)) * 100)))
progress_text = f" The first is {progress}% complete."
return f"{service} found {_count_message(count, 'matching download')} in its queue.{progress_text}"
def _command_name(payload: Optional[Dict[str, Any]]) -> str:
raw_name = str((payload or {}).get("name") or "").strip()
names = {
"MoviesSearch": "movie search",
"SeriesSearch": "series search",
"EpisodeSearch": "episode search",
"DownloadRelease": "release download",
"RefreshMovie": "movie refresh",
"RescanMovie": "movie rescan",
"RefreshSeries": "series refresh",
"RescanSeries": "series rescan",
}
return names.get(raw_name, "command")
def _operation_result_message(
service: str,
method: str,
path: str,
result: Any,
*,
params: Optional[Dict[str, Any]] = None,
payload: Optional[Dict[str, Any]] = None,
) -> str:
normalized_path = path.lower().split("?", 1)[0].rstrip("/")
normalized_method = method.upper()
title = _result_title(result, payload)
title_text = f' "{title}"' if title else ""
if service == "Seerr":
if normalized_path.endswith("/request") and normalized_method == "POST":
request_id = result.get("id") if isinstance(result, dict) else None
suffix = f" #{request_id}" if isinstance(request_id, int) else ""
return f"Seerr created the request{suffix} and passed it into the collection workflow."
if "/request/" in normalized_path and normalized_method == "GET":
status_names = {1: "waiting for approval", 2: "approved", 3: "declined"}
status = result.get("status") if isinstance(result, dict) else None
status_text = status_names.get(status)
return (
f"Seerr found the request; it is currently {status_text}."
if status_text
else "Seerr found the request and returned its current status."
)
if service in {"Radarr", "Sonarr"}:
media_name = "movie" if service == "Radarr" else "series"
media_path = "/movie" if service == "Radarr" else "/series"
if "/queue" in normalized_path and normalized_method == "GET":
return _queue_result_message(service, result)
if "/command" in normalized_path and normalized_method == "POST":
return f"{service} accepted the {_command_name(payload)} and queued it for processing."
if "/release" in normalized_path:
if normalized_method == "GET":
count = len(_result_items(result, "records", "items"))
return (
f"{service} found {_count_message(count, 'download option')}."
if count
else f"{service} could not find a suitable download option."
)
return f"{service} accepted the selected release and sent it to the download client."
if "/qualityprofile" in normalized_path and normalized_method == "GET":
count = len(_result_items(result))
return f"{service} returned {_count_message(count, 'available quality profile')}."
if "/rootfolder" in normalized_path and normalized_method == "GET":
count = len(_result_items(result))
return f"{service} returned {_count_message(count, 'configured library location')}."
if "/indexer" in normalized_path and normalized_method == "GET":
count = len(_result_items(result))
return f"{service} reports {_count_message(count, 'configured search source')}."
if service == "Sonarr" and "/episodefile" in normalized_path:
if normalized_method == "DELETE":
return "Sonarr removed the existing episode file so it can be replaced."
count = len(_result_items(result))
return f"Sonarr found {_count_message(count, 'downloaded episode file')}."
if service == "Sonarr" and normalized_path.endswith("/episode/monitor") and normalized_method == "PUT":
return "Sonarr marked the selected episodes as wanted."
if service == "Sonarr" and "/episode" in normalized_path and normalized_method == "GET":
episodes = _result_items(result)
available = sum(1 for item in episodes if isinstance(item, dict) and item.get("hasFile") is True)
return f"Sonarr reports {available} of {len(episodes)} episodes downloaded."
if service == "Radarr" and "/moviefile/" in normalized_path and normalized_method == "DELETE":
return "Radarr removed the existing movie file so it can be replaced."
is_media_endpoint = normalized_path.endswith(media_path) or f"{media_path}/" in normalized_path
if is_media_endpoint:
if normalized_method == "GET":
found = bool(result) if not isinstance(result, list) else len(result) > 0
return (
f"{service} found{title_text} in its library list."
if found
else f"This {media_name} is not currently in {service}."
)
if normalized_method == "POST":
search_key = "searchForMovie" if service == "Radarr" else "searchForMissingEpisodes"
search_requested = bool(((payload or {}).get("addOptions") or {}).get(search_key))
search_text = " and started looking for a download" if search_requested else ""
subject = title_text or f" the {media_name}"
return f"{service} added{subject}{search_text}."
if normalized_method == "PUT":
return f"{service} saved the updated settings for{title_text or f' the {media_name}'}."
if "/system/status" in normalized_path:
version = str(result.get("version") or "").strip() if isinstance(result, dict) else ""
return f"Connected to {service}{f' version {version}' if version else ''}."
if service == "Prowlarr":
if "/health" in normalized_path:
issues = _result_items(result)
if not issues:
return "Prowlarr reports that all configured indexers are healthy."
first = next((item for item in issues if isinstance(item, dict)), {})
detail = str(first.get("message") or first.get("source") or "").strip()
suffix = f" First issue: {detail}" if detail else ""
return f"Prowlarr reports {_count_message(len(issues), 'indexer issue')}.{suffix}"
if "/search" in normalized_path:
results = _result_items(result, "results", "records")
return (
f"Prowlarr found {_count_message(len(results), 'possible release')}."
if results
else "Prowlarr did not find any possible releases."
)
if service == "Bazarr" and normalized_method == "PATCH" and "/subtitles" in normalized_path:
target = "movie" if "/movies/" in normalized_path else "selected episode"
language = str((params or {}).get("language") or "the requested language").upper()
return f"Bazarr accepted a fresh {language} subtitle search for the {target}."
if normalized_method == "GET":
return f"{service} completed the check successfully."
if normalized_method == "POST":
return f"{service} accepted the request and started processing it."
if normalized_method == "PUT":
return f"{service} saved the requested changes."
if normalized_method == "DELETE":
return f"{service} confirmed the item was removed."
return f"{service} completed the request successfully."
def _operation_error_message(service: str, status_code: Optional[int]) -> str:
explanations = {
400: "rejected the request because some details were invalid",
401: "rejected Magent's login details",
403: "refused permission for this action",
404: "could not find the requested item",
409: "reported a conflict, usually because the item already exists",
422: "could not use the details Magent supplied",
429: "is busy and asked Magent to try again later",
500: "encountered an internal error while processing the request",
502: "could not reach one of its own dependent services",
503: "is temporarily unavailable",
504: "did not finish before the request timed out",
}
explanation = explanations.get(status_code)
if explanation:
return f"{service} {explanation}."
if status_code:
return f"{service} could not complete the request (response code {status_code})."
return f"Magent could not get a usable response from {service}."
def _operation_messages(service: str, method: str, path: str) -> tuple[str, str]:
normalized_path = path.lower()
normalized_method = method.upper()
if service == "Seerr" and "/request/" in normalized_path and normalized_method == "GET":
return "Reading the request from Seerr…", "Seerr returned the current request record"
if service == "Radarr" and normalized_path.endswith("/movie") and normalized_method == "GET":
return "Checking Radarr for the movie…", "Radarr returned the movie record"
if service == "Sonarr" and normalized_path.endswith("/series") and normalized_method == "GET":
return "Checking Sonarr for the series…", "Sonarr returned the series record"
if service in {"Radarr", "Sonarr"} and "/queue" in normalized_path:
return f"Checking {service}'s download queue…", f"{service} returned its queue state"
if service == "Sonarr" and "/episode" in normalized_path:
return "Checking episode availability in Sonarr…", "Sonarr returned episode availability"
if service in {"Radarr", "Sonarr"} and "/release" in normalized_path:
return f"Checking releases through {service}", f"{service} returned release information"
if service in {"Radarr", "Sonarr"} and "/command" in normalized_path:
return f"Sending a command to {service}", f"{service} accepted the command"
if service == "Bazarr" and "/subtitles" in normalized_path and normalized_method == "PATCH":
return "Asking Bazarr for fresh subtitles…", "Bazarr started the subtitle search"
if service == "Prowlarr" and "/health" in normalized_path:
return "Checking Prowlarr indexer health…", "Prowlarr returned its indexer health"
return f"Contacting {service}", f"{service} responded"
class ApiClient:
@@ -272,24 +29,6 @@ class ApiClient:
return f"{payload[:500]}..."
return payload
async def _send_request(
self,
client: httpx.AsyncClient,
method: str,
url: str,
*,
headers: Dict[str, str],
params: Optional[Dict[str, Any]],
payload: Optional[Dict[str, Any]],
) -> httpx.Response:
return await client.request(
method,
url,
headers=headers,
params=params,
json=payload,
)
async def _request(
self,
method: str,
@@ -297,16 +36,12 @@ class ApiClient:
*,
params: Optional[Dict[str, Any]] = None,
payload: Optional[Dict[str, Any]] = None,
timeout_seconds: float = 10.0,
) -> Optional[Any]:
if not self.base_url:
self.logger.warning("client request skipped method=%s path=%s reason=not-configured", method, path)
return None
url = f"{self.base_url}{path}"
started_at = time.perf_counter()
service_name = _SERVICE_NAMES.get(self.__class__.__name__, self.__class__.__name__.removesuffix("Client"))
active_message, _ = _operation_messages(service_name, method, path)
operation_event_id = start_remote_call(service_name, active_message)
self.logger.debug(
"outbound request started method=%s url=%s params=%s payload=%s headers=%s",
method,
@@ -316,14 +51,13 @@ class ApiClient:
sanitize_headers(self.headers()),
)
try:
async with httpx.AsyncClient(timeout=timeout_seconds) as client:
response = await self._send_request(
client,
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.request(
method,
url,
headers=self.headers(),
params=params,
payload=payload,
json=payload,
)
response.raise_for_status()
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
@@ -334,21 +68,9 @@ class ApiClient:
response.status_code,
duration_ms,
)
result = response.json() if response.content else None
finish_remote_call(
operation_event_id,
success=True,
status_code=response.status_code,
message=_operation_result_message(
service_name,
method,
path,
result,
params=params,
payload=payload,
),
)
return result
if not response.content:
return None
return response.json()
except httpx.HTTPStatusError as exc:
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
response = exc.response
@@ -362,15 +84,6 @@ class ApiClient:
duration_ms,
self._response_summary(response),
)
finish_remote_call(
operation_event_id,
success=False,
status_code=status if isinstance(status, int) else None,
message=_operation_error_message(
service_name,
status if isinstance(status, int) else None,
),
)
raise
except Exception:
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
@@ -380,22 +93,10 @@ class ApiClient:
url,
duration_ms,
)
finish_remote_call(
operation_event_id,
success=False,
message=_operation_error_message(service_name, None),
)
raise
async def get(
self,
path: str,
params: Optional[Dict[str, Any]] = None,
timeout_seconds: float = 10.0,
) -> Optional[Any]:
return await self._request(
"GET", path, params=params, timeout_seconds=timeout_seconds
)
async def get(self, path: str, params: Optional[Dict[str, Any]] = None) -> Optional[Any]:
return await self._request("GET", path, params=params)
async def post(self, path: str, payload: Optional[Dict[str, Any]] = None) -> Optional[Any]:
return await self._request("POST", path, payload=payload)
@@ -403,9 +104,5 @@ class ApiClient:
async def put(self, path: str, payload: Optional[Dict[str, Any]] = None) -> Optional[Any]:
return await self._request("PUT", path, payload=payload)
async def delete(
self,
path: str,
params: Optional[Dict[str, Any]] = None,
) -> Optional[Any]:
return await self._request("DELETE", path, params=params)
async def delete(self, path: str) -> Optional[Any]:
return await self._request("DELETE", path)
-48
View File
@@ -1,48 +0,0 @@
from typing import Any, Optional
from .base import ApiClient
class BazarrClient(ApiClient):
async def get_system_status(self) -> Optional[Any]:
return await self._request("GET", "/api/system/status")
async def search_movie_subtitles(
self,
radarr_id: int,
*,
language: str,
forced: bool = False,
) -> Optional[Any]:
return await self._request(
"PATCH",
"/api/movies/subtitles",
params={
"radarrid": radarr_id,
"language": language,
"forced": str(forced).lower(),
"hi": "false",
},
timeout_seconds=90.0,
)
async def search_episode_subtitles(
self,
series_id: int,
episode_id: int,
*,
language: str,
forced: bool = False,
) -> Optional[Any]:
return await self._request(
"PATCH",
"/api/episodes/subtitles",
params={
"seriesid": series_id,
"episodeid": episode_id,
"language": language,
"forced": str(forced).lower(),
"hi": "false",
},
timeout_seconds=90.0,
)
+8 -78
View File
@@ -1,24 +1,6 @@
from typing import Any, Dict, Optional
import httpx
import time
from .base import ApiClient, _operation_error_message
from ..services.operation_progress import finish_remote_call, start_remote_call
def _availability_message(result: Any) -> str:
if not isinstance(result, dict):
return "Jellyfin did not return any matching library items."
total = result.get("TotalRecordCount")
items = result.get("Items")
available = (
(isinstance(total, int) and total > 0)
or (isinstance(items, list) and len(items) > 0)
)
return (
"The title is available to watch in Jellyfin."
if available
else "The title is not currently available in Jellyfin."
)
from .base import ApiClient
class JellyfinClient(ApiClient):
@@ -185,8 +167,6 @@ class JellyfinClient(ApiClient):
) -> Optional[Dict[str, Any]]:
if not self.base_url or not self.api_key:
return None
started_at = time.perf_counter()
operation_event_id = start_remote_call("Jellyfin", "Checking whether the title is available in Jellyfin…")
url = f"{self.base_url}/Items"
params = {
"SearchTerm": term,
@@ -195,29 +175,10 @@ class JellyfinClient(ApiClient):
"Limit": limit,
}
headers = self._emby_headers()
try:
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.get(url, headers=headers, params=params)
response.raise_for_status()
result = response.json()
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
finish_remote_call(
operation_event_id,
success=True,
status_code=response.status_code,
message=_availability_message(result),
)
return result
except Exception as exc:
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
status_code = exc.response.status_code if isinstance(exc, httpx.HTTPStatusError) else None
finish_remote_call(
operation_event_id,
success=False,
status_code=status_code,
message=_operation_error_message("Jellyfin", status_code),
)
raise
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.get(url, headers=headers, params=params)
response.raise_for_status()
return response.json()
async def get_system_info(self) -> Optional[Dict[str, Any]]:
if not self.base_url or not self.api_key:
@@ -229,43 +190,12 @@ class JellyfinClient(ApiClient):
response.raise_for_status()
return response.json()
async def get_sessions(self) -> Optional[list[Dict[str, Any]]]:
if not self.base_url or not self.api_key:
return None
url = f"{self.base_url}/Sessions"
headers = self._emby_headers()
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.get(url, headers=headers)
response.raise_for_status()
payload = response.json()
return payload if isinstance(payload, list) else []
async def refresh_library(self, recursive: bool = True) -> None:
if not self.base_url or not self.api_key:
return None
started_at = time.perf_counter()
operation_event_id = start_remote_call("Jellyfin", "Asking Jellyfin to refresh its library…")
url = f"{self.base_url}/Library/Refresh"
headers = self._emby_headers()
params = {"Recursive": "true" if recursive else "false"}
try:
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.post(url, headers=headers, params=params)
response.raise_for_status()
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
finish_remote_call(
operation_event_id,
success=True,
status_code=response.status_code,
message="Jellyfin accepted the library refresh and is scanning for new media.",
)
except Exception as exc:
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
status_code = exc.response.status_code if isinstance(exc, httpx.HTTPStatusError) else None
finish_remote_call(
operation_event_id,
success=False,
status_code=status_code,
message=_operation_error_message("Jellyfin", status_code),
)
raise
async with httpx.AsyncClient(timeout=10.0) as client:
response = await client.post(url, headers=headers, params=params)
response.raise_for_status()
+7 -53
View File
@@ -1,44 +1,9 @@
from typing import Any, Dict, Optional
from urllib.parse import quote, unquote, urlsplit
import httpx
from .base import ApiClient
class JellyseerrClient(ApiClient):
async def _send_request(
self,
client: httpx.AsyncClient,
method: str,
url: str,
*,
headers: Dict[str, str],
params: Optional[Dict[str, Any]],
payload: Optional[Dict[str, Any]],
) -> httpx.Response:
request_headers = dict(headers)
if method.upper() in {"POST", "PUT", "PATCH", "DELETE"} and self.base_url:
# Seerr's optional CSRF protection also applies to API-key writes.
# Seed its secret/token cookie pair, then echo the readable token in
# the header Seerr's own web client uses.
csrf_response = await client.get(
f"{self.base_url}/api/v1/auth/me",
headers=self.headers(),
)
csrf_response.raise_for_status()
csrf_token = client.cookies.get("XSRF-TOKEN")
if csrf_token:
request_headers["XSRF-TOKEN"] = unquote(csrf_token)
parsed_base = urlsplit(self.base_url)
request_headers["Origin"] = f"{parsed_base.scheme}://{parsed_base.netloc}"
return await super()._send_request(
client,
method,
url,
headers=request_headers,
params=params,
payload=payload,
)
async def get_status(self) -> Optional[Dict[str, Any]]:
return await self.get("/api/v1/status")
@@ -61,15 +26,13 @@ class JellyseerrClient(ApiClient):
return await self.get(f"/api/v1/tv/{tmdb_id}")
async def search(self, query: str, page: int = 1) -> Optional[Dict[str, Any]]:
# Seerr rejects the `+` encoding that standard query builders use for
# spaces. Build this query explicitly so multi-word titles are sent as
# percent-encoded values.
encoded_query = quote(query, safe="")
return await self.get(f"/api/v1/search?query={encoded_query}&page={page}")
async def get_service_settings(self, media_type: str) -> Optional[Any]:
service = "sonarr" if media_type == "tv" else "radarr"
return await self.get(f"/api/v1/settings/{service}")
return await self.get(
"/api/v1/search",
params={
"query": query,
"page": page,
},
)
async def create_request(
self,
@@ -78,9 +41,6 @@ class JellyseerrClient(ApiClient):
media_id: int,
seasons: Optional[list[int]] = None,
is_4k: Optional[bool] = None,
server_id: Optional[int] = None,
profile_id: Optional[int] = None,
root_folder: Optional[str] = None,
) -> Optional[Dict[str, Any]]:
payload: Dict[str, Any] = {
"mediaType": media_type,
@@ -90,12 +50,6 @@ class JellyseerrClient(ApiClient):
payload["seasons"] = seasons
if isinstance(is_4k, bool):
payload["is4k"] = is_4k
if isinstance(server_id, int):
payload["serverId"] = server_id
if isinstance(profile_id, int):
payload["profileId"] = profile_id
if isinstance(root_folder, str) and root_folder.strip():
payload["rootFolder"] = root_folder.strip()
return await self.post("/api/v1/request", payload=payload)
async def get_users(self, take: int = 50, skip: int = 0) -> Optional[Dict[str, Any]]:
+17 -140
View File
@@ -1,59 +1,7 @@
from typing import Any, Dict, Optional
import httpx
import logging
import time
from .base import ApiClient, _operation_error_message
from ..services.operation_progress import finish_remote_call, start_remote_call
def _torrent_state_text(state: Any) -> str:
normalized = str(state or "").strip().lower()
if "pause" in normalized:
return "paused"
if "stall" in normalized:
return "stalled"
if normalized.startswith("queued"):
return "waiting in the queue"
if "downloading" in normalized or normalized in {"forcedl", "metadl", "checkingdl"}:
return "downloading"
if "upload" in normalized or normalized in {"stalledup", "forcedup"}:
return "finished and seeding"
if normalized in {"completed", "missingfiles"}:
return "finished" if normalized == "completed" else "missing files"
if "error" in normalized:
return "in an error state"
return "present"
def _torrent_result_message(result: Any) -> str:
torrents = result if isinstance(result, list) else []
if not torrents:
return "qBittorrent found no matching downloads."
first = next((item for item in torrents if isinstance(item, dict)), {})
if len(torrents) == 1:
name = str(first.get("name") or "the matching download").strip()
progress = first.get("progress")
progress_text = (
f" and {max(0, min(100, round(progress * 100)))}% complete"
if isinstance(progress, (int, float))
else ""
)
return f'qBittorrent found "{name}"; it is {_torrent_state_text(first.get("state"))}{progress_text}.'
active = sum(
1
for item in torrents
if isinstance(item, dict) and _torrent_state_text(item.get("state")) == "downloading"
)
return f"qBittorrent found {len(torrents)} matching downloads; {active} are actively downloading."
def _torrent_action_message(path: str) -> str:
normalized_path = path.lower()
if normalized_path.endswith("/resume") or normalized_path.endswith("/start"):
return "qBittorrent accepted the request to resume the download."
if normalized_path.endswith("/add"):
return "qBittorrent accepted the release and added it to the download queue."
return "qBittorrent accepted the requested download action."
from .base import ApiClient
class QBittorrentClient(ApiClient):
@@ -75,98 +23,34 @@ class QBittorrentClient(ApiClient):
headers={"Referer": self.base_url},
)
response.raise_for_status()
text = response.text.strip().lower()
has_session_cookie = any(name.upper().startswith("QBT_SID") for name in client.cookies.keys())
if text not in {"ok.", ""} or (text == "" and not has_session_cookie):
if response.text.strip().lower() != "ok.":
raise RuntimeError("qBittorrent login failed")
async def _get(self, path: str, params: Optional[Dict[str, Any]] = None) -> Optional[Any]:
if not self.base_url:
return None
started_at = time.perf_counter()
operation_event_id = start_remote_call("qBittorrent", "Checking qBittorrent for matching downloads…")
try:
async with httpx.AsyncClient(timeout=10.0) as client:
await self._login(client)
response = await client.get(f"{self.base_url}{path}", params=params)
response.raise_for_status()
result = response.json()
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
finish_remote_call(
operation_event_id,
success=True,
status_code=response.status_code,
message=_torrent_result_message(result),
)
return result
except Exception as exc:
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
status_code = exc.response.status_code if isinstance(exc, httpx.HTTPStatusError) else None
finish_remote_call(
operation_event_id,
success=False,
status_code=status_code,
message=_operation_error_message("qBittorrent", status_code),
)
raise
async with httpx.AsyncClient(timeout=10.0) as client:
await self._login(client)
response = await client.get(f"{self.base_url}{path}", params=params)
response.raise_for_status()
return response.json()
async def _get_text(self, path: str, params: Optional[Dict[str, Any]] = None) -> Optional[str]:
if not self.base_url:
return None
started_at = time.perf_counter()
operation_event_id = start_remote_call("qBittorrent")
try:
async with httpx.AsyncClient(timeout=10.0) as client:
await self._login(client)
response = await client.get(f"{self.base_url}{path}", params=params)
response.raise_for_status()
result = response.text.strip()
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
finish_remote_call(
operation_event_id,
success=True,
status_code=response.status_code,
message=f"Connected to qBittorrent{f' version {result}' if result else ''}.",
)
return result
except Exception as exc:
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
status_code = exc.response.status_code if isinstance(exc, httpx.HTTPStatusError) else None
finish_remote_call(
operation_event_id,
success=False,
status_code=status_code,
message=_operation_error_message("qBittorrent", status_code),
)
raise
async with httpx.AsyncClient(timeout=10.0) as client:
await self._login(client)
response = await client.get(f"{self.base_url}{path}", params=params)
response.raise_for_status()
return response.text.strip()
async def _post_form(self, path: str, data: Dict[str, Any]) -> None:
if not self.base_url:
return None
started_at = time.perf_counter()
operation_event_id = start_remote_call("qBittorrent")
try:
async with httpx.AsyncClient(timeout=10.0) as client:
await self._login(client)
response = await client.post(f"{self.base_url}{path}", data=data)
response.raise_for_status()
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
finish_remote_call(
operation_event_id,
success=True,
status_code=response.status_code,
message=_torrent_action_message(path),
)
except Exception as exc:
duration_ms = round((time.perf_counter() - started_at) * 1000, 2)
status_code = exc.response.status_code if isinstance(exc, httpx.HTTPStatusError) else None
finish_remote_call(
operation_event_id,
success=False,
status_code=status_code,
message=_operation_error_message("qBittorrent", status_code),
)
raise
async with httpx.AsyncClient(timeout=10.0) as client:
await self._login(client)
response = await client.post(f"{self.base_url}{path}", data=data)
response.raise_for_status()
async def is_webui_reachable(self) -> bool:
if not self.base_url:
@@ -188,9 +72,6 @@ class QBittorrentClient(ApiClient):
async def get_torrents_by_category(self, category: str) -> Optional[Any]:
return await self._get("/api/v2/torrents/info", params={"category": category})
async def get_torrents_by_tag(self, tag: str) -> Optional[Any]:
return await self._get("/api/v2/torrents/info", params={"tag": tag})
async def get_app_version(self) -> Optional[Any]:
return await self._get_text("/api/v2/app/version")
@@ -203,9 +84,7 @@ class QBittorrentClient(ApiClient):
return
raise
async def add_torrent_url(
self, url: str, category: Optional[str] = None, tags: Optional[str] = None
) -> None:
async def add_torrent_url(self, url: str, category: Optional[str] = None) -> None:
url_host = None
if isinstance(url, str) and "://" in url:
url_host = url.split("://", 1)[-1].split("/", 1)[0]
@@ -217,6 +96,4 @@ class QBittorrentClient(ApiClient):
data: Dict[str, Any] = {"urls": url}
if category:
data["category"] = category
if tags:
data["tags"] = tags
await self._post_form("/api/v2/torrents/add", data=data)
-30
View File
@@ -9,10 +9,6 @@ class RadarrClient(ApiClient):
async def get_movie_by_tmdb_id(self, tmdb_id: int) -> Optional[Dict[str, Any]]:
return await self.get("/api/v3/movie", params={"tmdbId": tmdb_id})
async def lookup_movie_by_tmdb_id(self, tmdb_id: int) -> Optional[Dict[str, Any]]:
result = await self.get("/api/v3/movie/lookup/tmdb", params={"tmdbId": tmdb_id})
return result if isinstance(result, dict) else None
async def get_movie(self, movie_id: int) -> Optional[Dict[str, Any]]:
return await self.get(f"/api/v3/movie/{movie_id}")
@@ -28,32 +24,12 @@ class RadarrClient(ApiClient):
async def get_queue(self, movie_id: int) -> Optional[Dict[str, Any]]:
return await self.get("/api/v3/queue", params={"movieId": movie_id})
async def search_releases(self, movie_id: int) -> Optional[Any]:
return await self.get(
"/api/v3/release", params={"movieId": movie_id}, timeout_seconds=90.0
)
async def get_indexers(self) -> Optional[Dict[str, Any]]:
return await self.get("/api/v3/indexer")
async def search(self, movie_id: int) -> Optional[Dict[str, Any]]:
return await self.post("/api/v3/command", payload={"name": "MoviesSearch", "movieIds": [movie_id]})
async def monitor_movie(
self, movie_id: int, monitored: bool = True
) -> Optional[Dict[str, Any]]:
movie = await self.get_movie(movie_id)
if not isinstance(movie, dict):
raise ValueError("Radarr did not return the movie before updating its monitored state")
movie["monitored"] = monitored
return await self.update_movie(movie)
async def delete_movie_file(self, movie_file_id: int) -> Optional[Any]:
return await self.delete(
f"/api/v3/moviefile/{movie_file_id}",
params={"deleteFromClient": "true"},
)
async def add_movie(
self,
tmdb_id: int,
@@ -61,15 +37,9 @@ class RadarrClient(ApiClient):
root_folder: str,
monitored: bool = True,
search_for_movie: bool = True,
title: Optional[str] = None,
) -> Optional[Dict[str, Any]]:
lookup = await self.lookup_movie_by_tmdb_id(tmdb_id)
resolved_title = str((lookup or {}).get("title") or "").strip() or (title or "").strip()
if not resolved_title:
raise ValueError("Radarr could not resolve a title for this TMDB ID")
payload = {
"tmdbId": tmdb_id,
"title": resolved_title,
"qualityProfileId": quality_profile_id,
"rootFolderPath": root_folder,
"monitored": monitored,
+2 -43
View File
@@ -9,20 +9,6 @@ class SonarrClient(ApiClient):
async def get_series_by_tvdb_id(self, tvdb_id: int) -> Optional[Dict[str, Any]]:
return await self.get("/api/v3/series", params={"tvdbId": tvdb_id})
async def lookup_series_by_tvdb_id(self, tvdb_id: int) -> Optional[Dict[str, Any]]:
result = await self.get("/api/v3/series/lookup", params={"term": f"tvdb:{tvdb_id}"})
if not isinstance(result, list):
return None
for item in result:
if not isinstance(item, dict):
continue
try:
if int(item.get("tvdbId")) == tvdb_id:
return item
except (TypeError, ValueError):
continue
return next((item for item in result if isinstance(item, dict)), None)
async def get_series(self, series_id: int) -> Optional[Dict[str, Any]]:
return await self.get(f"/api/v3/series/{series_id}")
@@ -41,36 +27,12 @@ class SonarrClient(ApiClient):
async def get_episodes(self, series_id: int) -> Optional[Dict[str, Any]]:
return await self.get("/api/v3/episode", params={"seriesId": series_id})
async def get_episode_files(self, series_id: int) -> Optional[Dict[str, Any]]:
return await self.get("/api/v3/episodefile", params={"seriesId": series_id})
async def search_releases(self, series_id: int, season_number: int) -> Optional[Any]:
return await self.get(
"/api/v3/release",
params={"seriesId": series_id, "seasonNumber": season_number},
timeout_seconds=90.0,
)
async def search(self, series_id: int) -> Optional[Dict[str, Any]]:
return await self.post("/api/v3/command", payload={"name": "SeriesSearch", "seriesId": series_id})
async def search_episodes(self, episode_ids: list[int]) -> Optional[Dict[str, Any]]:
return await self.post("/api/v3/command", payload={"name": "EpisodeSearch", "episodeIds": episode_ids})
async def monitor_episodes(
self, episode_ids: list[int], monitored: bool = True
) -> Optional[Dict[str, Any]]:
return await self.put(
"/api/v3/episode/monitor",
payload={"episodeIds": episode_ids, "monitored": monitored},
)
async def delete_episode_file(self, episode_file_id: int) -> Optional[Any]:
return await self.delete(
f"/api/v3/episodefile/{episode_file_id}",
params={"deleteFromClient": "true"},
)
async def add_series(
self,
tvdb_id: int,
@@ -80,19 +42,16 @@ class SonarrClient(ApiClient):
title: Optional[str] = None,
search_missing: bool = True,
) -> Optional[Dict[str, Any]]:
lookup = await self.lookup_series_by_tvdb_id(tvdb_id)
resolved_title = str((lookup or {}).get("title") or "").strip() or (title or "").strip()
if not resolved_title:
raise ValueError("Sonarr could not resolve a title for this TVDB ID")
payload = {
"tvdbId": tvdb_id,
"title": resolved_title,
"qualityProfileId": quality_profile_id,
"rootFolderPath": root_folder,
"monitored": monitored,
"seasonFolder": True,
"addOptions": {"searchForMissingEpisodes": search_missing},
}
if title:
payload["title"] = title
return await self.post("/api/v3/series", payload=payload)
async def update_series(self, payload: Dict[str, Any]) -> Optional[Dict[str, Any]]:
-22
View File
@@ -85,15 +85,6 @@ class Settings(BaseSettings):
requests_data_source: str = Field(
default="prefer_cache", validation_alias=AliasChoices("REQUESTS_DATA_SOURCE")
)
issue_confirmation_contact_attempts: int = Field(
default=2, validation_alias=AliasChoices("ISSUE_CONFIRMATION_CONTACT_ATTEMPTS")
)
issue_confirmation_interval_value: int = Field(
default=3, validation_alias=AliasChoices("ISSUE_CONFIRMATION_INTERVAL_VALUE")
)
issue_confirmation_interval_unit: str = Field(
default="days", validation_alias=AliasChoices("ISSUE_CONFIRMATION_INTERVAL_UNIT")
)
artwork_cache_mode: str = Field(
default="remote", validation_alias=AliasChoices("ARTWORK_CACHE_MODE")
)
@@ -119,9 +110,6 @@ class Settings(BaseSettings):
site_login_show_signup_link: bool = Field(
default=True, validation_alias=AliasChoices("SITE_LOGIN_SHOW_SIGNUP_LINK")
)
site_nav_show_requests: bool = Field(
default=True, validation_alias=AliasChoices("SITE_NAV_SHOW_REQUESTS")
)
site_changelog: Optional[str] = Field(default=CHANGELOG)
magent_application_url: Optional[str] = Field(
@@ -305,16 +293,6 @@ class Settings(BaseSettings):
validation_alias=AliasChoices("RADARR_QBITTORRENT_CATEGORY"),
)
bazarr_base_url: Optional[str] = Field(
default=None, validation_alias=AliasChoices("BAZARR_URL", "BAZARR_BASE_URL")
)
bazarr_api_key: Optional[str] = Field(
default=None, validation_alias=AliasChoices("BAZARR_API_KEY", "BAZARR_KEY")
)
bazarr_default_language: str = Field(
default="en", validation_alias=AliasChoices("BAZARR_DEFAULT_LANGUAGE")
)
prowlarr_base_url: Optional[str] = Field(
default=None, validation_alias=AliasChoices("PROWLARR_URL", "PROWLARR_BASE_URL")
)
+1 -193
View File
@@ -400,27 +400,6 @@ def init_db() -> None:
)
"""
)
conn.execute(
"""
CREATE TABLE IF NOT EXISTS portal_item_activity (
id INTEGER PRIMARY KEY AUTOINCREMENT,
item_id INTEGER NOT NULL,
event_type TEXT NOT NULL,
actor_username TEXT NOT NULL,
actor_role TEXT NOT NULL,
message TEXT NOT NULL,
metadata_json TEXT,
created_at TEXT NOT NULL,
FOREIGN KEY(item_id) REFERENCES portal_items(id) ON DELETE CASCADE
)
"""
)
conn.execute(
"""
CREATE INDEX IF NOT EXISTS idx_portal_item_activity_item
ON portal_item_activity (item_id, created_at ASC, id ASC)
"""
)
conn.execute(
"""
CREATE INDEX IF NOT EXISTS idx_requests_cache_created_at
@@ -712,18 +691,6 @@ def save_snapshot(snapshot: Snapshot) -> None:
payload = json.dumps(snapshot.model_dump(), ensure_ascii=True)
created_at = datetime.now(timezone.utc).isoformat()
with _connect() as conn:
latest = conn.execute(
"""
SELECT state, state_reason
FROM snapshots
WHERE request_id = ?
ORDER BY id DESC
LIMIT 1
""",
(snapshot.request_id,),
).fetchone()
if latest and latest[0] == snapshot.state.value and latest[1] == snapshot.state_reason:
return
conn.execute(
"""
INSERT INTO snapshots (request_id, state, state_reason, created_at, payload_json)
@@ -758,7 +725,6 @@ def save_action(
def get_recent_snapshots(request_id: str, limit: int = 10) -> list[dict[str, Any]]:
bounded_limit = max(1, min(int(limit or 10), 100))
with _connect() as conn:
rows = conn.execute(
"""
@@ -768,15 +734,10 @@ def get_recent_snapshots(request_id: str, limit: int = 10) -> list[dict[str, Any
ORDER BY id DESC
LIMIT ?
""",
(request_id, min(bounded_limit * 20, 500)),
(request_id, limit),
).fetchall()
results = []
previous_signature: tuple[str, Optional[str]] | None = None
for row in rows:
signature = (row[1], row[2])
if signature == previous_signature:
continue
previous_signature = signature
results.append(
{
"request_id": row[0],
@@ -786,8 +747,6 @@ def get_recent_snapshots(request_id: str, limit: int = 10) -> list[dict[str, Any
"payload": json.loads(row[4]),
}
)
if len(results) >= bounded_limit:
break
return results
@@ -818,55 +777,6 @@ def get_recent_actions(request_id: str, limit: int = 10) -> list[dict[str, Any]]
return results
def get_request_download_evidence(request_id: str, limit: int = 100) -> Dict[str, Any]:
"""Return the most recent proof that this request reached qBittorrent.
A current qBittorrent API error is not proof that a download exists. Historical
snapshots are used so a torrent that has since been removed can still be
described honestly in the UI.
"""
with _connect() as conn:
rows = conn.execute(
"""
SELECT created_at, payload_json
FROM snapshots
WHERE request_id = ?
ORDER BY id DESC
LIMIT ?
""",
(request_id, max(1, min(int(limit or 100), 500))),
).fetchall()
for created_at, payload_json in rows:
try:
payload = json.loads(payload_json)
except (TypeError, ValueError):
continue
timeline = payload.get("timeline") if isinstance(payload, dict) else None
if not isinstance(timeline, list):
continue
for hop in timeline:
if not isinstance(hop, dict) or hop.get("service") != "qBittorrent":
continue
details = hop.get("details") if isinstance(hop.get("details"), dict) else {}
torrents = details.get("torrents")
if isinstance(torrents, list) and torrents:
return {
"observed": True,
"last_seen_at": created_at,
"state": hop.get("status"),
"summary": details.get("summary"),
"torrents": torrents,
}
return {
"observed": False,
"last_seen_at": None,
"state": None,
"summary": None,
"torrents": [],
}
def ensure_admin_user() -> None:
if not settings.admin_username or not _has_secure_bootstrap_admin_credentials():
return
@@ -3519,23 +3429,6 @@ def update_portal_item(
return updated
def delete_portal_item(item_id: int) -> bool:
with _connect() as conn:
conn.execute(
"UPDATE portal_items SET related_item_id = NULL WHERE related_item_id = ?",
(item_id,),
)
conn.execute("DELETE FROM portal_comments WHERE item_id = ?", (item_id,))
conn.execute("DELETE FROM portal_item_activity WHERE item_id = ?", (item_id,))
deleted = conn.execute(
"DELETE FROM portal_items WHERE id = ?",
(item_id,),
).rowcount
if deleted:
logger.info("portal item deleted id=%s", item_id)
return bool(deleted)
def add_portal_comment(
item_id: int,
*,
@@ -3618,91 +3511,6 @@ def list_portal_comments(item_id: int, *, include_internal: bool = True, limit:
return [_portal_comment_from_row(row) for row in rows]
def add_portal_item_activity(
item_id: int,
*,
event_type: str,
actor_username: str,
actor_role: str,
message: str,
metadata_json: Optional[str] = None,
) -> Dict[str, Any]:
now = datetime.now(timezone.utc).isoformat()
with _connect() as conn:
cursor = conn.execute(
"""
INSERT INTO portal_item_activity (
item_id,
event_type,
actor_username,
actor_role,
message,
metadata_json,
created_at
)
VALUES (?, ?, ?, ?, ?, ?, ?)
""",
(
item_id,
event_type,
actor_username,
actor_role,
message,
metadata_json,
now,
),
)
activity_id = cursor.lastrowid
row = conn.execute(
"""
SELECT id, item_id, event_type, actor_username, actor_role, message, metadata_json, created_at
FROM portal_item_activity
WHERE id = ?
""",
(activity_id,),
).fetchone()
if not row:
raise RuntimeError("Portal activity could not be loaded after insert.")
return {
"id": row[0],
"item_id": row[1],
"event_type": row[2],
"actor_username": row[3],
"actor_role": row[4],
"message": row[5],
"metadata_json": row[6],
"created_at": row[7],
}
def list_portal_item_activity(item_id: int, *, limit: int = 300) -> list[Dict[str, Any]]:
safe_limit = max(1, min(int(limit), 500))
with _connect() as conn:
rows = conn.execute(
"""
SELECT id, item_id, event_type, actor_username, actor_role, message, metadata_json, created_at
FROM portal_item_activity
WHERE item_id = ?
ORDER BY created_at ASC, id ASC
LIMIT ?
""",
(item_id, safe_limit),
).fetchall()
return [
{
"id": row[0],
"item_id": row[1],
"event_type": row[2],
"actor_username": row[3],
"actor_role": row[4],
"message": row[5],
"metadata_json": row[6],
"created_at": row[7],
}
for row in rows
]
def get_portal_overview() -> Dict[str, Any]:
with _connect() as conn:
kind_rows = conn.execute(
-28
View File
@@ -25,15 +25,7 @@ from .routers.feedback import router as feedback_router
from .routers.site import router as site_router
from .routers.events import router as events_router
from .routers.portal import router as portal_router
from .routers.operations import router as operations_router
from .services.jellyfin_sync import run_daily_jellyfin_sync
from .services.issue_resolution import run_issue_confirmation_loop
from .services.operation_progress import (
begin_operation,
finish_operation,
normalize_operation_id,
reset_operation,
)
from .logging_config import (
bind_request_id,
configure_logging,
@@ -67,14 +59,6 @@ app.add_middleware(
async def log_requests_and_add_security_headers(request: Request, call_next):
request_id = request.headers.get("X-Request-ID") or uuid.uuid4().hex[:12]
token = bind_request_id(request_id)
operation_id = normalize_operation_id(request.headers.get("X-Magent-Operation-ID"))
operation_token = None
if operation_id and request.method.upper() not in {"GET", "HEAD", "OPTIONS"}:
operation_token = begin_operation(
operation_id,
label=request.headers.get("X-Magent-Operation-Label"),
path=request.url.path,
)
request.state.request_id = request_id
started_at = time.perf_counter()
body = await request.body()
@@ -117,9 +101,6 @@ async def log_requests_and_add_security_headers(request: Request, call_next):
request.url.path,
duration_ms,
)
if operation_id and operation_token is not None:
finish_operation(operation_id, success=False, status_code=500)
reset_operation(operation_token)
reset_request_id(token)
raise
@@ -149,13 +130,6 @@ async def log_requests_and_add_security_headers(request: Request, call_next):
}
),
)
if operation_id and operation_token is not None:
finish_operation(
operation_id,
success=response.status_code < 400,
status_code=response.status_code,
)
reset_operation(operation_token)
reset_request_id(token)
return response
@@ -256,7 +230,6 @@ async def startup() -> None:
_launch_background_task("requests-delta-loop", run_requests_delta_loop)
_launch_background_task("requests-full-sync", run_daily_requests_full_sync)
_launch_background_task("db-cleanup", run_daily_db_cleanup)
_launch_background_task("issue-confirmation", run_issue_confirmation_loop)
logger.info("startup complete")
@@ -271,4 +244,3 @@ app.include_router(feedback_router)
app.include_router(site_router)
app.include_router(events_router)
app.include_router(portal_router)
app.include_router(operations_router)
-2
View File
@@ -35,7 +35,6 @@ class ActionOption(BaseModel):
id: str
label: str
risk: str
description: Optional[str] = None
requires_confirmation: bool = True
@@ -49,7 +48,6 @@ class Snapshot(BaseModel):
timeline: List[TimelineHop] = Field(default_factory=list)
actions: List[ActionOption] = Field(default_factory=list)
artwork: Dict[str, Any] = Field(default_factory=dict)
presentation: Dict[str, Any] = Field(default_factory=dict)
raw: Dict[str, Any] = Field(default_factory=dict)
+3 -108
View File
@@ -122,15 +122,6 @@ def _require_recipient_email(value: object) -> str:
detail="recipient_email is required and must be a valid email address",
)
def _optional_recipient_email(value: object) -> Optional[str]:
if value is None or (isinstance(value, str) and not value.strip()):
return None
normalized = normalize_delivery_email(value)
if normalized:
return normalized
raise HTTPException(status_code=400, detail="recipient_email must be a valid email address")
SENSITIVE_KEYS = {
"magent_ssl_certificate_pem",
"magent_ssl_private_key_pem",
@@ -144,7 +135,6 @@ SENSITIVE_KEYS = {
"jellyfin_api_key",
"sonarr_api_key",
"radarr_api_key",
"bazarr_api_key",
"prowlarr_api_key",
"qbittorrent_password",
}
@@ -160,7 +150,6 @@ URL_SETTING_KEYS = {
"jellyfin_public_url",
"sonarr_base_url",
"radarr_base_url",
"bazarr_base_url",
"prowlarr_base_url",
"qbittorrent_base_url",
}
@@ -227,9 +216,6 @@ SETTING_KEYS: List[str] = [
"radarr_quality_profile_id",
"radarr_root_folder",
"radarr_qbittorrent_category",
"bazarr_base_url",
"bazarr_api_key",
"bazarr_default_language",
"prowlarr_base_url",
"prowlarr_api_key",
"qbittorrent_base_url",
@@ -248,9 +234,6 @@ SETTING_KEYS: List[str] = [
"requests_cleanup_time",
"requests_cleanup_days",
"requests_data_source",
"issue_confirmation_contact_attempts",
"issue_confirmation_interval_value",
"issue_confirmation_interval_unit",
"site_banner_enabled",
"site_banner_message",
"site_banner_tone",
@@ -258,7 +241,6 @@ SETTING_KEYS: List[str] = [
"site_login_show_local_login",
"site_login_show_forgot_password",
"site_login_show_signup_link",
"site_nav_show_requests",
]
@@ -678,26 +660,6 @@ async def update_settings(payload: Dict[str, Any]) -> Dict[str, Any]:
changed_keys.append(key)
continue
value_to_store = str(value).strip() if isinstance(value, str) else str(value)
if key == "issue_confirmation_contact_attempts":
try:
attempts = int(value_to_store)
except (TypeError, ValueError) as exc:
raise HTTPException(status_code=400, detail="Confirmation contacts must be a whole number from 0 to 10") from exc
if attempts < 0 or attempts > 10:
raise HTTPException(status_code=400, detail="Confirmation contacts must be from 0 to 10")
value_to_store = str(attempts)
if key == "issue_confirmation_interval_value":
try:
interval_value = int(value_to_store)
except (TypeError, ValueError) as exc:
raise HTTPException(status_code=400, detail="Confirmation interval must be a whole number") from exc
if interval_value < 1 or interval_value > 365:
raise HTTPException(status_code=400, detail="Confirmation interval must be from 1 to 365")
value_to_store = str(interval_value)
if key == "issue_confirmation_interval_unit":
value_to_store = value_to_store.lower()
if value_to_store not in {"days", "weeks", "months"}:
raise HTTPException(status_code=400, detail="Confirmation interval unit must be days, weeks, or months")
if key in URL_SETTING_KEYS and value_to_store:
try:
value_to_store = _normalize_service_url(value_to_store)
@@ -1358,35 +1320,6 @@ async def update_user_role(username: str, payload: Dict[str, Any]) -> Dict[str,
return {"status": "ok", "username": username, "role": role}
@router.post("/users/{username}/email")
async def update_user_email(username: str, payload: Dict[str, Any]) -> Dict[str, Any]:
user = get_user_by_username(username)
if not user:
raise HTTPException(status_code=404, detail="User not found")
if not isinstance(payload, dict):
raise HTTPException(status_code=400, detail="Invalid payload")
email = _optional_recipient_email(payload.get("email"))
if email:
duplicate = next(
(
candidate
for candidate in get_all_users()
if str(candidate.get("username") or "").casefold() != username.casefold()
and str(candidate.get("email") or "").strip().casefold() == email.casefold()
),
None,
)
if duplicate:
raise HTTPException(status_code=409, detail="That email address is already assigned to another user")
if not set_user_email(username, email):
raise HTTPException(status_code=404, detail="User not found")
refreshed = get_user_by_username(username)
logger.info("Admin updated user contact email: username=%s email_set=%s", username, bool(email))
return {"status": "ok", "user": refreshed, "email": email}
@router.post("/users/{username}/auto-search")
async def update_user_auto_search(username: str, payload: Dict[str, Any]) -> Dict[str, Any]:
enabled = payload.get("enabled") if isinstance(payload, dict) else None
@@ -1733,34 +1666,9 @@ async def get_invites() -> Dict[str, Any]:
results = []
for invite in invites:
profile = profiles.get(invite.get("profile_id"))
if not invite.get("enabled"):
operational_state = "disabled"
state_label = "Disabled"
attention_reason = "This invite has been switched off."
elif invite.get("is_expired"):
operational_state = "expired"
state_label = "Expired"
attention_reason = "The invite has passed its expiry date."
elif invite.get("remaining_uses") == 0:
operational_state = "exhausted"
state_label = "Fully used"
attention_reason = "Every permitted sign-up has been used."
elif invite.get("profile_id") is not None and (
profile is None or profile.get("is_active") is False
):
operational_state = "profile_unavailable"
state_label = "Profile unavailable"
attention_reason = "The assigned profile is missing or disabled."
else:
operational_state = "ready"
state_label = "Ready to use"
attention_reason = None
results.append(
{
**invite,
"operational_state": operational_state,
"state_label": state_label,
"attention_reason": attention_reason,
"profile": (
{
"id": profile.get("id"),
@@ -1771,16 +1679,7 @@ async def get_invites() -> Dict[str, Any]:
),
}
)
return {
"invites": results,
"summary": {
"total": len(results),
"ready": sum(1 for invite in results if invite["operational_state"] == "ready"),
"attention": sum(1 for invite in results if invite["operational_state"] != "ready"),
"used_signups": sum(int(invite.get("use_count") or 0) for invite in results),
"with_recipient": sum(1 for invite in results if invite.get("recipient_email")),
},
}
return {"invites": results}
@router.get("/invites/policy")
@@ -1965,10 +1864,8 @@ async def create_invite(payload: Dict[str, Any], current_user: Dict[str, Any] =
role = _normalize_role_or_none(payload.get("role"))
max_uses = _parse_optional_positive_int(payload.get("max_uses"), "max_uses")
expires_at = _parse_optional_expires_at(payload.get("expires_at"))
recipient_email = _optional_recipient_email(payload.get("recipient_email"))
recipient_email = _require_recipient_email(payload.get("recipient_email"))
send_email = bool(payload.get("send_email"))
if send_email and not recipient_email:
raise HTTPException(status_code=400, detail="recipient_email is required for email delivery")
delivery_message = _normalize_optional_text(payload.get("message"))
try:
invite = create_signup_invite(
@@ -2038,10 +1935,8 @@ async def edit_invite(invite_id: int, payload: Dict[str, Any]) -> Dict[str, Any]
role = _normalize_role_or_none(payload.get("role"))
max_uses = _parse_optional_positive_int(payload.get("max_uses"), "max_uses")
expires_at = _parse_optional_expires_at(payload.get("expires_at"))
recipient_email = _optional_recipient_email(payload.get("recipient_email"))
recipient_email = _normalize_optional_text(payload.get("recipient_email"))
send_email = bool(payload.get("send_email"))
if send_email and not recipient_email:
raise HTTPException(status_code=400, detail="recipient_email is required for email delivery")
delivery_message = _normalize_optional_text(payload.get("message"))
try:
invite = update_signup_invite(
+24
View File
@@ -11,6 +11,7 @@ from fastapi.responses import StreamingResponse
from ..auth import get_current_user_event_stream
from . import requests as requests_router
from .status import services_status
router = APIRouter(prefix="/events", tags=["events"])
@@ -84,7 +85,9 @@ async def events_stream(
async def event_generator():
yield "retry: 2000\n\n"
last_recent_signature: Optional[str] = None
last_services_signature: Optional[str] = None
next_recent_at = 0.0
next_services_at = 0.0
heartbeat_counter = 0
while True:
@@ -126,6 +129,27 @@ async def events_stream(
yield _sse_json(payload)
sent_any = True
if now >= next_services_at:
next_services_at = now + 30.0
try:
status_payload = await services_status()
payload = {
"type": "home_services",
"ts": datetime.now(timezone.utc).isoformat(),
"status": status_payload,
}
except Exception as exc:
payload = {
"type": "home_services",
"ts": datetime.now(timezone.utc).isoformat(),
"error": str(exc),
}
signature = json.dumps(payload, ensure_ascii=True, separators=(",", ":"), default=str)
if signature != last_services_signature:
last_services_signature = signature
yield _sse_json(payload)
sent_any = True
if sent_any:
heartbeat_counter = 0
else:
-19
View File
@@ -1,19 +0,0 @@
from fastapi import APIRouter, Depends, HTTPException
from ..auth import get_current_user
from ..services.operation_progress import get_operation
router = APIRouter(
prefix="/operations",
tags=["operations"],
dependencies=[Depends(get_current_user)],
)
@router.get("/{operation_id}")
async def operation_status(operation_id: str) -> dict:
operation = get_operation(operation_id)
if not operation:
raise HTTPException(status_code=404, detail="Operation not found")
return operation
+3 -459
View File
@@ -1,35 +1,23 @@
from __future__ import annotations
import logging
import time
from datetime import datetime, timezone
from typing import Any, Dict, Optional, Tuple
import httpx
from fastapi import APIRouter, Depends, HTTPException, Query
from ..auth import get_current_user
from ..clients.jellyfin import JellyfinClient
from ..db import (
add_portal_item_activity,
add_portal_comment,
count_portal_items,
create_portal_item,
delete_portal_item,
get_portal_item,
get_portal_overview,
list_portal_comments,
list_portal_item_activity,
list_portal_items,
update_portal_item,
)
from ..services.issue_resolution import (
begin_issue_confirmation,
issue_resolution_state,
respond_to_issue_confirmation,
)
from ..services.notifications import send_portal_notification
from ..runtime import get_runtime_settings
router = APIRouter(prefix="/portal", tags=["portal"], dependencies=[Depends(get_current_user)])
logger = logging.getLogger(__name__)
@@ -45,7 +33,6 @@ PORTAL_STATUSES = {
"done",
"declined",
"closed",
"awaiting_confirmation",
# Seerr-style request pipeline statuses
"pending",
"approved",
@@ -68,10 +55,6 @@ PORTAL_MEDIA_STATUSES = {
PORTAL_ISSUE_TYPES = {
"general",
"playback",
"transcode",
"service_unavailable",
"broken_media",
"audio",
"subtitle",
"quality",
"metadata",
@@ -79,9 +62,6 @@ PORTAL_ISSUE_TYPES = {
"other",
}
_MEDIA_STATUS_CACHE: Dict[str, Any] = {"expires_at": 0.0, "payload": None}
_MEDIA_STATUS_CACHE_SECONDS = 15.0
REQUEST_STATUS_TRANSITIONS: Dict[str, set[str]] = {
"pending": {"pending", "approved", "declined"},
"approved": {"approved", "declined"},
@@ -259,97 +239,6 @@ def _stage_label_for_workflow(request_status: str, media_status: str) -> str:
return "Approved"
ISSUE_WORKFLOW_STAGES = (
("reported", "Reported"),
("review", "Under review"),
("planned", "Fix planned"),
("repair", "Fix underway"),
("confirmation", "Confirm fix"),
("resolved", "Resolved"),
)
ISSUE_STATUS_TO_STAGE: Dict[str, Tuple[int, str, str, str]] = {
"new": (
0,
"Issue received",
"Your report has been logged and is waiting for the support team to review it.",
"active",
),
"triaging": (
1,
"Being investigated",
"The support team is checking the report and identifying the right fix.",
"active",
),
"planned": (
2,
"Fix ready to begin",
"The problem has been reviewed and the next action has been selected.",
"active",
),
"in_progress": (
3,
"Fix in progress",
"Work is underway on the affected content or service.",
"active",
),
"blocked": (
3,
"Fix needs attention",
"Work has paused because the support team needs another service, resource, or decision before continuing.",
"attention",
),
"awaiting_confirmation": (
4,
"Waiting for confirmation",
"A fix has been applied. Magent is waiting for the reporter to confirm that the problem is gone.",
"active",
),
"done": (
5,
"Issue resolved",
"The reported problem has been fixed and the issue is complete.",
"complete",
),
"closed": (
5,
"Issue resolved",
"The reported problem has been fixed and the issue is closed.",
"complete",
),
}
def _issue_workflow_payload(status: Any) -> Dict[str, Any]:
normalized_status = str(status or "new").strip().lower()
stage_index, headline, message, state = ISSUE_STATUS_TO_STAGE.get(
normalized_status,
ISSUE_STATUS_TO_STAGE["new"],
)
steps = []
for index, (key, label) in enumerate(ISSUE_WORKFLOW_STAGES):
step_state = (
"complete"
if index < stage_index or (index == stage_index and state == "complete")
else "active"
if index == stage_index
else "waiting"
)
if index == stage_index and state == "attention":
step_state = "attention"
steps.append({"key": key, "label": label, "state": step_state})
return {
"current_step": stage_index + 1,
"total_steps": len(ISSUE_WORKFLOW_STAGES),
"stage": ISSUE_WORKFLOW_STAGES[stage_index][0],
"stage_label": ISSUE_WORKFLOW_STAGES[stage_index][1],
"headline": headline,
"message": message,
"state": state,
"steps": steps,
}
def _normalize_request_pipeline(
request_status: Optional[str],
media_status: Optional[str],
@@ -450,36 +339,6 @@ def _is_owner(user: Dict[str, Any], item: Dict[str, Any]) -> bool:
return str(user.get("username") or "") == str(item.get("created_by_username") or "")
def _public_media_status_payload(
*,
status: str,
headline: str,
message: str,
latency_ms: Optional[int] = None,
version: Optional[str] = None,
restart_pending: Optional[bool] = None,
active_streams: Optional[int] = None,
transcoding_streams: Optional[int] = None,
session_check_available: bool = False,
) -> Dict[str, Any]:
return {
"checked_at": datetime.now(timezone.utc).isoformat(),
"status": status,
"headline": headline,
"message": message,
"latency_ms": latency_ms,
"server": {
"version": version,
"restart_pending": restart_pending,
},
"activity": {
"active_streams": active_streams,
"transcoding_streams": transcoding_streams,
"available": session_check_available,
},
}
def _serialize_item(item: Dict[str, Any], user: Dict[str, Any]) -> Dict[str, Any]:
is_admin = _is_admin(user)
is_owner = _is_owner(user, item)
@@ -488,13 +347,7 @@ def _serialize_item(item: Dict[str, Any], user: Dict[str, Any]) -> Dict[str, Any
"can_edit": is_admin or is_owner,
"can_comment": True,
"can_moderate": is_admin,
"can_delete": is_admin and str(item.get("kind") or "").lower() == "issue",
"can_raise_issue": str(item.get("kind") or "") == "request",
"can_confirm_resolution": (
str(item.get("kind") or "").lower() == "issue"
and str(item.get("status") or "").lower() == "awaiting_confirmation"
and (is_admin or is_owner)
),
}
kind = str(item.get("kind") or "").strip().lower()
if kind == "request":
@@ -506,85 +359,15 @@ def _serialize_item(item: Dict[str, Any], user: Dict[str, Any]) -> Dict[str, Any
"is_terminal": media_status in {"available", "failed"} or request_status == "declined",
}
elif kind == "issue":
resolution = issue_resolution_state(item)
serialized["issue"] = {
"issue_type": _clean_text(item.get("issue_type")) or "general",
"related_item_id": _normalize_int(item.get("related_item_id"), "related_item_id"),
"is_resolved": bool(_clean_text(item.get("issue_resolved_at"))),
"resolved_at": _clean_text(item.get("issue_resolved_at")),
"workflow": _issue_workflow_payload(item.get("status")),
"confirmation": {
"status": resolution.get("status"),
"attempts_sent": int(resolution.get("attemptsSent") or 0),
"maximum_attempts": int(resolution.get("maximumAttempts") or 0),
"last_contact_at": resolution.get("lastContactAt"),
"next_contact_at": resolution.get("nextContactAt"),
"interval_value": resolution.get("intervalValue"),
"interval_unit": resolution.get("intervalUnit"),
"last_delivery_succeeded": resolution.get("lastDeliverySucceeded"),
},
}
return serialized
def _activity_payload(item: Dict[str, Any], *, include_internal: bool = False) -> list[Dict[str, Any]]:
activity = [
entry
for entry in list_portal_item_activity(int(item["id"]), limit=300)
if include_internal or entry.get("event_type") != "internal_note_added"
]
if not any(entry.get("event_type") == "item_created" for entry in activity):
activity.insert(
0,
{
"id": f"created-{item['id']}",
"item_id": item["id"],
"event_type": "item_created",
"actor_username": item.get("created_by_username") or "unknown",
"actor_role": "user",
"message": (
"Issue raised and added to the support queue."
if str(item.get("kind") or "").lower() == "issue"
else "Portal item created."
),
"metadata_json": None,
"created_at": item.get("created_at"),
},
)
if include_internal:
return activity
public_activity: list[Dict[str, Any]] = []
for entry in activity:
public_entry = {key: value for key, value in entry.items() if key != "metadata_json"}
actor_role = str(entry.get("actor_role") or "user").lower()
public_entry["actor_username"] = (
"Magent"
if actor_role == "system"
else "Support team"
if actor_role == "admin"
else "Reporter"
)
public_entry["actor_role"] = "system" if actor_role == "system" else "support" if actor_role == "admin" else "user"
public_activity.append(public_entry)
return public_activity
def _record_activity(
item_id: int,
*,
event_type: str,
message: str,
user: Dict[str, Any],
) -> None:
add_portal_item_activity(
item_id,
event_type=event_type,
actor_username=str(user.get("username") or "unknown"),
actor_role=str(user.get("role") or "user"),
message=message,
)
async def _notify(
*,
event_type: str,
@@ -623,122 +406,6 @@ async def portal_overview(current_user: Dict[str, Any] = Depends(get_current_use
}
@router.get("/issues/media-status")
async def portal_media_status() -> Dict[str, Any]:
"""Return a short, privacy-safe Jellyfin health check for guided issue reporting."""
now = time.monotonic()
cached_payload = _MEDIA_STATUS_CACHE.get("payload")
if isinstance(cached_payload, dict) and now < float(_MEDIA_STATUS_CACHE.get("expires_at") or 0):
return cached_payload
runtime = get_runtime_settings()
jellyfin = JellyfinClient(runtime.jellyfin_base_url, runtime.jellyfin_api_key)
if not jellyfin.configured():
payload = _public_media_status_payload(
status="not_configured",
headline="Media server status is unavailable",
message="Magent cannot run a playback check right now. Your report can still be submitted.",
)
_MEDIA_STATUS_CACHE.update(
expires_at=now + _MEDIA_STATUS_CACHE_SECONDS,
payload=payload,
)
return payload
started_at = time.perf_counter()
try:
system_info = await jellyfin.get_system_info()
except (httpx.HTTPError, RuntimeError, ValueError):
latency_ms = round((time.perf_counter() - started_at) * 1000)
payload = _public_media_status_payload(
status="down",
headline="The media server is not responding",
message=(
"This looks broader than one title. The report will include the failed server check "
"so an administrator can investigate the service first."
),
latency_ms=latency_ms,
)
_MEDIA_STATUS_CACHE.update(
expires_at=now + _MEDIA_STATUS_CACHE_SECONDS,
payload=payload,
)
return payload
except Exception:
logger.exception("guided issue Jellyfin system check failed")
latency_ms = round((time.perf_counter() - started_at) * 1000)
payload = _public_media_status_payload(
status="down",
headline="The media server check failed",
message="Your report can still be submitted and will include this failed service check.",
latency_ms=latency_ms,
)
_MEDIA_STATUS_CACHE.update(
expires_at=now + _MEDIA_STATUS_CACHE_SECONDS,
payload=payload,
)
return payload
latency_ms = round((time.perf_counter() - started_at) * 1000)
info = system_info if isinstance(system_info, dict) else {}
version_value = info.get("Version")
version = str(version_value).strip() if version_value is not None else None
restart_pending = bool(info.get("HasPendingRestart"))
session_check_available = False
active_streams: Optional[int] = None
transcoding_streams: Optional[int] = None
try:
sessions = await jellyfin.get_sessions()
if isinstance(sessions, list):
session_check_available = True
active_streams = sum(
1 for session in sessions if isinstance(session, dict) and session.get("NowPlayingItem")
)
transcoding_streams = sum(
1
for session in sessions
if isinstance(session, dict)
and session.get("NowPlayingItem")
and session.get("TranscodingInfo")
)
except Exception:
logger.warning("guided issue Jellyfin session check unavailable", exc_info=True)
if restart_pending:
status = "degraded"
headline = "Media server is online but needs attention"
message = "Jellyfin is responding, but it reports that a restart is pending."
elif session_check_available and active_streams:
status = "up"
headline = "Media server is online and actively streaming"
message = (
"Other playback is currently working, so this is more likely specific to the title, "
"audio track, subtitle, client, or transcode path."
)
else:
status = "up"
headline = "Media server is online"
message = "Jellyfin responded normally. Continue with the report if playback is still failing."
payload = _public_media_status_payload(
status=status,
headline=headline,
message=message,
latency_ms=latency_ms,
version=version,
restart_pending=restart_pending,
active_streams=active_streams,
transcoding_streams=transcoding_streams,
session_check_available=session_check_available,
)
_MEDIA_STATUS_CACHE.update(
expires_at=now + _MEDIA_STATUS_CACHE_SECONDS,
payload=payload,
)
return payload
@router.get("/items")
async def portal_list_items(
kind: Optional[str] = None,
@@ -954,16 +621,6 @@ async def portal_create_item(
priority=priority or "normal",
assignee_username=assignee_username,
)
_record_activity(
int(created["id"]),
event_type="item_created",
message=(
"Issue raised and added to the support queue."
if created.get("kind") == "issue"
else f"{str(created.get('kind') or 'Portal item').capitalize()} created."
),
user=current_user,
)
initial_comment = _clean_text(payload.get("comment"))
if initial_comment:
add_portal_comment(
@@ -983,7 +640,6 @@ async def portal_create_item(
return {
"item": _serialize_item(created, current_user),
"comments": comments,
"activity": _activity_payload(created, include_internal=_is_admin(current_user)),
}
@@ -1036,12 +692,6 @@ async def portal_create_issue_for_request(
priority=priority or "normal",
assignee_username=_clean_text(payload.get("assignee_username")) if _is_admin(current_user) else None,
)
_record_activity(
int(created["id"]),
event_type="item_created",
message=f"Issue raised and linked to collection request #{item_id}.",
user=current_user,
)
initial_comment = _clean_text(payload.get("comment"))
if initial_comment:
add_portal_comment(
@@ -1061,7 +711,6 @@ async def portal_create_issue_for_request(
return {
"item": _serialize_item(created, current_user),
"comments": comments,
"activity": _activity_payload(created, include_internal=_is_admin(current_user)),
"linked_request_id": item_id,
}
@@ -1174,33 +823,9 @@ async def portal_get_item(
return {
"item": _serialize_item(item, current_user),
"comments": comments,
"activity": _activity_payload(item, include_internal=_is_admin(current_user)),
}
@router.delete("/items/{item_id}")
async def portal_delete_item(
item_id: int,
current_user: Dict[str, Any] = Depends(get_current_user),
) -> Dict[str, Any]:
if not _is_admin(current_user):
raise HTTPException(status_code=403, detail="Admin access required")
item = get_portal_item(item_id)
if not item:
raise HTTPException(status_code=404, detail="Portal item not found")
if str(item.get("kind") or "").lower() != "issue":
raise HTTPException(status_code=400, detail="Only issues can be deleted here")
if not delete_portal_item(item_id):
raise HTTPException(status_code=404, detail="Issue not found")
logger.info(
"portal issue deleted id=%s title=%s actor=%s",
item_id,
item.get("title"),
current_user.get("username"),
)
return {"status": "deleted", "item_id": item_id}
@router.patch("/items/{item_id}")
async def portal_update_item(
item_id: int,
@@ -1212,7 +837,6 @@ async def portal_update_item(
raise HTTPException(status_code=404, detail="Portal item not found")
is_admin = _is_admin(current_user)
is_owner = _is_owner(current_user, item)
item_kind = str(item.get("kind") or "").lower()
if not (is_admin or is_owner):
raise HTTPException(status_code=403, detail="Only the owner or admin can edit this item")
@@ -1262,7 +886,7 @@ async def portal_update_item(
if "external_ref" in payload:
updates["external_ref"] = _clean_text(payload.get("external_ref"))
if is_admin:
kind = item_kind
kind = str(item.get("kind") or "").lower()
if "priority" in payload:
updates["priority"] = _normalize_choice(
payload.get("priority"),
@@ -1352,9 +976,9 @@ async def portal_update_item(
updates["issue_resolved_at"] = _clean_text(payload.get("issue_resolved_at"))
if "status" in payload:
next_status = str(updates.get("status") or item.get("status") or "").lower()
if next_status == "closed":
if next_status in {"done", "closed"}:
updates.setdefault("issue_resolved_at", datetime.now(timezone.utc).isoformat())
elif next_status in {"new", "triaging", "planned", "in_progress", "blocked", "done", "awaiting_confirmation"}:
elif next_status in {"new", "triaging", "planned", "in_progress", "blocked"}:
updates.setdefault("issue_resolved_at", None)
if not updates:
@@ -1362,47 +986,14 @@ async def portal_update_item(
return {
"item": _serialize_item(item, current_user),
"comments": comments,
"activity": _activity_payload(item, include_internal=is_admin),
}
updated = update_portal_item(item_id, **updates)
if not updated:
raise HTTPException(status_code=404, detail="Portal item not found")
requested_issue_status = str(updates.get("status") or "").lower()
should_start_confirmation = item_kind == "issue" and (
(requested_issue_status == "done" and str(item.get("status") or "").lower() != "done")
or (
requested_issue_status == "awaiting_confirmation"
and str(item.get("status") or "").lower() != "awaiting_confirmation"
)
)
if should_start_confirmation:
try:
updated = await begin_issue_confirmation(
item_id,
actor_username=str(current_user.get("username") or "unknown"),
actor_role=str(current_user.get("role") or "admin"),
)
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
changed_fields = [key for key in updates.keys() if item.get(key) != updated.get(key)]
if changed_fields:
if item_kind == "issue" and not should_start_confirmation:
old_status = str(item.get("status") or "unknown").replace("_", " ")
new_status = str(updated.get("status") or "unknown").replace("_", " ")
activity_message = (
f"Status changed from {old_status} to {new_status}."
if item.get("status") != updated.get("status")
else f"Issue details updated: {', '.join(sorted(changed_fields))}."
)
_record_activity(
item_id,
event_type="status_changed" if item.get("status") != updated.get("status") else "issue_updated",
message=activity_message,
user=current_user,
)
await _notify(
event_type="portal_item_updated",
item=updated,
@@ -1413,42 +1004,6 @@ async def portal_update_item(
return {
"item": _serialize_item(updated, current_user),
"comments": comments,
"activity": _activity_payload(updated, include_internal=is_admin),
}
@router.post("/issues/{item_id}/resolution-response")
async def portal_issue_resolution_response(
item_id: int,
payload: Dict[str, Any],
current_user: Dict[str, Any] = Depends(get_current_user),
) -> Dict[str, Any]:
item = get_portal_item(item_id)
if not item or str(item.get("kind") or "").lower() != "issue":
raise HTTPException(status_code=404, detail="Issue not found")
if not (_is_admin(current_user) or _is_owner(current_user, item)):
raise HTTPException(status_code=403, detail="Only the reporter or an admin can confirm this resolution")
if not isinstance(payload.get("resolved"), bool):
raise HTTPException(status_code=400, detail="resolved must be true or false")
try:
updated = respond_to_issue_confirmation(
item_id,
resolved=payload["resolved"],
actor_username=str(current_user.get("username") or "unknown"),
actor_role=str(current_user.get("role") or "user"),
)
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
await _notify(
event_type="portal_issue_resolution_confirmed" if payload["resolved"] else "portal_issue_resolution_rejected",
item=updated,
user=current_user,
note="resolved=true" if payload["resolved"] else "resolved=false",
)
return {
"item": _serialize_item(updated, current_user),
"comments": list_portal_comments(item_id, include_internal=_is_admin(current_user)),
"activity": _activity_payload(updated, include_internal=_is_admin(current_user)),
}
@@ -1490,17 +1045,6 @@ async def portal_create_comment(
message=message,
is_internal=is_internal,
)
if str(item.get("kind") or "").lower() == "issue":
_record_activity(
item_id,
event_type="internal_note_added" if is_internal else "comment_added",
message=(
f"Internal troubleshooting note: {message[:240]}"
if is_internal
else f"Support update: {message[:240]}"
),
user=current_user,
)
updated_item = get_portal_item(item_id)
if updated_item:
await _notify(
File diff suppressed because it is too large Load Diff
-3
View File
@@ -30,9 +30,6 @@ def _build_site_info(include_changelog: bool) -> Dict[str, Any]:
"showForgotPassword": bool(runtime.site_login_show_forgot_password),
"showSignupLink": bool(runtime.site_login_show_signup_link),
},
"navigation": {
"showRequests": bool(runtime.site_nav_show_requests),
},
}
if include_changelog:
info["changelog"] = (CHANGELOG or "").strip()
+2 -17
View File
@@ -2,17 +2,16 @@ from typing import Any, Dict
import httpx
from fastapi import APIRouter, Depends, HTTPException
from ..auth import require_admin
from ..auth import get_current_user
from ..runtime import get_runtime_settings
from ..clients.jellyseerr import JellyseerrClient
from ..clients.sonarr import SonarrClient
from ..clients.radarr import RadarrClient
from ..clients.bazarr import BazarrClient
from ..clients.prowlarr import ProwlarrClient
from ..clients.qbittorrent import QBittorrentClient
from ..clients.jellyfin import JellyfinClient
router = APIRouter(prefix="/status", tags=["status"], dependencies=[Depends(require_admin)])
router = APIRouter(prefix="/status", tags=["status"], dependencies=[Depends(get_current_user)])
async def _check(name: str, configured: bool, func) -> Dict[str, Any]:
@@ -62,7 +61,6 @@ async def services_status() -> Dict[str, Any]:
jellyseerr = JellyseerrClient(runtime.jellyseerr_base_url, runtime.jellyseerr_api_key)
sonarr = SonarrClient(runtime.sonarr_base_url, runtime.sonarr_api_key)
radarr = RadarrClient(runtime.radarr_base_url, runtime.radarr_api_key)
bazarr = BazarrClient(runtime.bazarr_base_url, runtime.bazarr_api_key)
prowlarr = ProwlarrClient(runtime.prowlarr_base_url, runtime.prowlarr_api_key)
qbittorrent = QBittorrentClient(
runtime.qbittorrent_base_url, runtime.qbittorrent_username, runtime.qbittorrent_password
@@ -91,13 +89,6 @@ async def services_status() -> Dict[str, Any]:
radarr.get_system_status,
)
)
services.append(
await _check(
"Bazarr",
bazarr.configured() and bool(runtime.bazarr_api_key),
bazarr.get_system_status,
)
)
prowlarr_status = await _check(
"Prowlarr",
prowlarr.configured(),
@@ -133,7 +124,6 @@ async def test_service(service: str) -> Dict[str, Any]:
jellyseerr = JellyseerrClient(runtime.jellyseerr_base_url, runtime.jellyseerr_api_key)
sonarr = SonarrClient(runtime.sonarr_base_url, runtime.sonarr_api_key)
radarr = RadarrClient(runtime.radarr_base_url, runtime.radarr_api_key)
bazarr = BazarrClient(runtime.bazarr_base_url, runtime.bazarr_api_key)
prowlarr = ProwlarrClient(runtime.prowlarr_base_url, runtime.prowlarr_api_key)
qbittorrent = QBittorrentClient(
runtime.qbittorrent_base_url, runtime.qbittorrent_username, runtime.qbittorrent_password
@@ -154,11 +144,6 @@ async def test_service(service: str) -> Dict[str, Any]:
),
"sonarr": ("Sonarr", sonarr.configured(), sonarr.get_system_status),
"radarr": ("Radarr", radarr.configured(), radarr.get_system_status),
"bazarr": (
"Bazarr",
bazarr.configured() and bool(runtime.bazarr_api_key),
bazarr.get_system_status,
),
"prowlarr": ("Prowlarr", prowlarr.configured(), prowlarr.get_health),
"jellyfin": ("Jellyfin", jellyfin.configured(), jellyfin.get_system_info),
}
-3
View File
@@ -19,8 +19,6 @@ _INT_FIELDS = {
"requests_poll_interval_seconds",
"requests_delta_sync_interval_minutes",
"requests_cleanup_days",
"issue_confirmation_contact_attempts",
"issue_confirmation_interval_value",
"magent_notify_email_smtp_port",
}
_BOOL_FIELDS = {
@@ -41,7 +39,6 @@ _BOOL_FIELDS = {
"site_login_show_local_login",
"site_login_show_forgot_password",
"site_login_show_signup_link",
"site_nav_show_requests",
}
_SKIP_OVERRIDE_FIELDS = {"site_build_number", "site_changelog"}
-378
View File
@@ -1,378 +0,0 @@
from __future__ import annotations
import asyncio
from datetime import datetime, timedelta, timezone
from html import escape
import json
import logging
from typing import Any, Dict, Optional
from ..config import settings as env_settings
from ..db import (
add_portal_item_activity,
get_portal_item,
get_user_by_username,
list_portal_items,
update_portal_item,
)
from ..runtime import get_runtime_settings
from .invite_email import resolve_user_delivery_email, send_generic_email
logger = logging.getLogger(__name__)
_SYSTEM_USER = "Magent"
def _now() -> datetime:
return datetime.now(timezone.utc)
def _parse_datetime(value: Any) -> Optional[datetime]:
if not isinstance(value, str) or not value.strip():
return None
try:
parsed = datetime.fromisoformat(value.strip().replace("Z", "+00:00"))
except ValueError:
return None
return parsed.replace(tzinfo=parsed.tzinfo or timezone.utc).astimezone(timezone.utc)
def _metadata(item: Dict[str, Any]) -> Dict[str, Any]:
raw = item.get("metadata_json")
if not isinstance(raw, str) or not raw.strip():
return {}
try:
parsed = json.loads(raw)
except (TypeError, ValueError):
return {}
return parsed if isinstance(parsed, dict) else {}
def issue_resolution_state(item: Dict[str, Any]) -> Dict[str, Any]:
state = _metadata(item).get("resolutionConfirmation")
return dict(state) if isinstance(state, dict) else {}
def _metadata_with_resolution(item: Dict[str, Any], state: Dict[str, Any]) -> str:
metadata = _metadata(item)
metadata["resolutionConfirmation"] = state
return json.dumps(metadata, separators=(",", ":"), sort_keys=True)
def _interval_delta(value: int, unit: str) -> timedelta:
safe_value = max(1, min(int(value), 365))
normalized_unit = str(unit or "days").strip().lower()
if normalized_unit == "weeks":
return timedelta(weeks=safe_value)
if normalized_unit == "months":
return timedelta(days=30 * safe_value)
return timedelta(days=safe_value)
def _workflow_settings() -> tuple[int, int, str]:
runtime = get_runtime_settings()
attempts = max(0, min(int(runtime.issue_confirmation_contact_attempts or 0), 10))
interval_value = max(1, min(int(runtime.issue_confirmation_interval_value or 1), 365))
interval_unit = str(runtime.issue_confirmation_interval_unit or "days").strip().lower()
if interval_unit not in {"days", "weeks", "months"}:
interval_unit = "days"
return attempts, interval_value, interval_unit
def _app_url() -> str:
runtime = get_runtime_settings()
for value in (runtime.magent_application_url, runtime.magent_proxy_base_url, env_settings.cors_allow_origin):
candidate = str(value or "").strip()
if candidate:
return candidate.rstrip("/")
return f"http://localhost:{int(runtime.magent_application_port or 3000)}"
def _issue_url(item_id: int) -> str:
return f"{_app_url()}/portal/issues?item={item_id}"
def _activity(
item_id: int,
event_type: str,
message: str,
*,
actor_username: str = _SYSTEM_USER,
actor_role: str = "system",
metadata: Optional[Dict[str, Any]] = None,
) -> None:
add_portal_item_activity(
item_id,
event_type=event_type,
actor_username=actor_username,
actor_role=actor_role,
message=message,
metadata_json=json.dumps(metadata, separators=(",", ":"), sort_keys=True) if metadata else None,
)
def _close_issue(
item: Dict[str, Any],
*,
reason: str,
confirmed: bool,
actor_username: str = _SYSTEM_USER,
actor_role: str = "system",
) -> Dict[str, Any]:
now = _now().isoformat()
state = issue_resolution_state(item)
state.update(
{
"status": "confirmed" if confirmed else "auto_closed",
"confirmedAt": now if confirmed else state.get("confirmedAt"),
"closedAt": now,
"nextContactAt": None,
"closedReason": reason,
}
)
updated = update_portal_item(
int(item["id"]),
status="closed",
issue_resolved_at=now,
metadata_json=_metadata_with_resolution(item, state),
)
if not updated:
raise RuntimeError("Issue could not be closed")
_activity(
int(item["id"]),
"resolution_confirmed" if confirmed else "issue_auto_closed",
reason,
actor_username=actor_username,
actor_role=actor_role,
)
return updated
async def _contact_reporter(item: Dict[str, Any]) -> Dict[str, Any]:
maximum, interval_value, interval_unit = _workflow_settings()
state = issue_resolution_state(item)
attempts = max(0, int(state.get("attemptsSent") or 0))
if maximum <= 0:
return _close_issue(
item,
reason="Issue closed automatically because reporter confirmation emails are disabled.",
confirmed=False,
)
if attempts >= maximum:
return _close_issue(
item,
reason=f"Issue closed automatically after {attempts} confirmation email attempt(s) without a response.",
confirmed=False,
)
attempt_number = attempts + 1
reporter = get_user_by_username(str(item.get("created_by_username") or ""))
recipient = resolve_user_delivery_email(reporter)
issue_url = _issue_url(int(item["id"]))
sent = False
delivery_error: Optional[str] = None
if recipient:
subject = f"Is your issue fixed? #{item['id']} {item.get('title') or ''}".strip()
body_text = (
f"We have marked issue #{item['id']} as fixed and need your confirmation.\n\n"
f"Issue: {item.get('title') or 'Untitled issue'}\n"
f"Confirmation request: {attempt_number} of {maximum}\n\n"
f"Open the issue and choose whether it is fixed or still happening:\n{issue_url}\n\n"
"If you do not respond, Magent will close the issue automatically after the configured confirmation period."
)
body_html = (
'<div style="font-family:Segoe UI,Arial,sans-serif;color:#132033;">'
'<h2 style="margin:0 0 12px;">Is your issue fixed?</h2>'
f'<p style="line-height:1.6;">We have marked issue <strong>#{int(item["id"])}</strong> as fixed and need your confirmation.</p>'
f'<p style="line-height:1.6;"><strong>{escape(str(item.get("title") or "Untitled issue"))}</strong><br>'
f'Confirmation request {attempt_number} of {maximum}</p>'
f'<a href="{escape(issue_url)}" style="display:inline-block;padding:11px 18px;border-radius:8px;background:#1c6bff;color:#fff;text-decoration:none;font-weight:700;">Confirm the outcome</a>'
'<p style="margin-top:18px;color:#64748b;line-height:1.6;">If you do not respond, Magent will close the issue automatically after the configured confirmation period.</p>'
'</div>'
)
try:
await send_generic_email(
recipient_email=recipient,
subject=subject,
body_text=body_text,
body_html=body_html,
)
sent = True
except Exception as exc:
delivery_error = str(exc)
logger.exception("issue confirmation email failed item_id=%s attempt=%s", item.get("id"), attempt_number)
else:
delivery_error = "No email address is stored for the reporter."
now = _now()
state.update(
{
"status": "awaiting_confirmation",
"attemptsSent": attempt_number,
"maximumAttempts": maximum,
"lastContactAt": now.isoformat(),
"nextContactAt": (now + _interval_delta(interval_value, interval_unit)).isoformat(),
"intervalValue": interval_value,
"intervalUnit": interval_unit,
"lastDeliverySucceeded": sent,
"lastDeliveryError": delivery_error,
}
)
updated = update_portal_item(
int(item["id"]),
metadata_json=_metadata_with_resolution(item, state),
)
if not updated:
raise RuntimeError("Issue confirmation schedule could not be saved")
if sent:
message = f"Confirmation email {attempt_number} of {maximum} was sent to the reporter."
else:
message = f"Confirmation email {attempt_number} of {maximum} could not be delivered."
_activity(
int(item["id"]),
"confirmation_email_sent" if sent else "confirmation_email_failed",
message,
metadata={
"attempt": attempt_number,
"maximum": maximum,
"nextContactAt": state["nextContactAt"],
"deliveryError": delivery_error,
},
)
return updated
async def begin_issue_confirmation(
item_id: int,
*,
actor_username: str,
actor_role: str,
) -> Dict[str, Any]:
item = get_portal_item(item_id)
if not item or str(item.get("kind") or "").lower() != "issue":
raise ValueError("Issue not found")
now = _now().isoformat()
maximum, interval_value, interval_unit = _workflow_settings()
state = {
"status": "awaiting_confirmation",
"startedAt": now,
"attemptsSent": 0,
"maximumAttempts": maximum,
"lastContactAt": None,
"nextContactAt": now,
"intervalValue": interval_value,
"intervalUnit": interval_unit,
"confirmedAt": None,
"closedAt": None,
}
updated = update_portal_item(
item_id,
status="awaiting_confirmation",
issue_resolved_at=None,
metadata_json=_metadata_with_resolution(item, state),
)
if not updated:
raise RuntimeError("Issue confirmation workflow could not be started")
_activity(
item_id,
"resolution_proposed",
"The issue was marked fixed and sent to the reporter for confirmation.",
actor_username=actor_username,
actor_role=actor_role,
metadata={"maximumAttempts": maximum, "intervalValue": interval_value, "intervalUnit": interval_unit},
)
return await _contact_reporter(updated)
def respond_to_issue_confirmation(
item_id: int,
*,
resolved: bool,
actor_username: str,
actor_role: str,
) -> Dict[str, Any]:
item = get_portal_item(item_id)
if not item or str(item.get("kind") or "").lower() != "issue":
raise ValueError("Issue not found")
if str(item.get("status") or "").lower() != "awaiting_confirmation":
raise ValueError("This issue is not waiting for resolution confirmation")
if resolved:
return _close_issue(
item,
reason="The reporter confirmed that the issue is fixed.",
confirmed=True,
actor_username=actor_username,
actor_role=actor_role,
)
now = _now().isoformat()
state = issue_resolution_state(item)
state.update(
{
"status": "reported_still_broken",
"reporterResponseAt": now,
"nextContactAt": None,
"closedAt": None,
}
)
updated = update_portal_item(
item_id,
status="in_progress",
issue_resolved_at=None,
metadata_json=_metadata_with_resolution(item, state),
)
if not updated:
raise RuntimeError("Issue could not be reopened")
_activity(
item_id,
"resolution_rejected",
"The reporter said the issue is still happening. The issue was returned to In progress.",
actor_username=actor_username,
actor_role=actor_role,
)
return updated
async def process_due_issue_confirmations(now: Optional[datetime] = None) -> Dict[str, int]:
current = (now or _now()).astimezone(timezone.utc)
items = list_portal_items(kind="issue", status="awaiting_confirmation", limit=500)
result = {"checked": len(items), "contacted": 0, "closed": 0, "failed": 0}
maximum, _, _ = _workflow_settings()
for item in items:
state = issue_resolution_state(item)
due_at = _parse_datetime(state.get("nextContactAt"))
if due_at and due_at > current:
continue
try:
attempts = max(0, int(state.get("attemptsSent") or 0))
if maximum <= 0 or attempts >= maximum:
_close_issue(
item,
reason=(
"Issue closed automatically because reporter confirmation emails are disabled."
if maximum <= 0
else f"Issue closed automatically after {attempts} confirmation email attempt(s) without a response."
),
confirmed=False,
)
result["closed"] += 1
else:
await _contact_reporter(item)
result["contacted"] += 1
except Exception:
result["failed"] += 1
logger.exception("issue confirmation processing failed item_id=%s", item.get("id"))
return result
async def run_issue_confirmation_loop() -> None:
while True:
try:
result = await process_due_issue_confirmations()
if result["contacted"] or result["closed"] or result["failed"]:
logger.info("issue confirmation sweep complete result=%s", result)
except asyncio.CancelledError:
raise
except Exception:
logger.exception("issue confirmation sweep failed")
await asyncio.sleep(15 * 60)
-206
View File
@@ -1,206 +0,0 @@
from __future__ import annotations
from contextvars import ContextVar, Token
from copy import deepcopy
from datetime import datetime, timezone
import re
import threading
import time
import uuid
from typing import Any, Dict, Optional
_OPERATION_ID_PATTERN = re.compile(r"^[A-Za-z0-9_-]{8,80}$")
_OPERATION_TTL_SECONDS = 15 * 60
_MAX_OPERATIONS = 500
_MAX_EVENTS = 60
_current_operation_id: ContextVar[Optional[str]] = ContextVar(
"magent_operation_id", default=None
)
_operations: Dict[str, Dict[str, Any]] = {}
_lock = threading.Lock()
def _now_iso() -> str:
return datetime.now(timezone.utc).isoformat()
def normalize_operation_id(value: Optional[str]) -> Optional[str]:
if not isinstance(value, str):
return None
normalized = value.strip()
return normalized if _OPERATION_ID_PATTERN.fullmatch(normalized) else None
def _prune_locked(now_monotonic: float) -> None:
expired = [
operation_id
for operation_id, operation in _operations.items()
if now_monotonic - float(operation.get("updated_monotonic") or 0) > _OPERATION_TTL_SECONDS
]
for operation_id in expired:
_operations.pop(operation_id, None)
if len(_operations) <= _MAX_OPERATIONS:
return
oldest = sorted(
_operations,
key=lambda operation_id: float(_operations[operation_id].get("updated_monotonic") or 0),
)
for operation_id in oldest[: len(_operations) - _MAX_OPERATIONS]:
_operations.pop(operation_id, None)
def begin_operation(operation_id: str, *, label: Optional[str], path: str) -> Token:
now_monotonic = time.monotonic()
now_iso = _now_iso()
normalized_label = str(label or "Requested action").strip()[:120] or "Requested action"
with _lock:
_prune_locked(now_monotonic)
_operations[operation_id] = {
"id": operation_id,
"label": normalized_label,
"path": path,
"status": "running",
"started_at": now_iso,
"updated_at": now_iso,
"updated_monotonic": now_monotonic,
"duration_ms": None,
"events": [
{
"id": uuid.uuid4().hex,
"service": "Magent",
"state": "complete",
"message": "Magent received the action.",
"started_at": now_iso,
"finished_at": now_iso,
"duration_ms": 0,
"status_code": None,
}
],
}
return _current_operation_id.set(operation_id)
def reset_operation(token: Token) -> None:
_current_operation_id.reset(token)
def start_remote_call(service: str, message: Optional[str] = None) -> Optional[str]:
operation_id = _current_operation_id.get()
if not operation_id:
return None
event_id = uuid.uuid4().hex
now_iso = _now_iso()
now_monotonic = time.monotonic()
with _lock:
operation = _operations.get(operation_id)
if not operation:
return None
operation["events"].append(
{
"id": event_id,
"service": service,
"state": "active",
"message": message or f"Contacting {service}",
"started_at": now_iso,
"finished_at": None,
"duration_ms": None,
"status_code": None,
"started_monotonic": now_monotonic,
}
)
operation["events"] = operation["events"][-_MAX_EVENTS:]
operation["updated_at"] = now_iso
operation["updated_monotonic"] = now_monotonic
return event_id
def finish_remote_call(
event_id: Optional[str],
*,
success: bool,
status_code: Optional[int] = None,
message: Optional[str] = None,
) -> None:
operation_id = _current_operation_id.get()
if not operation_id or not event_id:
return
now_iso = _now_iso()
now_monotonic = time.monotonic()
with _lock:
operation = _operations.get(operation_id)
if not operation:
return
event = next(
(candidate for candidate in operation["events"] if candidate.get("id") == event_id),
None,
)
if not event:
return
started_monotonic = float(event.pop("started_monotonic", now_monotonic))
event["state"] = "complete" if success else "error"
event["finished_at"] = now_iso
event["duration_ms"] = round((now_monotonic - started_monotonic) * 1000, 1)
event["status_code"] = status_code
event["message"] = message or (
f"{event['service']} responded successfully."
if success
else f"{event['service']} returned an error."
)
operation["updated_at"] = now_iso
operation["updated_monotonic"] = now_monotonic
def finish_operation(operation_id: str, *, success: bool, status_code: Optional[int]) -> None:
now_iso = _now_iso()
now_monotonic = time.monotonic()
with _lock:
operation = _operations.get(operation_id)
if not operation:
return
for event in operation["events"]:
if event.get("state") == "active":
started_monotonic = float(event.pop("started_monotonic", now_monotonic))
event["state"] = "error"
event["finished_at"] = now_iso
event["duration_ms"] = round((now_monotonic - started_monotonic) * 1000, 1)
event["message"] = f"{event.get('service') or 'Remote service'} did not complete."
started = datetime.fromisoformat(str(operation["started_at"]))
duration_ms = (datetime.now(timezone.utc) - started).total_seconds() * 1000
operation["status"] = "complete" if success else "error"
operation["status_code"] = status_code
operation["duration_ms"] = round(duration_ms, 1)
operation["updated_at"] = now_iso
operation["updated_monotonic"] = now_monotonic
operation["events"].append(
{
"id": uuid.uuid4().hex,
"service": "Magent",
"state": "complete" if success else "error",
"message": (
"Magent finished processing the action."
if success
else "Magent could not complete the action."
),
"started_at": now_iso,
"finished_at": now_iso,
"duration_ms": 0,
"status_code": status_code,
}
)
operation["events"] = operation["events"][-_MAX_EVENTS:]
def get_operation(operation_id: str) -> Optional[Dict[str, Any]]:
normalized = normalize_operation_id(operation_id)
if not normalized:
return None
with _lock:
operation = _operations.get(normalized)
if not operation:
return None
result = deepcopy(operation)
result.pop("updated_monotonic", None)
for event in result.get("events", []):
event.pop("started_monotonic", None)
return result
+38 -744
View File
@@ -15,10 +15,8 @@ from ..clients.qbittorrent import QBittorrentClient
from ..runtime import get_runtime_settings
from ..db import (
save_snapshot,
get_recent_actions,
get_request_cache_payload,
get_request_cache_by_id,
get_request_download_evidence,
get_recent_snapshots,
get_setting,
set_setting,
@@ -32,8 +30,6 @@ logger = logging.getLogger(__name__)
JELLYFIN_SCAN_COOLDOWN_SECONDS = 300
_jellyfin_scan_key = "jellyfin_scan_last_at"
REPAIR_ACTIVITY_MAX_AGE = 7 * 24 * 60 * 60
REPAIR_ACTION_IDS = {"replace_media", "search_missing", "repair_subtitles"}
STATUS_LABELS = {
@@ -62,22 +58,6 @@ def _pick_first(value: Any) -> Optional[Dict[str, Any]]:
return None
def _apply_arr_identity(snapshot: Snapshot, arr_item: Any) -> None:
"""Use the collector's authoritative identity when cached Seerr metadata is sparse."""
if not isinstance(arr_item, dict):
return
if snapshot.title in {None, "", "Unknown"}:
title = arr_item.get("title") or arr_item.get("seriesTitle")
if isinstance(title, str) and title.strip():
snapshot.title = title.strip()
if not snapshot.year:
year = arr_item.get("year")
try:
snapshot.year = int(year) if year else snapshot.year
except (TypeError, ValueError):
pass
def _normalize_media_title(value: Any) -> Optional[str]:
if not isinstance(value, str):
return None
@@ -226,20 +206,7 @@ async def _get_seerr_media_details(
async def _maybe_refresh_jellyfin(snapshot: Snapshot) -> None:
collector_item = snapshot.raw.get("arr", {}).get("item") if isinstance(snapshot.raw, dict) else None
collector_stats = collector_item.get("statistics") if isinstance(collector_item, dict) else None
collector_has_file = bool(
isinstance(collector_item, dict)
and (
collector_item.get("hasFile")
or snapshot.request_type == RequestType.tv
and isinstance(collector_stats, dict)
and collector_stats.get("episodeFileCount")
)
)
if snapshot.state not in {NormalizedState.available, NormalizedState.completed} and not (
snapshot.state == NormalizedState.importing and collector_has_file
):
if snapshot.state not in {NormalizedState.available, NormalizedState.completed}:
return
runtime = get_runtime_settings()
client = JellyfinClient(runtime.jellyfin_base_url, runtime.jellyfin_api_key)
@@ -255,9 +222,8 @@ async def _maybe_refresh_jellyfin(snapshot: Snapshot) -> None:
pass
previous = await asyncio.to_thread(get_recent_snapshots, snapshot.request_id, 1)
if previous:
previous_payload = previous[0].get("payload") or {}
previous_jellyfin = (previous_payload.get("raw") or {}).get("jellyfin") or {}
if previous_jellyfin.get("found"):
prev_state = previous[0].get("state")
if prev_state in {NormalizedState.available.value, NormalizedState.completed.value}:
return
try:
await client.refresh_library()
@@ -334,43 +300,6 @@ def _missing_episode_numbers_by_season(episodes: Any) -> Dict[int, List[int]]:
return grouped
def _episode_availability(episodes: Any) -> Dict[str, Any]:
if not isinstance(episodes, list):
return {"available": 0, "missing": 0, "total": 0, "seasons": []}
now = datetime.now(timezone.utc)
season_rows: Dict[int, Dict[str, Any]] = {}
for episode in episodes:
if not isinstance(episode, dict) or not episode.get("monitored", True):
continue
air_date = episode.get("airDateUtc")
if isinstance(air_date, str):
try:
aired_at = datetime.fromisoformat(air_date.replace("Z", "+00:00"))
except ValueError:
aired_at = None
if aired_at and aired_at > now:
continue
season_number = episode.get("seasonNumber")
if not isinstance(season_number, int):
continue
row = season_rows.setdefault(
season_number,
{"seasonNumber": season_number, "available": 0, "missing": 0, "total": 0},
)
row["total"] += 1
if episode.get("hasFile"):
row["available"] += 1
else:
row["missing"] += 1
seasons = [season_rows[key] for key in sorted(season_rows)]
return {
"available": sum(int(row["available"]) for row in seasons),
"missing": sum(int(row["missing"]) for row in seasons),
"total": sum(int(row["total"]) for row in seasons),
"seasons": seasons,
}
def _summarize_qbit(torrents: List[Dict[str, Any]]) -> Dict[str, Any]:
if not torrents:
return {"state": "idle", "message": "0 active downloads."}
@@ -415,546 +344,6 @@ def _artwork_url(path: Optional[str], size: str, cache_mode: str) -> Optional[st
return f"https://image.tmdb.org/t/p/{size}{path}"
def _torrent_progress(torrent: Dict[str, Any]) -> Optional[float]:
progress = torrent.get("progress")
try:
numeric = float(progress)
except (TypeError, ValueError):
numeric = -1
if 0 <= numeric <= 1:
return round(numeric * 100, 1)
try:
size = float(torrent.get("size"))
amount_left = float(torrent.get("amount_left"))
except (TypeError, ValueError):
return None
if size <= 0:
return None
return max(0.0, min(100.0, round(((size - amount_left) / size) * 100, 1)))
def _parse_action_time(value: Any) -> Optional[datetime]:
if not isinstance(value, str) or not value.strip():
return None
try:
parsed = datetime.fromisoformat(value.strip().replace("Z", "+00:00"))
except ValueError:
return None
if parsed.tzinfo is None:
parsed = parsed.replace(tzinfo=timezone.utc)
return parsed.astimezone(timezone.utc)
def _latest_repair_action(request_id: str, *, now: Optional[datetime] = None) -> Optional[Dict[str, Any]]:
current_time = (now or datetime.now(timezone.utc)).astimezone(timezone.utc)
for action in get_recent_actions(request_id, 25):
if action.get("action_id") not in REPAIR_ACTION_IDS:
continue
created_at = _parse_action_time(action.get("created_at"))
if created_at is None:
continue
age_seconds = (current_time - created_at).total_seconds()
if 0 <= age_seconds <= REPAIR_ACTIVITY_MAX_AGE:
return action
return None
def _build_repair_activity(
snapshot: Snapshot,
*,
action: Optional[Dict[str, Any]],
arr_state: str,
arr_details: Dict[str, Any],
download: Dict[str, Any],
jellyfin_found: bool,
) -> Optional[Dict[str, Any]]:
if not action:
return None
action_id = str(action.get("action_id") or "")
collector = (
"Bazarr"
if action_id == "repair_subtitles"
else ("Sonarr" if snapshot.request_type == RequestType.tv else "Radarr")
)
action_ok = str(action.get("status") or "").lower() == "ok"
action_message = str(action.get("message") or "The repair action was recorded.")
download_state = str(download.get("state") or "not_started")
download_visible = bool(download.get("visible"))
availability = arr_details.get("availability")
if not isinstance(availability, dict):
availability = {}
missing = int(availability.get("missing") or 0)
total = int(availability.get("total") or 0)
collection_complete = arr_state == "available" and (
snapshot.request_type == RequestType.movie or (total > 0 and missing == 0)
)
submitted_step = {
"id": "submitted",
"label": "Repair requested",
"state": "complete",
"detail": "Magent recorded the issue and started the selected repair.",
}
if not action_ok:
return {
"visible": True,
"actionId": action_id,
"state": "attention",
"headline": "Repair needs attention",
"message": action_message,
"service": collector,
"updatedAt": action.get("created_at"),
"steps": [
submitted_step,
{
"id": "collector",
"label": f"{collector} hand-off",
"state": "attention",
"detail": action_message,
},
],
}
if action_id == "repair_subtitles":
return {
"visible": True,
"actionId": action_id,
"state": "searching",
"headline": "Subtitle repair is running",
"message": (
f"{action_message} Bazarr is checking the configured subtitle providers; "
"the issue can be confirmed once the replacement track is available."
),
"service": collector,
"updatedAt": action.get("created_at"),
"steps": [
submitted_step,
{
"id": "collector",
"label": "Bazarr accepted the search",
"state": "complete",
"detail": action_message,
},
{
"id": "result",
"label": "Subtitle result",
"state": "active",
"detail": "Waiting for Bazarr to find and apply a suitable subtitle track.",
},
],
}
if collection_complete:
headline = "Repair collected"
message = (
f"{collector} now reports the replacement file as collected. "
+ (
"It is also available in Grizzlyflix."
if jellyfin_found
else "Grizzlyflix is indexing the updated file now."
)
)
state = "complete" if jellyfin_found else "indexing"
download_step_state = "complete"
download_step_detail = f"{collector} reports the replacement file as collected and imported."
available_step_state = "complete" if jellyfin_found else "active"
elif download_visible and download_state in {"downloading", "paused", "completed", "error", "missing"}:
state = {
"downloading": "downloading",
"completed": "importing",
"paused": "attention",
"error": "attention",
"missing": "attention",
}[download_state]
headline = {
"downloading": "Replacement download in progress",
"completed": "Replacement downloaded — waiting for import",
"paused": "Replacement download paused",
"error": "Replacement download cannot be checked",
"missing": "Replacement hand-off needs checking",
}[download_state]
message = {
"downloading": "The replacement is downloading now.",
"paused": "The replacement download is paused and needs attention.",
"completed": f"The download has finished and is waiting for {collector} to import it.",
"error": "Magent cannot currently read the replacement download from qBittorrent.",
"missing": "The collector reported a download, but it is not currently visible in qBittorrent.",
}[download_state]
download_step_state = "active" if download_state == "downloading" else (
"complete" if download_state == "completed" else "attention"
)
download_step_detail = str(
download.get("summary") or "Magent found the replacement download in qBittorrent."
)
available_step_state = "waiting"
else:
state = "searching"
headline = "Replacement search in progress"
message = (
f"{action_message} {collector} has accepted the search, but no replacement download "
"has been selected yet. Magent will keep checking."
)
download_step_state = "waiting"
download_step_detail = "Waiting for a suitable release to be selected."
available_step_state = "waiting"
return {
"visible": True,
"actionId": action_id,
"state": state,
"headline": headline,
"message": message,
"service": collector,
"updatedAt": action.get("created_at"),
"steps": [
submitted_step,
{
"id": "collector",
"label": f"{collector} accepted the search",
"state": "complete",
"detail": action_message,
},
{
"id": "download",
"label": "Replacement download",
"state": download_step_state,
"detail": download_step_detail,
},
{
"id": "available",
"label": "Updated media available",
"state": available_step_state,
"detail": (
"The repaired title is available in Grizzlyflix."
if jellyfin_found and collection_complete
else (
"The media server is indexing the replacement."
if collection_complete
else "Waiting for download and import to finish."
)
),
},
],
}
def _build_presentation(
snapshot: Snapshot,
*,
approved: bool,
arr_state: str,
arr_details: Dict[str, Any],
prowlarr_state: str,
download: Dict[str, Any],
jellyfin_found: bool,
jellyfin_link: Optional[str],
) -> Dict[str, Any]:
collector = "Sonarr" if snapshot.request_type == RequestType.tv else "Radarr"
noun = "episode" if snapshot.request_type == RequestType.tv else "movie"
availability = arr_details.get("availability")
if not isinstance(availability, dict):
availability = {"available": 0, "missing": 0, "total": 0, "seasons": []}
available = int(availability.get("available") or 0)
missing = int(availability.get("missing") or 0)
total = int(availability.get("total") or 0)
partial = available > 0 and missing > 0
jellyfin_partial = bool(
jellyfin_found and snapshot.request_type == RequestType.tv and missing > 0
)
fully_available = bool(jellyfin_found and not jellyfin_partial)
download_visible = bool(download.get("visible"))
download_state = str(download.get("state") or "not_started")
if snapshot.state == NormalizedState.requested:
status_label = "Waiting for approval"
meaning = "This request has been received, but it must be approved before collection can begin."
elif snapshot.state == NormalizedState.needs_add:
status_label = "Approved, but not yet in the library queue"
meaning = (
f"The request was approved, but it has not reached the {collector} collector yet. "
"Adding it to the library queue is the next step."
)
elif jellyfin_partial:
status_label = f"Partially available — {available} of {total} episodes collected"
meaning = (
f"Some of this request is ready to watch. {collector} is still looking for "
f"{missing} missing episode{'s' if missing != 1 else ''}."
)
elif snapshot.state in {NormalizedState.completed, NormalizedState.available}:
status_label = "Available to watch"
meaning = "Collection is complete and the title is available on the media server."
elif download_visible and download_state == "paused":
status_label = "Download paused"
meaning = "A release was collected, but its qBittorrent download is paused and needs to be resumed."
elif download_visible and download_state == "missing":
status_label = "Download attempt is no longer visible"
meaning = (
"A download was previously queued for this request, but qBittorrent no longer reports it. "
"A fresh release search may be required."
)
elif download_visible and download_state == "error":
status_label = "Unable to read the current download"
meaning = (
"A download attempt exists, but Magent cannot currently read its progress from qBittorrent."
)
elif snapshot.state == NormalizedState.downloading:
status_label = "Download in progress"
meaning = "A release has been collected and is currently downloading."
elif snapshot.state == NormalizedState.importing:
if arr_state == "available" and not jellyfin_found:
status_label = "Collected — waiting for the media server"
meaning = (
f"{collector} has collected and imported this title, but it is not visible on "
"the media server yet."
)
else:
status_label = "Downloaded — waiting for library import"
meaning = f"The download has finished and {collector} is preparing it for the media server."
elif arr_state == "error":
status_label = "Unable to read the library queue"
meaning = (
f"The request is approved, but Magent could not read its current state from {collector}. "
"The service may be temporarily unavailable."
)
elif arr_state in {"added", "searching"} and snapshot.request_type == RequestType.tv and total:
if partial:
status_label = f"Partially collected — {missing} episode{'s' if missing != 1 else ''} still missing"
meaning = (
f"The request was approved and sent to {collector}. {available} of {total} aired "
f"episodes have been collected; {missing} still need a matching release."
)
elif missing:
status_label = f"Added to library queue — waiting for {missing} episode{'s' if missing != 1 else ''}"
meaning = (
f"The request was approved and sent to the {collector} collector, but none of the "
f"{total} aired episodes have been collected yet."
)
else:
status_label = "Added to library queue"
meaning = f"The request was approved and sent to the {collector} collector."
elif arr_state in {"added", "searching"}:
status_label = "Added to library queue — waiting for a matching release"
meaning = (
f"The request was approved and sent to the {collector} collector, but a usable release "
"has not been collected yet."
)
elif snapshot.state == NormalizedState.failed:
status_label = "This request needs attention"
meaning = snapshot.state_reason or "Magent could not determine the next stage for this request."
else:
status_label = "Approved — preparing collection" if approved else "Request received"
meaning = snapshot.state_reason or "Magent is checking where this request is in the collection process."
action_ids = [action.id for action in snapshot.actions]
if fully_available:
next_title = "Ready to watch"
next_description = "Collection is complete. Open the title on the media server when you are ready."
recommended = []
elif "resume_torrent" in action_ids:
next_title = "Resume the interrupted download"
next_description = "The download exists but is not currently progressing. Resume it to continue collection."
recommended = ["resume_torrent"]
elif "readd_to_arr" in action_ids:
next_title = "Add this request to the library queue"
next_description = f"Send the approved request to {collector} so collection can begin."
recommended = ["readd_to_arr"]
elif "search_auto" in action_ids or "search_releases" in action_ids:
if snapshot.request_type == RequestType.tv and missing:
target = f"the {missing} missing episode{'s' if missing != 1 else ''}"
else:
target = f"a matching {noun} release"
next_title = f"Search for {target}"
next_description = (
"Run an automatic search, or review the available releases and choose one manually."
)
recommended = [action_id for action_id in ("search_auto", "search_releases") if action_id in action_ids]
elif download_state == "downloading":
next_title = "Let the current download finish"
next_description = "Magent is tracking the active download; no action is needed right now."
recommended = []
elif snapshot.state == NormalizedState.importing and arr_state == "available":
next_title = "Wait for the media server to index this title"
next_description = (
f"{collector} has completed its work. Use Recheck request to see whether the title "
"has appeared on the media server."
)
recommended = []
elif snapshot.state in {NormalizedState.completed, NormalizedState.available}:
next_title = "Ready to watch"
next_description = "Collection is complete. Open the title on the media server when you are ready."
recommended = []
elif snapshot.state == NormalizedState.requested:
next_title = "Wait for approval"
next_description = "An administrator must approve this request before collection can start."
recommended = []
else:
next_title = "Magent is checking the next step"
next_description = "No safe action is available until the current service state is known."
recommended = []
requested_stage = {
"id": "requested",
"label": "Requested",
"state": "complete",
"summary": "Request received",
}
approved_stage = {
"id": "approved",
"label": "Approved",
"state": "complete" if approved else "active",
"summary": "Approved for collection" if approved else "Waiting for approval",
}
if arr_state == "missing":
library_state, library_summary = "attention", "Not yet added to the collector"
elif arr_state == "error":
library_state, library_summary = "attention", f"Unable to read {collector}"
elif partial:
library_state, library_summary = "partial", f"{available} of {total} episodes collected"
elif arr_state == "available":
library_state, library_summary = "complete", "Collection complete"
elif arr_state in {"added", "searching"}:
library_state = "active" if missing or not available else "complete"
library_summary = (
f"{missing} episode{'s' if missing != 1 else ''} still missing"
if snapshot.request_type == RequestType.tv and missing
else "In the library queue"
)
else:
library_state, library_summary = "waiting", "Waiting for collector information"
if fully_available:
search_state, search_summary = "complete", "No further search needed"
elif arr_state == "available":
search_state, search_summary = "complete", "A release was collected"
elif download_visible:
search_state = "complete"
search_summary = "A release was found"
elif arr_state in {"added", "searching"} and (missing or snapshot.request_type == RequestType.movie):
search_state = "active" if prowlarr_state == "ok" else "attention"
search_summary = (
f"Ready to search for {missing} missing episode{'s' if missing != 1 else ''}"
if snapshot.request_type == RequestType.tv and missing
else "Ready to search for a release"
)
else:
search_state, search_summary = "waiting", "Search has not started"
completed_download_summary = (
"The requested content has been collected and is available to watch. "
"No further action is needed."
)
if fully_available:
download_stage_state, download_summary = "complete", completed_download_summary
pipeline_download_visible = False
pipeline_torrents: List[Dict[str, Any]] = []
elif arr_state == "available":
download_stage_state = "complete"
download_summary = f"{collector} has imported the collected file"
pipeline_download_visible = False
pipeline_torrents = []
elif download_visible:
download_stage_state = {
"downloading": "active",
"paused": "attention",
"completed": "complete",
"missing": "attention",
"error": "attention",
}.get(download_state, "waiting")
download_summary = str(download.get("summary") or "A prior download attempt was found")
pipeline_download_visible = True
pipeline_torrents = download.get("torrents") or []
else:
download_stage_state, download_summary = "waiting", "No download attempt yet"
pipeline_download_visible = False
pipeline_torrents = []
if jellyfin_partial:
available_label = "Partially available"
available_state = "partial"
available_state_label = "Partly ready"
available_summary = f"{available} of {total} episodes are ready to watch in Grizzlyflix."
elif jellyfin_found:
available_label = "Available to watch"
available_state = "complete"
available_state_label = "Ready"
available_summary = "This title is ready to watch in Grizzlyflix."
elif arr_state == "available":
available_label = "Adding to Grizzlyflix"
available_state = "active"
available_state_label = "Indexing"
available_summary = "The download is complete. Grizzlyflix is indexing this title now."
else:
available_label = "Media server"
available_state = "waiting"
available_state_label = "Waiting"
available_summary = "This title has not reached Grizzlyflix yet."
display_download = dict(download)
if fully_available:
display_download.update(
{
"visible": False,
"state": "completed",
"summary": completed_download_summary,
"torrents": [],
}
)
return {
"status": {"label": status_label, "meaning": meaning},
"download": display_download,
"nextStep": {
"title": next_title,
"description": next_description,
"actionIds": recommended,
},
"pipeline": [
requested_stage,
approved_stage,
{
"id": "library",
"label": "Library collection",
"state": library_state,
"summary": library_summary,
"available": available,
"missing": missing,
"total": total,
"seasons": availability.get("seasons") or [],
"missingEpisodes": arr_details.get("missingEpisodes") or {},
},
{
"id": "search",
"label": "Release search",
"state": search_state,
"summary": search_summary,
"actionIds": [] if fully_available else [
action_id
for action_id in ("search_auto", "search_releases")
if action_id in action_ids
],
},
{
"id": "download",
"label": "Download complete" if fully_available else "Download",
"state": download_stage_state,
"summary": download_summary,
"visible": pipeline_download_visible,
"torrents": pipeline_torrents,
},
{
"id": "available",
"label": available_label,
"state": available_state,
"stateLabel": available_state_label,
"summary": available_summary,
"link": jellyfin_link,
},
],
}
async def build_snapshot(request_id: str) -> Snapshot:
timeline = []
runtime = get_runtime_settings()
@@ -1060,7 +449,7 @@ async def build_snapshot(request_id: str) -> Snapshot:
poster_path = media.get("posterPath") or media.get("poster_path")
backdrop_path = media.get("backdropPath") or media.get("backdrop_path")
if snapshot.title in {None, "", "Unknown"} and jellyseerr.configured():
if snapshot.title in {None, "", "Unknown"} and allow_remote:
tmdb_id = jelly_request.get("media", {}).get("tmdbId")
if tmdb_id:
details = await _get_seerr_media_details(jellyseerr, snapshot.request_type, int(tmdb_id))
@@ -1144,7 +533,6 @@ async def build_snapshot(request_id: str) -> Snapshot:
arr_queue = _filter_queue(arr_queue, series_id, RequestType.tv)
arr_details["queue"] = arr_queue
episodes = await sonarr.get_episodes(series_id)
arr_details["availability"] = _episode_availability(episodes)
missing_by_season = _missing_episode_numbers_by_season(episodes)
if missing_by_season:
arr_details["missingEpisodes"] = missing_by_season
@@ -1193,12 +581,6 @@ async def build_snapshot(request_id: str) -> Snapshot:
arr_state = "added"
else:
arr_state = "missing"
arr_details["availability"] = {
"available": 1 if arr_item and arr_item.get("hasFile") else 0,
"missing": 0 if arr_item and arr_item.get("hasFile") else 1,
"total": 1,
"seasons": [],
}
if arr_item and isinstance(arr_item.get("id"), int):
arr_queue = await radarr.get_queue(int(arr_item["id"]))
arr_queue = _filter_queue(arr_queue, int(arr_item["id"]), RequestType.movie)
@@ -1210,20 +592,15 @@ async def build_snapshot(request_id: str) -> Snapshot:
if arr_state is None:
arr_state = "unknown"
_apply_arr_identity(snapshot, arr_item)
timeline.append(TimelineHop(service="Sonarr/Radarr", status=arr_state, details=arr_details))
prowlarr_state = "unknown"
try:
prowlarr_health = await prowlarr.get_health()
if isinstance(prowlarr_health, list) and len(prowlarr_health) > 0:
prowlarr_state = "issues"
timeline.append(TimelineHop(service="Prowlarr", status="issues", details={"health": prowlarr_health}))
else:
prowlarr_state = "ok"
timeline.append(TimelineHop(service="Prowlarr", status="ok"))
except Exception as exc:
prowlarr_state = "error"
timeline.append(TimelineHop(service="Prowlarr", status="error", details={"error": str(exc)}))
jellyfin_available = False
@@ -1291,66 +668,34 @@ async def build_snapshot(request_id: str) -> Snapshot:
except Exception:
pass
qbit_state = "not_started"
qbit_message = "No download attempt has been observed."
download_ids = _download_ids(_queue_records(arr_queue))
download_history = await asyncio.to_thread(get_request_download_evidence, request_id, 100)
torrent_list: List[Dict[str, Any]] = []
download_visible = bool(download_ids) or bool(download_history.get("observed"))
qbit_error = None
qbit_state = None
qbit_message = None
try:
download_ids = _download_ids(_queue_records(arr_queue))
torrent_list: List[Dict[str, Any]] = []
if qbittorrent.configured():
if download_ids:
torrents = await qbittorrent.get_torrents_by_hashes("|".join(download_ids))
torrent_list = torrents if isinstance(torrents, list) else []
else:
request_tag = f"magent-{request_id}"
torrents = await qbittorrent.get_torrents_by_tag(request_tag)
category = f"magent-{request_id}"
torrents = await qbittorrent.get_torrents_by_category(category)
torrent_list = torrents if isinstance(torrents, list) else []
for torrent in torrent_list:
if isinstance(torrent, dict):
torrent["progressPercent"] = _torrent_progress(torrent)
if torrent_list:
download_visible = True
summary = _summarize_qbit(torrent_list)
qbit_state = str(summary.get("state") or "idle")
qbit_message = str(summary.get("message") or "Download found in qBittorrent.")
elif download_ids:
qbit_state = "missing"
qbit_message = (
"The collector queued a download, but it is no longer visible in qBittorrent."
summary = _summarize_qbit(torrent_list)
qbit_state = summary.get("state")
qbit_message = summary.get("message")
timeline.append(
TimelineHop(
service="qBittorrent",
status=summary["state"],
details={
"summary": summary["message"],
"torrents": torrent_list,
},
)
elif download_history.get("observed"):
qbit_state = "missing"
qbit_message = (
"A previous download was observed, but it is not currently visible in qBittorrent."
)
except Exception as exc:
qbit_error = str(exc)
if download_visible:
qbit_state = "error"
qbit_message = (
"A download attempt exists, but Magent cannot currently read its state from qBittorrent."
)
download_presentation = {
"visible": download_visible,
"observed": download_visible,
"state": qbit_state,
"summary": qbit_message,
"torrents": torrent_list,
"lastSeenAt": download_history.get("last_seen_at"),
}
timeline.append(
TimelineHop(
service="qBittorrent",
status=qbit_state,
details={
**download_presentation,
"error": qbit_error,
},
)
)
except Exception as exc:
timeline.append(TimelineHop(service="qBittorrent", status="error", details={"error": str(exc)}))
status_code = None
try:
@@ -1375,8 +720,8 @@ async def build_snapshot(request_id: str) -> Snapshot:
snapshot.state_reason = qbit_message
elif qbit_state == "completed":
if arr_state == "available":
snapshot.state = NormalizedState.importing
snapshot.state_reason = "The collector imported the file. Waiting for the media server to index it."
snapshot.state = NormalizedState.completed
snapshot.state_reason = "In your library and ready to watch."
else:
snapshot.state = NormalizedState.importing
snapshot.state_reason = "Download finished. Waiting for library import."
@@ -1392,8 +737,8 @@ async def build_snapshot(request_id: str) -> Snapshot:
snapshot.state = NormalizedState.searching
snapshot.state_reason = "Searching for a matching release."
elif arr_state == "available":
snapshot.state = NormalizedState.importing
snapshot.state_reason = "Collected by Sonarr/Radarr and waiting for the media server to index it."
snapshot.state = NormalizedState.completed
snapshot.state_reason = "In your library and ready to watch."
elif arr_state == "added" and snapshot.state == NormalizedState.approved:
snapshot.state = NormalizedState.added_to_arr
snapshot.state_reason = "Item is present in Sonarr/Radarr"
@@ -1421,32 +766,23 @@ async def build_snapshot(request_id: str) -> Snapshot:
actions.append(
ActionOption(
id="readd_to_arr",
label=f"Add to {'Sonarr' if snapshot.request_type == RequestType.tv else 'Radarr'}",
label="Push to Sonarr/Radarr",
risk="medium",
description="Send this approved request to the library collector.",
)
)
elif arr_item and arr_state != "available" and qbit_state not in {"downloading", "completed"}:
missing_count = int((arr_details.get("availability") or {}).get("missing") or 0)
automatic_label = (
f"Search automatically for {missing_count} missing episode{'s' if missing_count != 1 else ''}"
if snapshot.request_type == RequestType.tv and missing_count
else "Search automatically for a release"
)
elif arr_item and arr_state != "available":
actions.append(
ActionOption(
id="search_auto",
label=automatic_label,
label="Search and auto-download",
risk="low",
description="Ask the library collector to find and download the best permitted match.",
)
)
actions.append(
ActionOption(
id="search_releases",
label="Review available releases",
label="Search and choose a download",
risk="low",
description="Search the configured indexers and choose a release yourself.",
)
)
@@ -1457,28 +793,18 @@ async def build_snapshot(request_id: str) -> Snapshot:
id="resume_torrent",
label="Resume the download",
risk="low",
description="Resume the existing qBittorrent job if it is paused or stalled.",
)
)
snapshot.actions = actions
jellyfin_link = None
if runtime.jellyfin_public_url and jellyfin_available:
if runtime.jellyfin_public_url and snapshot.state in {
NormalizedState.available,
NormalizedState.completed,
}:
base_url = runtime.jellyfin_public_url.rstrip("/")
jellyfin_item_id = jellyfin_item.get("Id") if isinstance(jellyfin_item, dict) else None
if jellyfin_item_id:
jellyfin_link = f"{base_url}/web/index.html#!/details?id={quote(str(jellyfin_item_id))}"
else:
query = quote(snapshot.title or "")
jellyfin_link = f"{base_url}/web/index.html#!/search?query={query}"
availability = arr_details.get("availability") or {}
is_partial = bool(
jellyfin_available
and snapshot.request_type == RequestType.tv
and int(availability.get("missing") or 0) > 0
)
if jellyfin_available and not is_partial:
snapshot.actions = []
query = quote(snapshot.title or "")
jellyfin_link = f"{base_url}/web/index.html#!/search?query={query}"
snapshot.raw = {
"jellyseerr": jelly_request,
"arr": {
@@ -1487,47 +813,15 @@ async def build_snapshot(request_id: str) -> Snapshot:
},
"jellyfin": {
"publicUrl": runtime.jellyfin_public_url,
"found": jellyfin_available,
"available": jellyfin_available and snapshot.state in {
"available": snapshot.state in {
NormalizedState.available,
NormalizedState.completed,
},
"partial": is_partial,
"link": jellyfin_link,
"item": jellyfin_item,
},
"qbittorrent": {
**download_presentation,
"downloadIds": download_ids,
"error": qbit_error,
},
}
snapshot.presentation = _build_presentation(
snapshot,
approved=derived_approved,
arr_state=arr_state,
arr_details=arr_details,
prowlarr_state=prowlarr_state,
download=download_presentation,
jellyfin_found=jellyfin_available,
jellyfin_link=jellyfin_link,
)
repair_action = await asyncio.to_thread(_latest_repair_action, request_id)
repair_activity = _build_repair_activity(
snapshot,
action=repair_action,
arr_state=arr_state,
arr_details=arr_details,
download=download_presentation,
jellyfin_found=jellyfin_available,
)
if repair_activity:
snapshot.presentation["repairActivity"] = repair_activity
status_presentation = snapshot.presentation.get("status")
if isinstance(status_presentation, dict) and status_presentation.get("meaning"):
snapshot.state_reason = str(status_presentation["meaning"])
await _maybe_refresh_jellyfin(snapshot)
await asyncio.to_thread(save_snapshot, snapshot)
return snapshot
+4 -4
View File
@@ -2,8 +2,8 @@ fastapi==0.134.0
uvicorn==0.41.0
httpx==0.28.1
pydantic==2.12.5
pydantic-settings==2.14.2
PyJWT==2.13.0
pydantic-settings==2.13.1
PyJWT==2.11.0
passlib==1.7.4
python-multipart==0.0.31
Pillow==12.3.0
python-multipart==0.0.22
Pillow==12.1.1
File diff suppressed because it is too large Load Diff
-28
View File
@@ -1,28 +0,0 @@
name: magent-beta
services:
magent:
build:
context: .
dockerfile: Dockerfile
env_file:
- ./.env
environment:
APP_NAME: Magent Beta
CORS_ALLOW_ORIGIN: https://beta.grizzlyflix.co.nz
MAGENT_APPLICATION_URL: https://beta.grizzlyflix.co.nz
MAGENT_API_URL: https://beta.grizzlyflix.co.nz/api
AUTH_COOKIE_NAME: magent_beta_auth
AUTH_STATE_COOKIE_NAME: magent_beta_logged_in
AUTH_COOKIE_DOMAIN: beta.grizzlyflix.co.nz
SQLITE_PATH: /app/data/magent.db
LOG_FILE: /app/data/magent.log
SITE_BANNER_ENABLED: "true"
SITE_BANNER_MESSAGE: "Beta environment"
SITE_BANNER_TONE: warning
ports:
- "${BETA_FRONTEND_BIND:-10.30.1.32}:3100:3000"
- "127.0.0.1:8100:8000"
volumes:
- ./data:/app/data
restart: unless-stopped
+149 -456
View File
@@ -1,10 +1,10 @@
'use client'
import { useRouter } from 'next/navigation'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { authFetch, clearToken, getApiBase, getEventStreamToken, getToken } from '../lib/auth'
import AdminDiagnosticsPanel from '../ui/AdminDiagnosticsPanel'
import { useRouter } from 'next/navigation'
import { authFetch, clearToken, getApiBase, getToken, getEventStreamToken } from '../lib/auth'
import AdminShell from '../ui/AdminShell'
import AdminDiagnosticsPanel from '../ui/AdminDiagnosticsPanel'
type AdminSetting = {
key: string
@@ -19,12 +19,6 @@ type ServiceOptions = {
qualityProfiles: { id: number; name: string; label: string }[]
}
type ServiceStatus = {
name: string
status: string
message?: string
}
const SECTION_LABELS: Record<string, string> = {
magent: 'Magent',
general: 'General',
@@ -33,17 +27,14 @@ const SECTION_LABELS: Record<string, string> = {
jellyseerr: 'Seerr',
jellyfin: 'Jellyfin',
artwork: 'Artwork cache',
cache: 'Request cache',
cache: 'Cache Control',
sonarr: 'Sonarr',
radarr: 'Radarr',
bazarr: 'Bazarr',
prowlarr: 'Prowlarr',
qbittorrent: 'qBittorrent',
logs: 'Activity log',
maintenance: 'Maintenance',
requests: 'Request pipeline',
'issue-workflow': 'Issue workflow',
site: 'Site & login',
log: 'Activity log',
requests: 'Request sync',
site: 'Site',
}
const BOOL_SETTINGS = new Set([
@@ -53,7 +44,6 @@ const BOOL_SETTINGS = new Set([
'site_login_show_local_login',
'site_login_show_forgot_password',
'site_login_show_signup_link',
'site_nav_show_requests',
'magent_proxy_enabled',
'magent_proxy_trust_forwarded_headers',
'magent_ssl_bind_enabled',
@@ -84,7 +74,6 @@ const URL_SETTINGS = new Set([
'jellyfin_public_url',
'sonarr_base_url',
'radarr_base_url',
'bazarr_base_url',
'prowlarr_base_url',
'qbittorrent_base_url',
])
@@ -98,8 +87,6 @@ const NUMBER_SETTINGS = new Set([
'requests_poll_interval_seconds',
'requests_delta_sync_interval_minutes',
'requests_cleanup_days',
'issue_confirmation_contact_attempts',
'issue_confirmation_interval_value',
])
const BANNER_TONES = ['info', 'warning', 'error', 'maintenance']
@@ -112,18 +99,15 @@ const SECTION_DESCRIPTIONS: Record<string, string> = {
'Notification providers and delivery channel settings used by Magent messaging features.',
seerr: 'Connect Seerr where users submit content requests.',
jellyseerr: 'Connect Seerr where users submit content requests.',
jellyfin: 'Jellyfin connection, public playback links, user sync, and availability checks.',
jellyfin: 'Control Jellyfin login and availability checks.',
artwork: 'Cache posters/backdrops and review artwork coverage.',
cache: 'Manage saved requests cache and refresh behavior.',
sonarr: 'Sonarr connection and the default profile and library location for TV requests.',
radarr: 'Radarr connection and the default profile and library location for movie requests.',
bazarr: 'Bazarr connection used to find and replace movie and episode subtitles.',
prowlarr: 'Prowlarr connection used by Sonarr and Radarr for release searches.',
qbittorrent: 'qBittorrent connection used for collector-owned download progress and diagnostics.',
sonarr: 'TV automation settings.',
radarr: 'Movie automation settings.',
prowlarr: 'Indexer search settings.',
qbittorrent: 'Downloader connection settings.',
requests: 'Control how often requests are refreshed and cleaned up.',
'issue-workflow': 'Control reporter confirmation, reminder timing, and automatic issue closure.',
logs: 'Control log output and inspect recent application activity for troubleshooting.',
maintenance: 'Repair cached data, clean historical records, and run recovery operations.',
log: 'Activity log for troubleshooting.',
site: 'Sitewide banner, login page visibility, and version details. The changelog is generated from git history during release builds.',
}
@@ -137,11 +121,9 @@ const SETTINGS_SECTION_MAP: Record<string, string | null> = {
artwork: null,
sonarr: 'sonarr',
radarr: 'radarr',
bazarr: 'bazarr',
prowlarr: 'prowlarr',
qbittorrent: 'qbittorrent',
requests: 'requests',
'issue-workflow': 'issue',
cache: null,
logs: 'log',
maintenance: null,
@@ -244,14 +226,10 @@ const MAGENT_SECTION_GROUPS: Array<{
'magent_notify_push_token',
'magent_notify_push_user_key',
'magent_notify_push_device',
'magent_notify_webhook_enabled',
'magent_notify_webhook_url',
],
},
{
key: 'magent-notify-webhook',
title: 'Generic Webhook',
description: 'Send notifications to a custom automation or integration endpoint.',
keys: ['magent_notify_webhook_enabled', 'magent_notify_webhook_url'],
},
]
const MAGENT_GROUPS_BY_SECTION: Record<string, Set<string>> = {
@@ -262,7 +240,6 @@ const MAGENT_GROUPS_BY_SECTION: Record<string, Set<string>> = {
'magent-notify-discord',
'magent-notify-telegram',
'magent-notify-push',
'magent-notify-webhook',
]),
}
@@ -289,165 +266,9 @@ const SITE_SECTION_GROUPS: Array<{
'site_login_show_signup_link',
],
},
{
key: 'site-navigation',
title: 'Beta Navigation',
description: 'Temporarily show or hide beta navigation entries while new request pipelines are built.',
keys: ['site_nav_show_requests'],
},
]
const STANDARD_SECTION_GROUPS: Record<
string,
Array<{ key: string; title: string; description: string; keys: string[] }>
> = {
seerr: [
{
key: 'seerr-connection',
title: 'Connection',
description: 'The Seerr endpoint and API credential Magent uses for request discovery and status.',
keys: ['jellyseerr_base_url', 'jellyseerr_api_key'],
},
],
jellyseerr: [
{
key: 'seerr-connection',
title: 'Connection',
description: 'The Seerr endpoint and API credential Magent uses for request discovery and status.',
keys: ['jellyseerr_base_url', 'jellyseerr_api_key'],
},
],
jellyfin: [
{
key: 'jellyfin-connection',
title: 'Connection',
description: 'Internal Jellyfin endpoint and administrator API credential used for lookups and user sync.',
keys: ['jellyfin_base_url', 'jellyfin_api_key'],
},
{
key: 'jellyfin-playback',
title: 'Playback Links',
description: 'Public address used when a viewer opens an available title from Magent.',
keys: ['jellyfin_public_url'],
},
{
key: 'jellyfin-users',
title: 'Library and User Sync',
description: 'Control cross-service library reconciliation and manually import Jellyfin users.',
keys: ['jellyfin_sync_to_arr'],
},
],
sonarr: [
{
key: 'sonarr-connection',
title: 'Connection',
description: 'Sonarr endpoint and API credential used for TV collection operations.',
keys: ['sonarr_base_url', 'sonarr_api_key'],
},
{
key: 'sonarr-library',
title: 'TV Collection Defaults',
description: 'Default quality profile and destination folder used for TV requests.',
keys: ['sonarr_quality_profile_id', 'sonarr_root_folder'],
},
],
radarr: [
{
key: 'radarr-connection',
title: 'Connection',
description: 'Radarr endpoint and API credential used for movie collection operations.',
keys: ['radarr_base_url', 'radarr_api_key'],
},
{
key: 'radarr-library',
title: 'Movie Collection Defaults',
description: 'Default quality profile and destination folder used for movie requests.',
keys: ['radarr_quality_profile_id', 'radarr_root_folder'],
},
],
bazarr: [
{
key: 'bazarr-connection',
title: 'Connection',
description: 'Bazarr endpoint, API credential, and default language used by subtitle issue repairs.',
keys: ['bazarr_base_url', 'bazarr_api_key', 'bazarr_default_language'],
},
],
prowlarr: [
{
key: 'prowlarr-connection',
title: 'Connection',
description: 'Prowlarr endpoint and API credential used for indexer health and release discovery.',
keys: ['prowlarr_base_url', 'prowlarr_api_key'],
},
],
qbittorrent: [
{
key: 'qbittorrent-connection',
title: 'Connection and Sign-in',
description: 'qBittorrent Web UI endpoint and credentials used for live download progress and recovery.',
keys: ['qbittorrent_base_url', 'qbittorrent_username', 'qbittorrent_password'],
},
],
requests: [
{
key: 'requests-sync',
title: 'Synchronization Schedule',
description: 'Control incremental checks and the scheduled full request-cache rebuild.',
keys: [
'requests_poll_interval_seconds',
'requests_delta_sync_interval_minutes',
'requests_full_sync_time',
],
},
{
key: 'requests-retention',
title: 'History Retention',
description: 'Choose when old status history is cleaned up and how long it is retained.',
keys: ['requests_cleanup_time', 'requests_cleanup_days'],
},
],
'issue-workflow': [
{
key: 'issues-resolution-confirmation',
title: 'Resolution confirmation',
description: 'Choose how often Magent asks a reporter to confirm a fix before the issue is closed automatically.',
keys: [
'issue_confirmation_contact_attempts',
'issue_confirmation_interval_value',
'issue_confirmation_interval_unit',
],
},
],
logs: [
{
key: 'logs-output',
title: 'Log Output',
description: 'Set the default application verbosity and the active log-file destination.',
keys: ['log_level', 'log_file'],
},
{
key: 'logs-rotation',
title: 'File Rotation',
description: 'Limit log-file growth and choose how many historical files remain on disk.',
keys: ['log_file_max_bytes', 'log_file_backup_count'],
},
{
key: 'logs-components',
title: 'Component Verbosity',
description: 'Tune noisy outbound-service and scheduled-background messages independently.',
keys: ['log_http_client_level', 'log_background_sync_level'],
},
],
}
const SETTING_LABEL_OVERRIDES: Record<string, string> = {
bazarr_base_url: 'Bazarr base URL',
bazarr_api_key: 'Bazarr API key',
bazarr_default_language: 'Default subtitle language',
issue_confirmation_contact_attempts: 'Confirmation emails before auto-close',
issue_confirmation_interval_value: 'Confirmation interval',
issue_confirmation_interval_unit: 'Interval unit',
jellyseerr_base_url: 'Seerr base URL',
jellyseerr_api_key: 'Seerr API key',
magent_application_url: 'Application URL',
@@ -488,38 +309,10 @@ const SETTING_LABEL_OVERRIDES: Record<string, string> = {
magent_notify_push_device: 'Device / target',
magent_notify_webhook_enabled: 'Generic webhook notifications enabled',
magent_notify_webhook_url: 'Generic webhook URL',
jellyfin_base_url: 'Internal server URL',
jellyfin_api_key: 'Administrator API key',
jellyfin_public_url: 'Public playback URL',
jellyfin_sync_to_arr: 'Reconcile Jellyfin with Sonarr and Radarr',
sonarr_base_url: 'Sonarr server URL',
sonarr_api_key: 'Sonarr API key',
sonarr_quality_profile_id: 'Default TV quality profile',
sonarr_root_folder: 'Default TV root folder',
radarr_base_url: 'Radarr server URL',
radarr_api_key: 'Radarr API key',
radarr_quality_profile_id: 'Default movie quality profile',
radarr_root_folder: 'Default movie root folder',
prowlarr_base_url: 'Prowlarr server URL',
prowlarr_api_key: 'Prowlarr API key',
qbittorrent_base_url: 'Web UI URL',
qbittorrent_username: 'Web UI username',
qbittorrent_password: 'Web UI password',
requests_sync_ttl_minutes: 'Request cache freshness (minutes)',
requests_poll_interval_seconds: 'Full-sync eligibility check (seconds)',
requests_delta_sync_interval_minutes: 'Recent-change sync interval (minutes)',
requests_full_sync_time: 'Daily full-sync time',
requests_cleanup_time: 'Daily history cleanup time',
requests_cleanup_days: 'History retention (days)',
requests_data_source: 'Request read source',
artwork_cache_mode: 'Artwork delivery mode',
log_level: 'Application log level',
log_file: 'Active log file',
site_login_show_jellyfin_login: 'Login page: Jellyfin sign-in',
site_login_show_local_login: 'Login page: local Magent sign-in',
site_login_show_forgot_password: 'Login page: forgot password',
site_login_show_signup_link: 'Login page: invite signup link',
site_nav_show_requests: 'Top navigation: New Requests',
log_file_max_bytes: 'Log file max size (bytes)',
log_file_backup_count: 'Rotated log files to keep',
log_http_client_level: 'Service HTTP log level',
@@ -550,7 +343,6 @@ const labelFromKey = (key: string) =>
.replace('site banner enabled', 'Sitewide banner enabled')
.replace('site banner message', 'Sitewide banner message')
.replace('site banner tone', 'Sitewide banner tone')
.replace('site nav show requests', 'Top navigation: New Requests')
.replace('site changelog', 'Changelog text')
const formatBytes = (value?: number | null) => {
@@ -583,12 +375,12 @@ type SectionFeedback = {
}
const SERVICE_TEST_ENDPOINTS: Record<string, string> = {
'seerr-connection': 'seerr',
'jellyfin-connection': 'jellyfin',
'sonarr-connection': 'sonarr',
'radarr-connection': 'radarr',
'prowlarr-connection': 'prowlarr',
'qbittorrent-connection': 'qbittorrent',
jellyseerr: 'seerr',
jellyfin: 'jellyfin',
sonarr: 'sonarr',
radarr: 'radarr',
prowlarr: 'prowlarr',
qbittorrent: 'qbittorrent',
}
export default function SettingsPage({ section }: SettingsPageProps) {
@@ -622,8 +414,6 @@ export default function SettingsPage({ section }: SettingsPageProps) {
const [maintenanceStatus, setMaintenanceStatus] = useState<string | null>(null)
const [maintenanceBusy, setMaintenanceBusy] = useState(false)
const [liveStreamConnected, setLiveStreamConnected] = useState(false)
const [serviceStatuses, setServiceStatuses] = useState<ServiceStatus[]>([])
const [serviceStatusCheckedAt, setServiceStatusCheckedAt] = useState<string | null>(null)
const requestsSyncRef = useRef<any | null>(null)
const artworkPrefetchRef = useRef<any | null>(null)
const computeProgressPercent = (
@@ -716,7 +506,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
console.error(err)
const message =
err instanceof Error && err.message
? err.message.replace(/^\\{"detail":"|"\\}$/g, '')
? err.message.replace(/^\\{\"detail\":\"|\"\\}$/g, '')
: 'Could not load artwork stats.'
setArtworkSummaryStatus(message)
}
@@ -753,21 +543,6 @@ export default function SettingsPage({ section }: SettingsPageProps) {
}
}, [])
const loadServiceStatuses = useCallback(async () => {
try {
const baseUrl = getApiBase()
const response = await authFetch(`${baseUrl}/status/services`)
if (!response.ok) {
return
}
const data = await response.json()
setServiceStatuses(Array.isArray(data?.services) ? data.services : [])
setServiceStatusCheckedAt(new Date().toISOString())
} catch (err) {
console.error(err)
}
}, [])
useEffect(() => {
const load = async () => {
if (!getToken()) {
@@ -775,7 +550,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
return
}
try {
await Promise.all([loadSettings(), loadServiceStatuses()])
await loadSettings()
if (section === 'cache' || section === 'artwork') {
await loadArtworkPrefetchStatus()
await loadArtworkSummary()
@@ -795,7 +570,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
if (section === 'radarr') {
void loadOptions('radarr')
}
}, [loadArtworkPrefetchStatus, loadArtworkSummary, loadOptions, loadServiceStatuses, loadSettings, router, section])
}, [loadArtworkPrefetchStatus, loadArtworkSummary, loadOptions, loadSettings, router, section])
const groupedSettings = useMemo(() => {
const groups: Record<string, AdminSetting[]> = {}
@@ -808,119 +583,115 @@ export default function SettingsPage({ section }: SettingsPageProps) {
}, [settings])
const settingsSection = SETTINGS_SECTION_MAP[section] ?? null
const statusNamesBySection: Record<string, string[]> = {
seerr: ['Seerr', 'Jellyseerr', 'Jellyseer'],
jellyseerr: ['Seerr', 'Jellyseerr', 'Jellyseer'],
jellyfin: ['Jellyfin'],
sonarr: ['Sonarr'],
radarr: ['Radarr'],
prowlarr: ['Prowlarr'],
qbittorrent: ['qBittorrent', 'Qbittorrent'],
}
const statusNames = statusNamesBySection[section] ?? statusNamesBySection[settingsSection ?? ''] ?? []
const currentServiceStatus = serviceStatuses.find((service) =>
statusNames.some((name) => name.toLowerCase() === service.name.toLowerCase())
)
const currentServiceConfigured = currentServiceStatus
? currentServiceStatus.status !== 'not_configured'
: null
const isMagentGroupedSection = section === 'magent' || section === 'general' || section === 'notifications'
const isSiteGroupedSection = section === 'site'
const visibleSections = settingsSection ? [settingsSection] : []
const isCacheSection = section === 'cache'
const isArtworkSection = section === 'artwork'
const cacheSettingKeys = new Set(['requests_sync_ttl_minutes', 'requests_data_source'])
const artworkSettingKeys = new Set(['artwork_cache_mode'])
const generatedSettingKeys = new Set(['site_changelog'])
const hiddenSettingKeys = new Set([...cacheSettingKeys, ...artworkSettingKeys, ...generatedSettingKeys])
const obsoleteSettingKeys = new Set([
'sonarr_qbittorrent_category',
'radarr_qbittorrent_category',
])
const requestSettingOrder = [
'requests_poll_interval_seconds',
'requests_delta_sync_interval_minutes',
'requests_full_sync_time',
'requests_cleanup_time',
'requests_cleanup_days',
]
const siteSettingOrder = [
'site_banner_enabled',
'site_banner_message',
'site_banner_tone',
'site_login_show_jellyfin_login',
'site_login_show_local_login',
'site_login_show_forgot_password',
'site_login_show_signup_link',
]
const sortByOrder = (items: AdminSetting[], order: string[]) => {
const position = new Map(order.map((key, index) => [key, index]))
return [...items].sort((a, b) => {
const aIndex = position.get(a.key) ?? Number.POSITIVE_INFINITY
const bIndex = position.get(b.key) ?? Number.POSITIVE_INFINITY
if (aIndex !== bIndex) return aIndex - bIndex
return a.key.localeCompare(b.key)
})
}
const cacheSettings = settings.filter((setting) => cacheSettingKeys.has(setting.key))
const artworkSettings = settings.filter((setting) => artworkSettingKeys.has(setting.key))
const buildDefinedSections = (
definitions: Array<{ key: string; title: string; description: string; keys: string[] }>,
sourceItems: AdminSetting[],
includeUnassigned = true,
): SettingsSectionGroup[] => {
const byKey = new Map(sourceItems.map((item) => [item.key, item]))
const assignedKeys = new Set(definitions.flatMap((group) => group.keys))
const groups = definitions.map((group) => ({
key: group.key,
title: group.title,
description: group.description,
items: group.keys
.map((key) => byKey.get(key))
.filter((item): item is AdminSetting => Boolean(item)),
}))
if (includeUnassigned) {
const unassigned = sourceItems.filter((item) => !assignedKeys.has(item.key))
if (unassigned.length > 0) {
groups.push({
key: `${section}-additional`,
title: 'Additional Settings',
description: 'Settings returned by Magent that do not yet belong to a dedicated subsection.',
items: unassigned.sort((a, b) => a.key.localeCompare(b.key)),
})
}
}
return groups
}
const standardDefinitions = STANDARD_SECTION_GROUPS[section]
const standardItems = settingsSection
? (groupedSettings[settingsSection] ?? []).filter(
(setting) => !obsoleteSettingKeys.has(setting.key) && !hiddenSettingKeys.has(setting.key),
)
: []
const settingsSections: SettingsSectionGroup[] = isCacheSection
? [
{
key: 'cache',
title: 'Request Cache Strategy',
description: 'Choose where request pages read from and how long cached request records remain fresh.',
items: cacheSettings,
},
{ key: 'cache', title: 'Cache control', items: cacheSettings },
{ key: 'artwork', title: 'Artwork cache', items: artworkSettings },
]
: isArtworkSection
? [
{
key: 'artwork',
title: 'Artwork Delivery and Storage',
description: 'Choose how posters and backdrops are delivered, then inspect or rebuild the local artwork cache.',
items: artworkSettings,
},
]
: isMagentGroupedSection
? (() => {
if (section === 'magent') {
return []
}
const magentItems = groupedSettings.magent ?? []
const byKey = new Map(magentItems.map((item) => [item.key, item]))
const allowedGroupKeys = MAGENT_GROUPS_BY_SECTION[section] ?? new Set<string>()
const definitions = MAGENT_SECTION_GROUPS.filter((group) => allowedGroupKeys.has(group.key))
return buildDefinedSections(definitions, magentItems, false)
const groups: SettingsSectionGroup[] = MAGENT_SECTION_GROUPS.filter((group) =>
allowedGroupKeys.has(group.key),
).map((group) => {
const items = group.keys
.map((key) => byKey.get(key))
.filter((item): item is AdminSetting => Boolean(item))
return {
key: group.key,
title: group.title,
description: group.description,
items,
}
})
return groups
})()
: isSiteGroupedSection
? buildDefinedSections(
SITE_SECTION_GROUPS,
(groupedSettings.site ?? []).filter((setting) => !hiddenSettingKeys.has(setting.key)),
)
: standardDefinitions
? buildDefinedSections(standardDefinitions, standardItems)
: []
? (() => {
const siteItems = groupedSettings.site ?? []
const byKey = new Map(siteItems.map((item) => [item.key, item]))
return SITE_SECTION_GROUPS.map((group) => {
const items = group.keys
.map((key) => byKey.get(key))
.filter((item): item is AdminSetting => Boolean(item))
return {
key: group.key,
title: group.title,
description: group.description,
items,
}
})
})()
: visibleSections.map((sectionKey) => ({
key: sectionKey,
title: SECTION_LABELS[sectionKey] ?? sectionKey,
items: (() => {
const sectionItems = groupedSettings[sectionKey] ?? []
const filtered =
sectionKey === 'requests' || sectionKey === 'artwork' || sectionKey === 'site'
? sectionItems.filter((setting) => !hiddenSettingKeys.has(setting.key))
: sectionItems
if (sectionKey === 'requests') {
return sortByOrder(filtered, requestSettingOrder)
}
if (sectionKey === 'site') {
return sortByOrder(filtered, siteSettingOrder)
}
return filtered
})(),
}))
const showLogs = section === 'logs'
const showMaintenance = section === 'maintenance'
const showRequestsExtras = section === 'requests'
const showArtworkExtras = section === 'artwork'
const showArtworkExtras = section === 'cache'
const showCacheExtras = section === 'cache'
const shouldRenderSection = (sectionGroup: { key: string; items?: AdminSetting[] }) => {
if (sectionGroup.items && sectionGroup.items.length > 0) return true
if (showArtworkExtras && sectionGroup.key === 'artwork') return true
if (showCacheExtras && sectionGroup.key === 'cache') return true
if (showRequestsExtras && sectionGroup.key === 'requests-sync') return true
if (showRequestsExtras && sectionGroup.key === 'requests') return true
return false
}
const renderedSettingsSections = settingsSections.filter(shouldRenderSection)
useEffect(() => {
requestsSyncRef.current = requestsSync
@@ -931,12 +702,6 @@ export default function SettingsPage({ section }: SettingsPageProps) {
}, [artworkPrefetch])
const settingDescriptions: Record<string, string> = {
issue_confirmation_contact_attempts:
'Number of confirmation emails sent after an issue is marked fixed. Set 0 to send none and close immediately.',
issue_confirmation_interval_value:
'Amount of time between confirmation emails, and the final waiting period before automatic closure.',
issue_confirmation_interval_unit:
'Unit used for the confirmation interval: days, weeks, or months.',
magent_application_url:
'Canonical public URL for the Magent web app (used for links and reverse-proxy-aware features).',
magent_application_port:
@@ -1008,15 +773,14 @@ export default function SettingsPage({ section }: SettingsPageProps) {
artwork_cache_mode: 'Choose whether posters are cached locally or loaded from the web.',
sonarr_base_url: 'Sonarr server URL for TV tracking (FQDN or IP). Scheme is optional.',
sonarr_api_key: 'API key for Sonarr.',
bazarr_base_url: 'Bazarr server URL used for movie and episode subtitle repairs. Scheme is optional.',
bazarr_api_key: 'API key used to ask Bazarr for fresh subtitles.',
bazarr_default_language: 'Language code Bazarr should search for by default, such as en.',
sonarr_quality_profile_id: 'Quality profile used when adding TV shows.',
sonarr_root_folder: 'Root folder where Sonarr stores TV shows.',
sonarr_qbittorrent_category: 'qBittorrent category for manual Sonarr downloads.',
radarr_base_url: 'Radarr server URL for movies (FQDN or IP). Scheme is optional.',
radarr_api_key: 'API key for Radarr.',
radarr_quality_profile_id: 'Quality profile used when adding movies.',
radarr_root_folder: 'Root folder where Radarr stores movies.',
radarr_qbittorrent_category: 'qBittorrent category for manual Radarr downloads.',
prowlarr_base_url:
'Prowlarr server URL for indexer searches (FQDN or IP). Scheme is optional.',
prowlarr_api_key: 'API key for Prowlarr.',
@@ -1050,8 +814,6 @@ export default function SettingsPage({ section }: SettingsPageProps) {
site_login_show_local_login: 'Show the local Magent login button on the login page.',
site_login_show_forgot_password: 'Show the forgot-password link on the login page.',
site_login_show_signup_link: 'Show the invite signup link on the login page.',
site_nav_show_requests:
'Show the New Requests item in the top navigation. Disable it while request creation is unavailable.',
site_changelog: 'One update per line for the public changelog.',
}
@@ -1085,8 +847,6 @@ export default function SettingsPage({ section }: SettingsPageProps) {
jellyfin_base_url: 'https://jelly.example.com or 10.40.0.80:8096',
jellyfin_public_url: 'https://jelly.example.com',
sonarr_base_url: 'https://sonarr.example.com or 10.30.1.81:8989',
bazarr_base_url: 'https://bazarr.example.com or 10.30.1.81:6767',
bazarr_default_language: 'en',
radarr_base_url: 'https://radarr.example.com or 10.30.1.81:7878',
prowlarr_base_url: 'https://prowlarr.example.com or 10.30.1.81:9696',
qbittorrent_base_url: 'https://qb.example.com or 10.30.1.81:8080',
@@ -1115,7 +875,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
const parseActionError = (err: unknown, fallback: string) => {
if (err instanceof Error && err.message) {
return err.message.replace(/^\\{"detail":"|"\\}$/g, '')
return err.message.replace(/^\\{\"detail\":\"|\"\\}$/g, '')
}
return fallback
}
@@ -1303,7 +1063,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
console.error(err)
const message =
err instanceof Error && err.message
? err.message.replace(/^\\{"detail":"|"\\}$/g, '')
? err.message.replace(/^\\{\"detail\":\"|\"\\}$/g, '')
: 'Could not import Jellyfin users.'
setJellyfinSyncStatus(message)
}
@@ -1334,7 +1094,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
console.error(err)
const message =
err instanceof Error && err.message
? err.message.replace(/^\\{"detail":"|"\\}$/g, '')
? err.message.replace(/^\\{\"detail\":\"|\"\\}$/g, '')
: 'Could not sync requests.'
setRequestsSyncStatus(message)
}
@@ -1365,7 +1125,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
console.error(err)
const message =
err instanceof Error && err.message
? err.message.replace(/^\\{"detail":"|"\\}$/g, '')
? err.message.replace(/^\\{\"detail\":\"|\"\\}$/g, '')
: 'Could not run delta sync.'
setRequestsSyncStatus(message)
}
@@ -1395,7 +1155,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
console.error(err)
const message =
err instanceof Error && err.message
? err.message.replace(/^\\{"detail":"|"\\}$/g, '')
? err.message.replace(/^\\{\"detail\":\"|\"\\}$/g, '')
: 'Could not cache artwork.'
setArtworkPrefetchStatus(message)
}
@@ -1426,7 +1186,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
console.error(err)
const message =
err instanceof Error && err.message
? err.message.replace(/^\\{"detail":"|"\\}$/g, '')
? err.message.replace(/^\\{\"detail\":\"|\"\\}$/g, '')
: 'Could not cache missing artwork.'
setArtworkPrefetchStatus(message)
}
@@ -1471,7 +1231,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
setLiveStreamConnected(true)
try {
const payload = JSON.parse(event.data)
if (payload?.type !== 'admin_live_state') {
if (!payload || payload.type !== 'admin_live_state') {
return
}
@@ -1641,7 +1401,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
console.error(err)
const message =
err instanceof Error && err.message
? err.message.replace(/^\\{"detail":"|"\\}$/g, '')
? err.message.replace(/^\\{\"detail\":\"|\"\\}$/g, '')
: 'Could not load logs.'
setLogsStatus(message)
}
@@ -1683,7 +1443,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
console.error(err)
const message =
err instanceof Error && err.message
? err.message.replace(/^\\{"detail":"|"\\}$/g, '')
? err.message.replace(/^\\{\"detail\":\"|\"\\}$/g, '')
: 'Could not load cache.'
setCacheStatus(message)
} finally {
@@ -1816,6 +1576,10 @@ export default function SettingsPage({ section }: SettingsPageProps) {
<span>Maintenance job</span>
<strong>{maintenanceBusy ? 'Running' : 'Idle'}</strong>
</div>
<div className="cache-rail-metric">
<span>Live updates</span>
<strong>{liveStreamConnected ? 'Connected' : 'Polling'}</strong>
</div>
<div className="cache-rail-metric">
<span>Log lines in view</span>
<strong>{logsLines.length}</strong>
@@ -1829,7 +1593,8 @@ export default function SettingsPage({ section }: SettingsPageProps) {
</div>
) : undefined
const cacheRail = showCacheExtras ? (
<div className="admin-rail-card cache-rail-card">
<div className="admin-rail-stack">
<div className="admin-rail-card cache-rail-card">
<span className="admin-rail-eyebrow">Cache control</span>
<h2>Saved requests</h2>
<p>Load and inspect cached request entries from the right rail.</p>
@@ -1874,10 +1639,8 @@ export default function SettingsPage({ section }: SettingsPageProps) {
)}
</button>
{cacheStatus && <div className="error-banner">{cacheStatus}</div>}
</div>
) : undefined
const artworkRail = showArtworkExtras ? (
<div className="admin-rail-card cache-rail-card">
</div>
<div className="admin-rail-card cache-rail-card">
<span className="admin-rail-eyebrow">Artwork</span>
<h2>Cache stats</h2>
<div className="cache-rail-metrics">
@@ -1898,6 +1661,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
<strong>{artworkSummary?.cache_mode ?? '--'}</strong>
</div>
</div>
</div>
</div>
) : undefined
@@ -1909,7 +1673,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
<AdminShell
title={SECTION_LABELS[section] ?? 'Settings'}
subtitle={SECTION_DESCRIPTIONS[section] ?? 'Manage settings.'}
rail={maintenanceRail ?? cacheRail ?? artworkRail}
rail={maintenanceRail ?? cacheRail}
actions={
<button type="button" onClick={() => router.push('/admin')}>
Back to settings
@@ -1917,72 +1681,27 @@ export default function SettingsPage({ section }: SettingsPageProps) {
}
>
{status && <div className="error-banner">{status}</div>}
{currentServiceStatus ? (
<section className="admin-section admin-zone service-status-panel">
<div className="service-status-summary">
<span className={`system-dot system-dot-${currentServiceStatus.status}`} aria-hidden="true" />
<div>
<span className="section-kicker">Connection status</span>
<h2>{currentServiceStatus.name}</h2>
<p className="section-subtitle">
{currentServiceStatus.message ?? 'No service message was returned.'}
</p>
</div>
</div>
<div className="service-status-grid">
<div>
<span>Status</span>
<strong>{currentServiceStatus.status.replaceAll('_', ' ')}</strong>
</div>
<div>
<span>Configuration</span>
<strong>{currentServiceConfigured ? 'Configured' : 'Not configured'}</strong>
</div>
<div>
<span>Last checked</span>
<strong>
{serviceStatusCheckedAt ? new Date(serviceStatusCheckedAt).toLocaleString() : 'Not checked yet'}
</strong>
</div>
<button type="button" className="ghost-button" onClick={() => void loadServiceStatuses()}>
Refresh status
</button>
</div>
</section>
) : null}
{renderedSettingsSections.length > 1 ? (
<nav className="config-subsection-nav" aria-label={`${SECTION_LABELS[section] ?? 'Settings'} subsections`}>
<span>On this page</span>
<div>
{renderedSettingsSections.map((sectionGroup, index) => (
<a key={sectionGroup.key} href={`#config-${sectionGroup.key}`}>
<small>{String(index + 1).padStart(2, '0')}</small>
{sectionGroup.title}
</a>
))}
</div>
</nav>
) : null}
{renderedSettingsSections.length > 0 ? (
{settingsSections.length > 0 ? (
<div className="admin-form admin-zone-stack">
{renderedSettingsSections.map((sectionGroup, sectionIndex) => (
<section id={`config-${sectionGroup.key}`} key={sectionGroup.key} className="admin-section admin-zone config-subsection">
{settingsSections
.filter(shouldRenderSection)
.map((sectionGroup) => (
<section key={sectionGroup.key} className="admin-section admin-zone">
<div className="section-header">
<div className="config-subsection-heading">
<span className="section-kicker">Subsection {String(sectionIndex + 1).padStart(2, '0')}</span>
<h2>{sectionGroup.title}</h2>
</div>
{sectionGroup.key === 'sonarr-library' && (
<h2>
{sectionGroup.key === 'requests' ? 'Request sync controls' : sectionGroup.title}
</h2>
{sectionGroup.key === 'sonarr' && (
<button type="button" onClick={() => loadOptions('sonarr')}>
Refresh Sonarr options
</button>
)}
{sectionGroup.key === 'radarr-library' && (
{sectionGroup.key === 'radarr' && (
<button type="button" onClick={() => loadOptions('radarr')}>
Refresh Radarr options
</button>
)}
{sectionGroup.key === 'jellyfin-users' && (
{sectionGroup.key === 'jellyfin' && (
<button type="button" onClick={syncJellyfinUsers}>
Import Jellyfin users
</button>
@@ -2001,7 +1720,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
</button>
</div>
) : null}
{showRequestsExtras && sectionGroup.key === 'requests-sync' && (
{showRequestsExtras && sectionGroup.key === 'requests' && (
<div className="sync-actions-block">
<div className="sync-actions">
<button type="button" onClick={syncRequests}>
@@ -2018,24 +1737,25 @@ export default function SettingsPage({ section }: SettingsPageProps) {
</div>
)}
</div>
{(sectionGroup.description || SECTION_DESCRIPTIONS[sectionGroup.key]) && (
<p className="section-subtitle">
{sectionGroup.description || SECTION_DESCRIPTIONS[sectionGroup.key]}
</p>
)}
{(sectionGroup.description || SECTION_DESCRIPTIONS[sectionGroup.key]) &&
(!settingsSection || isMagentGroupedSection || isSiteGroupedSection) && (
<p className="section-subtitle">
{sectionGroup.description || SECTION_DESCRIPTIONS[sectionGroup.key]}
</p>
)}
{section === 'general' && sectionGroup.key === 'magent-runtime' && (
<div className="status-banner">
Runtime host/port and SSL values are configuration settings. Container/process
restarts may still be required before bind/port changes take effect.
</div>
)}
{sectionGroup.key === 'sonarr-library' && sonarrError && (
{sectionGroup.key === 'sonarr' && sonarrError && (
<div className="error-banner">{sonarrError}</div>
)}
{sectionGroup.key === 'radarr-library' && radarrError && (
{sectionGroup.key === 'radarr' && radarrError && (
<div className="error-banner">{radarrError}</div>
)}
{sectionGroup.key === 'jellyfin-users' && jellyfinSyncStatus && (
{sectionGroup.key === 'jellyfin' && jellyfinSyncStatus && (
<div className="status-banner">{jellyfinSyncStatus}</div>
)}
{showArtworkExtras && sectionGroup.key === 'artwork' && artworkPrefetchStatus && (
@@ -2070,10 +1790,10 @@ export default function SettingsPage({ section }: SettingsPageProps) {
</div>
</div>
)}
{showRequestsExtras && sectionGroup.key === 'requests-sync' && requestsSyncStatus && (
{showRequestsExtras && sectionGroup.key === 'requests' && requestsSyncStatus && (
<div className="status-banner">{requestsSyncStatus}</div>
)}
{showRequestsExtras && sectionGroup.key === 'requests-sync' && (
{showRequestsExtras && sectionGroup.key === 'requests' && (
<div className="status-banner">
Full refresh checks only decide when to run a full refresh. The delta sync interval
polls for new or updated requests.
@@ -2105,7 +1825,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
{artworkPrefetch.message && <div className="meta">{artworkPrefetch.message}</div>}
</div>
)}
{showRequestsExtras && sectionGroup.key === 'requests-sync' && requestsSync && (
{showRequestsExtras && sectionGroup.key === 'requests' && requestsSync && (
<div className="sync-progress">
<div className="sync-meta">
<span>Status: {requestsSync.status}</span>
@@ -2450,8 +2170,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
<input
name={setting.key}
type="number"
min={setting.key === 'issue_confirmation_contact_attempts' ? 0 : 1}
max={setting.key === 'issue_confirmation_contact_attempts' ? 10 : setting.key === 'issue_confirmation_interval_value' ? 365 : undefined}
min={1}
step={1}
value={value}
onChange={(event) =>
@@ -2464,32 +2183,6 @@ export default function SettingsPage({ section }: SettingsPageProps) {
</label>
)
}
if (setting.key === 'issue_confirmation_interval_unit') {
return (
<label key={setting.key} data-helper={helperText || undefined}>
<span className="label-row">
<span>{labelFromKey(setting.key)}</span>
<span className="meta">
{setting.isSet ? `Source: ${setting.source}` : 'Not set'}
</span>
</span>
<select
name={setting.key}
value={value || 'days'}
onChange={(event) =>
setFormValues((current) => ({
...current,
[setting.key]: event.target.value,
}))
}
>
<option value="days">Days</option>
<option value="weeks">Weeks</option>
<option value="months">Months</option>
</select>
</label>
)
}
if (setting.key === 'requests_data_source') {
return (
<label key={setting.key} data-helper={helperText || undefined}>
@@ -2621,7 +2314,7 @@ export default function SettingsPage({ section }: SettingsPageProps) {
onClick={() => void saveSettingGroup(sectionGroup)}
disabled={sectionSaving[sectionGroup.key] || sectionTesting[sectionGroup.key]}
>
{sectionSaving[sectionGroup.key] ? 'Saving...' : `Save ${sectionGroup.title}`}
{sectionSaving[sectionGroup.key] ? 'Saving...' : 'Save section'}
</button>
</div>
</section>
-2
View File
@@ -8,11 +8,9 @@ const ALLOWED_SECTIONS = new Set([
'artwork',
'sonarr',
'radarr',
'bazarr',
'prowlarr',
'qbittorrent',
'requests',
'issue-workflow',
'cache',
'logs',
'maintenance',
File diff suppressed because it is too large Load Diff
-5
View File
@@ -1,5 +0,0 @@
import PortalClient from '../../portal/PortalClient'
export default function AdminIssuesPage() {
return <PortalClient workspace="issue" />
}
+7 -328
View File
@@ -1,345 +1,24 @@
'use client'
import { useEffect, useMemo, useState } from 'react'
import { useRouter } from 'next/navigation'
import { authFetch, clearToken, getApiBase, getToken } from '../lib/auth'
import AdminShell from '../ui/AdminShell'
type ServiceState = {
name: string
status: string
message?: string
}
type RecentRequest = {
id: number
title?: string | null
year?: number | null
statusLabel?: string | null
requestedBy?: string | null
createdAt?: string | null
}
type PortalOverview = {
overview?: {
total_items?: number
total_comments?: number
by_kind?: Record<string, number>
by_status?: Record<string, number>
}
my_items?: number
}
const formatDateTime = (value?: string | null) => {
if (!value) return 'Unknown'
const date = new Date(value)
if (Number.isNaN(date.valueOf())) return value
return date.toLocaleString()
}
const normalizeRecent = (items: any[]): RecentRequest[] =>
items
.filter((item) => item?.id)
.map((item) => ({
id: Number(item.id),
title: item.title ?? null,
year: item.year ?? null,
statusLabel: item.statusLabel ?? null,
requestedBy: item.requestedBy ?? null,
createdAt: item.createdAt ?? null,
}))
export default function AdminLandingPage() {
const router = useRouter()
const [services, setServices] = useState<ServiceState[]>([])
const [serviceOverall, setServiceOverall] = useState('unknown')
const [recent, setRecent] = useState<RecentRequest[]>([])
const [portalOverview, setPortalOverview] = useState<PortalOverview | null>(null)
const [loading, setLoading] = useState(true)
const [error, setError] = useState<string | null>(null)
const [serviceTesting, setServiceTesting] = useState<Record<string, boolean>>({})
const [serviceTestResults, setServiceTestResults] = useState<Record<string, string>>({})
const [serviceCheckedAt, setServiceCheckedAt] = useState<string | null>(null)
useEffect(() => {
if (!getToken()) {
router.push('/login')
return
}
const load = async () => {
setLoading(true)
setError(null)
try {
const baseUrl = getApiBase()
const [meResponse, serviceResponse, recentResponse, overviewResponse] = await Promise.all([
authFetch(`${baseUrl}/auth/me`),
authFetch(`${baseUrl}/status/services`),
authFetch(`${baseUrl}/requests/recent?take=8&days=0`),
authFetch(`${baseUrl}/portal/overview`),
])
if (meResponse.status === 401) {
clearToken()
router.push('/login')
return
}
if (meResponse.status === 403) {
router.push('/')
return
}
const me = await meResponse.json()
if (me?.role !== 'admin') {
router.push('/')
return
}
if (serviceResponse.ok) {
const data = await serviceResponse.json()
setServiceOverall(data?.overall ?? 'unknown')
setServices(Array.isArray(data?.services) ? data.services : [])
setServiceCheckedAt(new Date().toISOString())
}
if (recentResponse.ok) {
const data = await recentResponse.json()
setRecent(Array.isArray(data?.results) ? normalizeRecent(data.results) : [])
}
if (overviewResponse.ok) {
const data = await overviewResponse.json()
setPortalOverview(data)
}
} catch (err) {
console.error(err)
setError('Unable to load the operations dashboard.')
} finally {
setLoading(false)
}
}
void load()
const refreshTimer = window.setInterval(async () => {
try {
const response = await authFetch(`${getApiBase()}/status/services`)
if (!response.ok) return
const data = await response.json()
setServiceOverall(data?.overall ?? 'unknown')
setServices(Array.isArray(data?.services) ? data.services : [])
setServiceCheckedAt(new Date().toISOString())
} catch (err) {
console.error(err)
}
}, 30_000)
return () => window.clearInterval(refreshTimer)
}, [router])
const testService = async (service: ServiceState) => {
const slug = service.name.toLowerCase().replace(/[^a-z0-9]/g, '')
setServiceTesting((current) => ({ ...current, [service.name]: true }))
setServiceTestResults((current) => {
const next = { ...current }
delete next[service.name]
return next
})
try {
const response = await authFetch(`${getApiBase()}/status/services/${slug}/test`, {
method: 'POST',
})
if (!response.ok) {
const text = await response.text()
throw new Error(text || `Service test failed: ${response.status}`)
}
const result = await response.json()
setServices((current) => current.map((item) =>
item.name === service.name
? { ...item, status: result?.status ?? item.status, message: result?.message ?? item.message }
: item
))
setServiceTestResults((current) => ({
...current,
[service.name]: result?.message || (result?.status === 'up' ? 'Connection test passed.' : 'Connection test completed.'),
}))
setServiceCheckedAt(new Date().toISOString())
} catch (err) {
console.error(err)
setServiceTestResults((current) => ({ ...current, [service.name]: 'Connection test failed.' }))
} finally {
setServiceTesting((current) => ({ ...current, [service.name]: false }))
}
}
const serviceCounts = useMemo(() => {
const up = services.filter((service) => service.status === 'up').length
const down = services.filter((service) => service.status === 'down').length
const degraded = services.filter((service) => service.status === 'degraded').length
const notConfigured = services.filter((service) => service.status === 'not_configured').length
return { up, down, degraded, notConfigured, total: services.length }
}, [services])
const issueCount = Number(portalOverview?.overview?.by_kind?.issue ?? 0)
const requestItemCount = Number(portalOverview?.overview?.by_kind?.request ?? 0)
const commentCount = Number(portalOverview?.overview?.total_comments ?? 0)
const rail = (
<div className="admin-rail-stack">
<div className="admin-rail-card">
<span className="admin-rail-eyebrow">Fleet summary</span>
<h2>{serviceCounts.up} of {serviceCounts.total || 0} online</h2>
<p>
{serviceCounts.down + serviceCounts.degraded > 0
? `${serviceCounts.down + serviceCounts.degraded} configured service${serviceCounts.down + serviceCounts.degraded === 1 ? '' : 's'} need attention.`
: 'No configured service is currently reporting a fault.'}
</p>
<a className="admin-rail-action" href="/admin/diagnostics">Open full diagnostics</a>
</div>
<div className="admin-rail-card">
<span className="admin-rail-eyebrow">Quick actions</span>
<div className="quick-action-grid">
<a href="/admin/requests-all">Review requests</a>
<a href="/admin/issues">Manage issues</a>
<a href="/users">User directory</a>
<a href="/admin/logs">Activity log</a>
</div>
</div>
</div>
)
return (
<AdminShell
title="Admin overview"
subtitle="Service health, request movement, issue intake, and the controls that keep Magent running."
rail={rail}
title="Settings"
subtitle="Choose what you want to manage."
actions={
<button type="button" onClick={() => router.push('/admin/diagnostics')}>
Run diagnostics
<button type="button" onClick={() => router.push('/')}>
Back to requests
</button>
}
>
{loading ? <div className="status-banner">Loading operations dashboard...</div> : null}
{error ? <div className="error-banner">{error}</div> : null}
<section className="ops-metric-grid">
<div className="ops-metric-card">
<span className="section-kicker">Services online</span>
<strong>
{serviceCounts.up}/{serviceCounts.total || 0}
</strong>
<p>{serviceOverall === 'up' ? 'All configured services are responding.' : 'Some services need review.'}</p>
</div>
<div className="ops-metric-card">
<span className="section-kicker">Recent requests</span>
<strong>{recent.length}</strong>
<p>Loaded from the live request cache.</p>
</div>
<div className="ops-metric-card">
<span className="section-kicker">Open issue items</span>
<strong>{issueCount}</strong>
<p>{commentCount} portal comments recorded.</p>
</div>
<div className="ops-metric-card">
<span className="section-kicker">Portal requests</span>
<strong>{requestItemCount}</strong>
<p>Tracked in the dedicated request workflow.</p>
</div>
</section>
<section className="admin-zone fleet-status-panel">
<div className="section-header fleet-status-header">
<div>
<span className="section-kicker">Fleet service mesh</span>
<h2>System status</h2>
<p className="section-subtitle">
Admin-only connectivity status for the services used by Magent.
{serviceCheckedAt ? ` Last checked ${formatDateTime(serviceCheckedAt)}.` : ''}
</p>
</div>
<span className={`small-pill system-pill-${serviceOverall}`}>
{serviceOverall.replaceAll('_', ' ')}
</span>
</div>
{services.length === 0 ? (
<div className="status-banner">Service status is not available yet.</div>
) : (
<div className="fleet-service-grid">
{services.map((service) => {
const slug = service.name.toLowerCase().replace(/[^a-z0-9]/g, '')
const testing = Boolean(serviceTesting[service.name])
return (
<article className={`fleet-service-card system-${service.status}`} key={service.name}>
<div className="fleet-service-title">
<span className="system-dot" aria-hidden="true" />
<div>
<h3>{service.name}</h3>
<span className={`small-pill system-pill-${service.status}`}>
{service.status.replaceAll('_', ' ')}
</span>
</div>
</div>
<p>{serviceTestResults[service.name] ?? service.message ?? 'No recent detail was returned.'}</p>
<div className="fleet-service-actions">
<a href={`/admin/${slug}`}>Configure</a>
<button type="button" className="ghost-button" disabled={testing} onClick={() => void testService(service)}>
{testing ? 'Testing...' : 'Test connection'}
</button>
</div>
</article>
)
})}
</div>
)}
</section>
<section className="admin-zone">
<div className="section-header">
<div>
<h2>Recent activity</h2>
<p className="section-subtitle">Live request cache entries, newest first.</p>
</div>
</div>
{recent.length === 0 ? (
<div className="status-banner">No recent requests were returned.</div>
) : (
<div className="admin-table dashboard-activity-table">
<div className="admin-table-head">
<span>Request</span>
<span>Status</span>
<span>User</span>
<span>Created</span>
</div>
{recent.map((row) => (
<button
key={row.id}
type="button"
className="admin-table-row"
onClick={() => router.push(`/requests/${row.id}`)}
>
<span>
{row.title || `Request #${row.id}`}
{row.year ? ` (${row.year})` : ''}
</span>
<span>{row.statusLabel || 'Unknown'}</span>
<span>{row.requestedBy || 'Unknown'}</span>
<span>{formatDateTime(row.createdAt)}</span>
</button>
))}
</div>
)}
</section>
<section className="admin-zone">
<div className="section-header">
<div>
<h2>Attention states</h2>
<p className="section-subtitle">Service states that affect request processing.</p>
</div>
</div>
<div className="ops-status-strip">
<span>{serviceCounts.down} down</span>
<span>{serviceCounts.degraded} degraded</span>
<span>{serviceCounts.notConfigured} not configured</span>
<section className="admin-section">
<div className="status-banner">
Pick a section from the left. Each page explains what it does and how it helps.
</div>
</section>
</AdminShell>
+2 -2
View File
@@ -286,7 +286,7 @@ export default function AdminSystemGuidePage() {
<div className="system-guide-grid">
<article className="system-guide-card">
<h3>Landing page</h3>
<p>Recent request activity refreshes live for signed-in users.</p>
<p>Recent requests and service summaries refresh live for signed-in users.</p>
</article>
<article className="system-guide-card">
<h3>Request pages</h3>
@@ -294,7 +294,7 @@ export default function AdminSystemGuidePage() {
</article>
<article className="system-guide-card">
<h3>Admin views</h3>
<p>Fleet health, diagnostics, logs, sync state, and maintenance data stay in admin-only settings.</p>
<p>Diagnostics, logs, sync state, and maintenance surfaces stream live operational data.</p>
</article>
</div>
</div>
-649
View File
@@ -181,107 +181,6 @@ body {
align-items: center;
}
.signed-in-context {
display: inline-flex;
align-items: center;
gap: 10px;
}
.user-view-toggle {
min-height: 34px;
padding: 7px 12px;
border: 1px solid rgba(126, 215, 255, 0.28);
border-radius: 999px;
background: rgba(14, 165, 233, 0.08);
color: #bfeaff;
box-shadow: none;
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.user-view-toggle.is-active {
border-color: rgba(251, 191, 36, 0.5);
background: rgba(245, 158, 11, 0.13);
color: #fde68a;
}
.user-view-banner {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
margin: 14px 0;
padding: 12px 16px;
border: 1px solid rgba(251, 191, 36, 0.38);
border-radius: 10px;
background: linear-gradient(90deg, rgba(245, 158, 11, 0.13), rgba(14, 165, 233, 0.06));
color: #f8e7b2;
}
.user-view-banner > div {
display: flex;
align-items: baseline;
gap: 12px;
}
.user-view-banner strong {
color: #fde68a;
text-transform: uppercase;
letter-spacing: 0.06em;
}
.user-view-banner span {
color: var(--muted);
}
.user-view-banner button {
flex: 0 0 auto;
padding: 8px 12px;
border-color: rgba(251, 191, 36, 0.32);
background: rgba(245, 158, 11, 0.12);
color: #fde68a;
box-shadow: none;
}
.signed-in-header span {
display: block;
margin-top: 4px;
color: #fde68a;
font-size: 0.72rem;
font-weight: 700;
text-transform: uppercase;
}
@media (max-width: 720px) {
.signed-in-context {
margin-left: auto;
}
.user-view-toggle {
min-height: 30px;
padding: 5px 9px;
font-size: 0.64rem;
}
.user-view-banner {
align-items: stretch;
flex-direction: column;
gap: 10px;
}
.user-view-banner > div {
align-items: flex-start;
flex-direction: column;
gap: 4px;
}
.user-view-banner button {
width: 100%;
}
}
.avatar-button {
width: 44px;
height: 44px;
@@ -4658,51 +4557,6 @@ button:hover:not(:disabled) {
margin-bottom: 12px;
}
.invite-operations-strip {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10px;
margin-bottom: 12px;
}
.invite-operations-strip > button {
display: grid;
gap: 5px;
min-height: 112px;
padding: 14px;
border: 1px solid rgba(126, 215, 255, 0.18);
border-radius: 8px;
background: linear-gradient(135deg, rgba(14, 165, 233, 0.055), rgba(255, 255, 255, 0.018));
text-align: left;
}
.invite-operations-strip > button:hover {
border-color: rgba(126, 215, 255, 0.42);
background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(255, 255, 255, 0.026));
}
.invite-operations-strip span,
.invite-operations-strip small {
color: #9ea7b6;
font-size: 0.7rem;
}
.invite-operations-strip span {
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.invite-operations-strip strong {
color: #eef7ff;
font-size: 1.55rem;
}
.invite-operations-strip small {
align-self: end;
line-height: 1.35;
}
.invite-admin-summary-tile {
min-height: 96px;
}
@@ -4831,128 +4685,6 @@ button:hover:not(:disabled) {
gap: 12px;
}
.invite-automation-card {
gap: 12px;
}
.invite-automation-card > div:first-child {
display: grid;
gap: 4px;
}
.invite-readiness-list {
display: grid;
gap: 6px;
}
.invite-readiness-list > button {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
align-items: center;
gap: 8px;
padding: 9px 10px;
border: 1px solid rgba(255, 255, 255, 0.055);
background: rgba(255, 255, 255, 0.018);
text-align: left;
}
.invite-readiness-list span {
color: #9ea7b6;
font-size: 0.7rem;
}
.invite-readiness-list strong {
color: #dceafa;
font-size: 0.7rem;
white-space: nowrap;
}
.invite-list-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
margin-bottom: 12px;
}
.invite-list-heading h2,
.invite-list-heading p {
margin: 0;
}
.invite-view-filter {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 6px;
min-width: 0;
margin: 0;
padding: 0;
border: 0;
}
.invite-view-filter legend {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
.invite-view-filter button {
padding: 7px 10px;
border-color: rgba(255, 255, 255, 0.07);
background: rgba(255, 255, 255, 0.02);
color: #aeb8c7;
font-size: 0.7rem;
}
.invite-view-filter button.is-active {
border-color: rgba(126, 215, 255, 0.38);
background: rgba(14, 165, 233, 0.1);
color: #eaf8ff;
}
.invite-list-item {
border-left: 3px solid rgba(126, 215, 255, 0.4);
}
.invite-list-item.is-ready {
border-left-color: #48e0b2;
}
.invite-list-item.is-expired,
.invite-list-item.is-exhausted,
.invite-list-item.is-profile_unavailable {
border-left-color: #ffc56d;
}
.invite-list-item.is-disabled {
border-left-color: #7e8999;
}
.invite-state-pill.is-ready {
border-color: rgba(72, 224, 178, 0.32);
color: #69edc5;
}
.invite-state-pill.is-expired,
.invite-state-pill.is-exhausted,
.invite-state-pill.is-profile_unavailable {
border-color: rgba(255, 197, 109, 0.34);
color: #ffd38a;
}
.invite-attention-reason {
margin: 5px 0 0;
color: #ffc56d;
font-size: 0.76rem;
}
.invite-admin-bulk-panel .user-bulk-groups {
display: grid;
gap: 10px;
@@ -5040,328 +4772,6 @@ button:hover:not(:disabled) {
gap: 10px;
}
.invite-expiry-presets {
display: grid;
gap: 7px;
}
.invite-expiry-presets > span {
color: #9ea7b6;
font-size: 0.76rem;
}
.invite-expiry-presets > div {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.invite-expiry-presets button {
padding: 7px 9px;
font-size: 0.7rem;
}
.invite-expiry-presets small {
color: #aeb8c7;
font-size: 0.7rem;
}
.invite-flow-heading {
display: flex;
justify-content: space-between;
gap: 16px;
align-items: flex-start;
margin-bottom: 16px;
}
.invite-flow-heading h2,
.invite-created-card h3,
.invite-flow-step h3 {
margin: 0;
}
.invite-flow-heading .lede {
margin: 4px 0 0;
}
.invite-flow-form {
display: grid;
gap: 12px;
}
.invite-flow-route {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 8px;
margin: 0 0 4px;
padding: 0;
list-style: none;
}
.invite-flow-route li {
position: relative;
display: flex;
gap: 9px;
align-items: center;
min-width: 0;
padding: 10px 12px;
border: 1px solid rgba(138, 155, 185, 0.18);
background: rgba(255, 255, 255, 0.015);
color: #77849a;
}
.invite-flow-route li span {
color: #718095;
font-family: var(--font-mono), monospace;
font-size: 0.68rem;
}
.invite-flow-route li strong {
overflow: hidden;
font-size: 0.76rem;
text-overflow: ellipsis;
}
.invite-flow-route li.is-active {
border-color: rgba(126, 215, 255, 0.5);
background: linear-gradient(135deg, rgba(14, 165, 233, 0.14), rgba(35, 74, 119, 0.11));
color: #edf8ff;
box-shadow: inset 0 2px 0 rgba(126, 215, 255, 0.75);
}
.invite-flow-route li.is-active span,
.invite-flow-route li.is-complete span {
color: #7ed7ff;
}
.invite-flow-route li.is-complete {
border-color: rgba(72, 224, 178, 0.28);
color: #c9d7e5;
}
.invite-flow-step {
overflow: hidden;
border: 1px solid rgba(138, 155, 185, 0.18);
background: linear-gradient(145deg, rgba(31, 43, 65, 0.82), rgba(20, 29, 45, 0.82));
}
.invite-flow-step.is-active {
border-color: rgba(126, 215, 255, 0.38);
box-shadow: inset 0 2px 0 rgba(126, 215, 255, 0.7);
}
.invite-flow-step.is-complete {
border-color: rgba(72, 224, 178, 0.24);
}
.invite-flow-step > header {
display: flex;
gap: 12px;
align-items: flex-start;
padding: 16px;
border-bottom: 1px solid rgba(138, 155, 185, 0.14);
}
.invite-flow-step > header > div {
display: grid;
gap: 3px;
}
.invite-flow-step > header p {
margin: 0;
color: #aeb8c7;
font-size: 0.78rem;
}
.invite-flow-number {
display: grid;
flex: 0 0 34px;
width: 34px;
height: 34px;
place-items: center;
border: 1px solid rgba(126, 215, 255, 0.4);
border-radius: 50%;
color: #7ed7ff;
font-family: var(--font-mono), monospace;
font-size: 0.7rem;
font-weight: 700;
}
.invite-flow-fields {
display: grid;
gap: 12px;
padding: 16px;
}
.invite-flow-fields > label,
.invite-flow-field-grid > label {
display: grid;
gap: 6px;
}
.invite-flow-fields label > span:first-child,
.invite-flow-field-grid label > span:first-child {
color: #cbd5e3;
font-size: 0.72rem;
font-weight: 700;
letter-spacing: 0.035em;
text-transform: uppercase;
}
.invite-flow-fields input:not([type='checkbox']),
.invite-flow-fields select,
.invite-flow-fields textarea {
width: 100%;
}
.invite-flow-fields label > small {
color: #8f9caf;
font-size: 0.7rem;
line-height: 1.4;
}
.invite-flow-field-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12px;
}
.invite-flow-choice-line,
.invite-status-control {
grid-template-columns: auto minmax(0, 1fr);
gap: 10px !important;
align-items: flex-start;
padding: 12px;
border: 1px solid rgba(138, 155, 185, 0.2);
background: rgba(255, 255, 255, 0.02);
cursor: pointer;
}
.invite-flow-choice-line > input,
.invite-status-control > input {
margin-top: 3px;
}
.invite-flow-choice-line > span,
.invite-status-control > span {
display: grid;
gap: 3px;
text-transform: none !important;
}
.invite-flow-choice-line strong,
.invite-status-control strong {
color: #e8edf5;
font-size: 0.8rem;
}
.invite-flow-choice-line small,
.invite-status-control small {
color: #9ba8ba;
font-size: 0.72rem;
font-weight: 400;
letter-spacing: normal;
line-height: 1.4;
}
.invite-flow-actions {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
padding-top: 2px;
}
.invite-policy-note,
.invite-delivery-summary {
display: grid;
gap: 4px;
padding: 12px;
border: 1px solid rgba(72, 224, 178, 0.2);
background: rgba(72, 224, 178, 0.055);
}
.invite-policy-note strong,
.invite-delivery-summary strong {
color: #dffaf1;
font-size: 0.78rem;
}
.invite-policy-note span,
.invite-delivery-summary span {
color: #9fb4b5;
font-size: 0.72rem;
}
.invite-delivery-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 10px;
}
.invite-delivery-grid > button {
display: grid;
gap: 5px;
min-height: 112px;
padding: 14px;
border-color: rgba(138, 155, 185, 0.2);
background: rgba(255, 255, 255, 0.018);
color: #cbd5e3;
text-align: left;
}
.invite-delivery-grid > button strong {
color: #f2f6fb;
font-size: 0.92rem;
}
.invite-delivery-grid > button small {
color: #98a5b7;
font-size: 0.72rem;
font-weight: 400;
line-height: 1.4;
}
.invite-delivery-grid > button.is-selected {
border-color: rgba(126, 215, 255, 0.58);
background: linear-gradient(145deg, rgba(14, 165, 233, 0.16), rgba(35, 74, 119, 0.13));
box-shadow: inset 0 2px 0 #7ed7ff;
}
.invite-status-control {
border-color: rgba(255, 197, 109, 0.27);
background: rgba(255, 197, 109, 0.045);
}
.invite-created-card {
display: grid;
gap: 12px;
padding: 18px;
border: 1px solid rgba(72, 224, 178, 0.38);
background: linear-gradient(145deg, rgba(72, 224, 178, 0.1), rgba(20, 29, 45, 0.72));
box-shadow: inset 0 2px 0 rgba(72, 224, 178, 0.72);
}
.invite-created-card p {
margin: 0;
color: #b7c5d4;
}
.invite-created-card > .ghost-button {
justify-self: start;
}
.invite-created-link {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 8px;
}
.invite-created-link input {
min-width: 0;
font-family: var(--font-mono), monospace;
}
.invite-email-template-picker {
display: flex;
flex-wrap: wrap;
@@ -5421,10 +4831,6 @@ button:hover:not(:disabled) {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.invite-operations-strip {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.invite-admin-bulk-grid {
grid-template-columns: 1fr;
}
@@ -5436,10 +4842,6 @@ button:hover:not(:disabled) {
.invite-form-row-grid {
grid-template-columns: 1fr;
}
.invite-flow-field-grid {
grid-template-columns: 1fr;
}
}
@media (max-width: 980px) {
@@ -5478,19 +4880,6 @@ button:hover:not(:disabled) {
grid-template-columns: 1fr;
}
.invite-operations-strip {
grid-template-columns: 1fr;
}
.invite-list-heading {
align-items: stretch;
flex-direction: column;
}
.invite-view-filter {
justify-content: flex-start;
}
.invite-admin-summary-row {
grid-template-columns: 1fr;
align-items: start;
@@ -5510,29 +4899,6 @@ button:hover:not(:disabled) {
}
}
@media (max-width: 680px) {
.invite-flow-heading {
display: grid;
}
.invite-flow-route {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.invite-delivery-grid,
.invite-created-link {
grid-template-columns: 1fr;
}
.invite-flow-actions {
justify-content: stretch;
}
.invite-flow-actions button {
flex: 1 1 auto;
}
}
/* Enterprise UI tightening pass */
.admin-panel,
.user-detail-panel,
@@ -5643,21 +5009,6 @@ textarea {
background: rgba(255, 255, 255, 0.02);
border-radius: 5px;
overflow: hidden;
margin: 0;
min-inline-size: 0;
padding: 0;
}
.invite-trace-view-toggle legend {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
white-space: nowrap;
width: 1px;
}
.invite-trace-view-toggle button {
+5 -7
View File
@@ -1,12 +1,11 @@
import './globals.css'
import './ops-redesign.css'
import type { ReactNode } from 'react'
import BrandingFavicon from './ui/BrandingFavicon'
import BrandingLogo from './ui/BrandingLogo'
import HeaderActions from './ui/HeaderActions'
import HeaderIdentity from './ui/HeaderIdentity'
import ThemeToggle from './ui/ThemeToggle'
import BrandingFavicon from './ui/BrandingFavicon'
import BrandingLogo from './ui/BrandingLogo'
import SiteStatus from './ui/SiteStatus'
import UserViewBanner from './ui/UserViewBanner'
export const metadata = {
title: 'Magent',
@@ -25,19 +24,18 @@ export default function RootLayout({ children }: { children: ReactNode }) {
<BrandingLogo className="brand-logo brand-logo--header" />
<div className="brand-stack">
<div className="brand">Magent</div>
<div className="tagline">GrizzlyFlix media operations</div>
<div className="tagline">Find and fix media requests fast.</div>
</div>
</a>
</div>
<div className="header-right">
<span className="beta-chip" title="Beta environment">Beta</span>
<ThemeToggle />
<HeaderIdentity />
</div>
<div className="header-nav">
<HeaderActions />
</div>
</header>
<UserViewBanner />
<SiteStatus />
{children}
</div>
-48
View File
@@ -1,48 +0,0 @@
'use client'
import { useEffect, useState } from 'react'
const USER_VIEW_STORAGE_KEY = 'magent_user_view_preview'
const USER_VIEW_EVENT = 'magent:user-view-change'
const readUserViewPreview = () => {
if (typeof window === 'undefined') return false
return window.sessionStorage.getItem(USER_VIEW_STORAGE_KEY) === '1'
}
const applyDocumentMode = (enabled: boolean) => {
if (typeof document === 'undefined') return
document.documentElement.dataset.userView = enabled ? 'true' : 'false'
}
export const setUserViewPreview = (enabled: boolean) => {
if (typeof window === 'undefined') return
if (enabled) {
window.sessionStorage.setItem(USER_VIEW_STORAGE_KEY, '1')
} else {
window.sessionStorage.removeItem(USER_VIEW_STORAGE_KEY)
}
applyDocumentMode(enabled)
window.dispatchEvent(new CustomEvent(USER_VIEW_EVENT, { detail: { enabled } }))
}
export const useUserViewPreview = () => {
const [enabled, setEnabled] = useState(false)
useEffect(() => {
const sync = () => {
const nextValue = readUserViewPreview()
applyDocumentMode(nextValue)
setEnabled(nextValue)
}
sync()
window.addEventListener(USER_VIEW_EVENT, sync)
window.addEventListener('storage', sync)
return () => {
window.removeEventListener(USER_VIEW_EVENT, sync)
window.removeEventListener('storage', sync)
}
}, [])
return enabled
}
+7 -20
View File
@@ -108,17 +108,10 @@ export default function LoginPage() {
})()
return (
<main className="auth-screen">
<section className="auth-hero">
<div className="auth-mark">
<BrandingLogo className="brand-logo brand-logo--login" />
</div>
<div className="auth-title-block">
<span className="section-kicker">Secure access</span>
<h1>Magent operational gateway</h1>
<p>{loginHelpText}</p>
</div>
</section>
<main className="card auth-card">
<BrandingLogo className="brand-logo brand-logo--login" />
<h1>Sign in</h1>
<p className="lede">{loginHelpText}</p>
<form
onSubmit={(event) => {
if (!primaryMode) {
@@ -128,25 +121,23 @@ export default function LoginPage() {
}
void submit(event, primaryMode)
}}
className="auth-form auth-panel"
className="auth-form"
>
<label>
<span>Username</span>
Username
<input
value={username}
onChange={(event) => setUsername(event.target.value)}
autoComplete="username"
placeholder="Enter your username"
/>
</label>
<label>
<span>Password</span>
Password
<input
type="password"
value={password}
onChange={(event) => setPassword(event.target.value)}
autoComplete="current-password"
placeholder="Enter your password"
/>
</label>
{error && <div className="error-banner">{error}</div>}
@@ -180,10 +171,6 @@ export default function LoginPage() {
{!loginOptions.showJellyfinLogin && !loginOptions.showLocalLogin ? (
<div className="error-banner">Login is currently disabled. Contact an administrator.</div>
) : null}
<div className="auth-footnote">
<span className="live-dot" aria-hidden="true" />
Beta environment
</div>
</form>
</main>
)
@@ -1,507 +0,0 @@
'use client'
import { useEffect, useRef, useState } from 'react'
import { useRouter } from 'next/navigation'
import { authFetch, clearToken, getApiBase, getToken } from '../lib/auth'
type MediaType = 'movie' | 'tv'
type DiscoveryResult = {
title: string
year?: number | null
type: MediaType
tmdbId: number
requestId?: number | null
statusLabel?: string | null
overview?: string | null
posterPath?: string | null
backdropPath?: string | null
}
type RequestOptions = {
media: DiscoveryResult & {
seasons: Array<{
seasonNumber: number
name: string
episodeCount: number
airDate?: string | null
}>
existingRequestId?: number | null
}
destination: {
collector: 'Sonarr' | 'Radarr'
serverName: string
defaultProfileId: number
profiles: Array<{ id: number; name: string }>
}
}
type OperationEvent = {
id: string
service: string
state: 'active' | 'complete' | 'error'
message: string
duration_ms?: number | null
status_code?: number | null
}
type OperationProgress = {
status: 'running' | 'complete' | 'error'
duration_ms?: number | null
events: OperationEvent[]
}
const mediaChoices: Array<{
type: MediaType
eyebrow: string
title: string
description: string
collector: 'Radarr' | 'Sonarr'
icon: string
}> = [
{
type: 'movie',
eyebrow: 'Film',
title: 'Movie',
description: 'Find a film and send it through Seerr to Radarr.',
collector: 'Radarr',
icon: '/service-icons/radarr.svg',
},
{
type: 'tv',
eyebrow: 'Series',
title: 'TV show',
description: 'Choose a series, the seasons you want, and send it to Sonarr.',
collector: 'Sonarr',
icon: '/service-icons/sonarr.svg',
},
]
const artworkUrl = (path?: string | null, size: 'w185' | 'w342' = 'w342') => {
if (!path) return null
return `https://image.tmdb.org/t/p/${size}${path.startsWith('/') ? path : `/${path}`}`
}
const apiError = async (response: Response, fallback: string) => {
try {
const payload = await response.json()
if (typeof payload?.detail === 'string' && payload.detail.trim()) return payload.detail
if (typeof payload?.message === 'string' && payload.message.trim()) return payload.message
} catch {
// The upstream response was not JSON. Use the friendly fallback below.
}
return fallback
}
const formatDuration = (milliseconds?: number | null) => {
if (milliseconds == null) return null
if (milliseconds < 1000) return `${Math.round(milliseconds)} ms`
return `${(milliseconds / 1000).toFixed(1)} s`
}
export default function NewRequestClient() {
const router = useRouter()
const searchSectionRef = useRef<HTMLElement | null>(null)
const resultsSectionRef = useRef<HTMLElement | null>(null)
const configureSectionRef = useRef<HTMLElement | null>(null)
const [mediaType, setMediaType] = useState<MediaType | null>(null)
const [query, setQuery] = useState('')
const [searching, setSearching] = useState(false)
const [searchAttempted, setSearchAttempted] = useState(false)
const [results, setResults] = useState<DiscoveryResult[]>([])
const [selected, setSelected] = useState<DiscoveryResult | null>(null)
const [options, setOptions] = useState<RequestOptions | null>(null)
const [loadingOptions, setLoadingOptions] = useState(false)
const [profileId, setProfileId] = useState<number | null>(null)
const [selectedSeasons, setSelectedSeasons] = useState<number[]>([])
const [submitting, setSubmitting] = useState(false)
const [operation, setOperation] = useState<OperationProgress | null>(null)
const [error, setError] = useState<string | null>(null)
const [success, setSuccess] = useState<string | null>(null)
useEffect(() => {
if (!getToken()) router.push('/login')
}, [router])
const resetAfterType = (nextType: MediaType) => {
setMediaType(nextType)
setQuery('')
setResults([])
setSearchAttempted(false)
setSelected(null)
setOptions(null)
setProfileId(null)
setSelectedSeasons([])
setOperation(null)
setError(null)
setSuccess(null)
window.setTimeout(() => searchSectionRef.current?.scrollIntoView({ behavior: 'smooth', block: 'center' }), 80)
}
const runSearch = async (event: React.FormEvent) => {
event.preventDefault()
if (!mediaType) return
const term = query.trim()
if (!term) {
setError('Enter a title to search for.')
return
}
setSearching(true)
setSearchAttempted(true)
setSelected(null)
setOptions(null)
setOperation(null)
setError(null)
setSuccess(null)
try {
const baseUrl = getApiBase()
const params = new URLSearchParams({ query: term, media_type: mediaType })
const response = await authFetch(`${baseUrl}/requests/search?${params.toString()}`)
if (response.status === 401) {
clearToken()
router.push('/login')
return
}
if (!response.ok) throw new Error(await apiError(response, `Search failed (${response.status}).`))
const payload = await response.json()
const mapped: DiscoveryResult[] = Array.isArray(payload?.results)
? payload.results
.filter((item: any) => item?.type === mediaType && Number(item?.tmdbId) > 0)
.map((item: any) => ({
title: String(item?.title || 'Untitled'),
year: typeof item?.year === 'number' ? item.year : null,
type: mediaType,
tmdbId: Number(item.tmdbId),
requestId: typeof item?.requestId === 'number' ? item.requestId : null,
statusLabel: typeof item?.statusLabel === 'string' ? item.statusLabel : null,
overview: typeof item?.overview === 'string' ? item.overview : null,
posterPath: item?.posterPath ?? null,
backdropPath: item?.backdropPath ?? null,
}))
: []
setResults(mapped)
window.setTimeout(() => resultsSectionRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }), 80)
} catch (caught) {
setResults([])
setError(caught instanceof Error ? caught.message : 'Search is unavailable right now.')
} finally {
setSearching(false)
}
}
const selectResult = async (item: DiscoveryResult) => {
setSelected(item)
setOptions(null)
setProfileId(null)
setSelectedSeasons([])
setOperation(null)
setError(null)
setSuccess(null)
if (item.requestId) {
window.setTimeout(() => configureSectionRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }), 80)
return
}
setLoadingOptions(true)
try {
const baseUrl = getApiBase()
const params = new URLSearchParams({ media_type: item.type, tmdb_id: String(item.tmdbId) })
const response = await authFetch(`${baseUrl}/requests/request-options?${params.toString()}`)
if (response.status === 401) {
clearToken()
router.push('/login')
return
}
if (!response.ok) throw new Error(await apiError(response, `Could not load request options (${response.status}).`))
const payload = (await response.json()) as RequestOptions
const refreshedSelection: DiscoveryResult = {
...item,
title: payload.media.title || item.title,
year: payload.media.year ?? item.year,
overview: payload.media.overview || item.overview,
posterPath: payload.media.posterPath || item.posterPath,
backdropPath: payload.media.backdropPath || item.backdropPath,
requestId: payload.media.existingRequestId || item.requestId,
statusLabel: payload.media.existingRequestId ? 'Already requested' : item.statusLabel,
}
setSelected(refreshedSelection)
if (payload.media.existingRequestId) {
setResults((current) => current.map((result) => result.tmdbId === item.tmdbId && result.type === item.type
? refreshedSelection
: result))
return
}
setOptions(payload)
setProfileId(payload.destination.defaultProfileId)
setSelectedSeasons(payload.media.seasons.map((season) => season.seasonNumber))
} catch (caught) {
setError(caught instanceof Error ? caught.message : 'Could not load request options.')
} finally {
setLoadingOptions(false)
window.setTimeout(() => configureSectionRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' }), 80)
}
}
const pollOperation = async (operationId: string) => {
try {
const response = await authFetch(`${getApiBase()}/operations/${operationId}`)
if (response.ok) setOperation((await response.json()) as OperationProgress)
} catch {
// The request response remains authoritative if a progress poll is interrupted.
}
}
const submitRequest = async () => {
if (!selected || !options || !profileId) return
if (selected.type === 'tv' && selectedSeasons.length === 0) {
setError('Select at least one season.')
return
}
setSubmitting(true)
setError(null)
setSuccess(null)
const operationId = globalThis.crypto?.randomUUID?.() ?? `request-${Date.now()}`
setOperation({ status: 'running', events: [] })
const interval = window.setInterval(() => void pollOperation(operationId), 500)
try {
const response = await authFetch(`${getApiBase()}/requests/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Magent-Operation-ID': operationId,
'X-Magent-Operation-Label': `Requesting ${selected.title}`,
},
body: JSON.stringify({
mediaType: selected.type,
tmdbId: selected.tmdbId,
profileId,
seasons: selected.type === 'tv' ? selectedSeasons : undefined,
}),
})
await pollOperation(operationId)
if (response.status === 401) {
clearToken()
router.push('/login')
return
}
if (!response.ok) throw new Error(await apiError(response, `Request failed (${response.status}).`))
const payload = await response.json()
const requestId = typeof payload?.requestId === 'number' ? payload.requestId : null
setSelected((current) => current ? { ...current, requestId, statusLabel: payload?.statusLabel ?? current.statusLabel } : current)
setResults((current) => current.map((item) => item.tmdbId === selected.tmdbId && item.type === selected.type
? { ...item, requestId, statusLabel: payload?.statusLabel ?? item.statusLabel }
: item))
setSuccess(requestId ? `Request #${requestId} has been accepted by Seerr.` : 'Your request has been accepted by Seerr.')
} catch (caught) {
setError(caught instanceof Error ? caught.message : 'The request could not be submitted.')
} finally {
window.clearInterval(interval)
await pollOperation(operationId)
setSubmitting(false)
}
}
const setEverySeason = (checked: boolean) => {
setSelectedSeasons(checked && options ? options.media.seasons.map((season) => season.seasonNumber) : [])
}
const selectedPoster = artworkUrl(selected?.posterPath, 'w185')
return (
<main className="card request-portal-page">
<header className="request-portal-hero">
<div>
<span className="section-kicker">New requests</span>
<h1>Find something worth watching.</h1>
<p>Choose what you want, find the right title, then tailor the request before it goes to Seerr.</p>
</div>
<div className="request-portal-route">
<span>Seerr</span><i aria-hidden="true" />
<span>{mediaType === 'tv' ? 'Sonarr' : mediaType === 'movie' ? 'Radarr' : 'Collector'}</span><i aria-hidden="true" />
<span>Grizzlyflix</span>
</div>
</header>
{error && <div className="error-banner request-flow-alert">{error}</div>}
{success && <div className="status-banner request-flow-alert">{success}</div>}
<section className="request-flow-stage is-current">
<div className="request-flow-heading">
<span className="request-flow-number">01</span>
<div><span>Start here</span><h2>What are you looking for?</h2></div>
</div>
<div className="request-type-grid">
{mediaChoices.map((choice) => (
<button
key={choice.type}
type="button"
className={`request-type-card ${mediaType === choice.type ? 'is-selected' : ''}`}
onClick={() => resetAfterType(choice.type)}
aria-pressed={mediaType === choice.type}
>
<span className="request-type-card-body">
<span className="request-service-icon">
<img src={choice.icon} alt={`${choice.collector} logo`} />
</span>
<span className="request-type-card-copy">
<span>{choice.eyebrow}</span>
<strong>{choice.title}</strong>
<span className="request-type-description">{choice.description}</span>
<b>{mediaType === choice.type ? 'Selected' : `Choose ${choice.title.toLowerCase()}`}</b>
</span>
</span>
</button>
))}
</div>
</section>
{mediaType && (
<section ref={searchSectionRef} className="request-flow-stage is-current">
<div className="request-flow-heading">
<span className="request-flow-number">02</span>
<div><span>{mediaType === 'tv' ? 'TV show selected' : 'Movie selected'}</span><h2>Search for the title</h2></div>
</div>
<form className="request-flow-search" onSubmit={runSearch}>
<label htmlFor="request-title-search">Title</label>
<div>
<input
id="request-title-search"
value={query}
onChange={(event) => setQuery(event.target.value)}
placeholder={mediaType === 'tv' ? 'Search TV shows' : 'Search movies'}
autoComplete="off"
/>
<button type="submit" disabled={searching}>{searching ? 'Searching…' : 'Search Seerr'}</button>
</div>
</form>
</section>
)}
{mediaType && searchAttempted && !searching && (
<section ref={resultsSectionRef} className="request-flow-stage is-current">
<div className="request-flow-heading">
<span className="request-flow-number">03</span>
<div><span>Search results</span><h2>{results.length ? 'Select the right title' : 'No matches found'}</h2></div>
</div>
{results.length === 0 ? (
<div className="request-flow-empty">
<strong>Nothing matched {query.trim()}.</strong>
<p>Check the spelling or try a shorter title.</p>
</div>
) : (
<div className="request-result-grid">
{results.map((item) => {
const poster = artworkUrl(item.posterPath)
const isSelected = selected?.tmdbId === item.tmdbId && selected.type === item.type
return (
<button
key={`${item.type}:${item.tmdbId}`}
type="button"
className={`request-result-card ${isSelected ? 'is-selected' : ''}`}
onClick={() => void selectResult(item)}
>
<span className="request-result-poster">
{poster ? <img src={poster} alt="" loading="lazy" /> : <i>No artwork</i>}
</span>
<span className="request-result-copy">
<small>{item.type === 'tv' ? 'TV show' : 'Movie'}{item.year ? ` · ${item.year}` : ''}</small>
<strong>{item.title}</strong>
<p>{item.overview || 'Select this title to view the available request options.'}</p>
<b>{item.requestId ? item.statusLabel || 'Already requested' : isSelected ? 'Selected' : 'Select title'}</b>
</span>
</button>
)
})}
</div>
)}
</section>
)}
{selected && (
<section ref={configureSectionRef} className="request-flow-stage is-current request-configure-stage">
<div className="request-flow-heading">
<span className="request-flow-number">04</span>
<div><span>Final step</span><h2>{selected.requestId ? 'This title is already in the pipeline' : 'Configure your request'}</h2></div>
</div>
<div className="request-selection-summary">
<span className="request-selection-poster">
{selectedPoster ? <img src={selectedPoster} alt="" /> : <i>No artwork</i>}
</span>
<div>
<small>{selected.type === 'tv' ? 'TV show' : 'Movie'}{selected.year ? ` · ${selected.year}` : ''}</small>
<h3>{selected.title}</h3>
<p>{selected.overview || 'Ready to configure.'}</p>
</div>
</div>
{selected.requestId ? (
<div className="request-existing-state">
<div><span>Current status</span><strong>{selected.statusLabel || 'Already requested'}</strong><p>Request #{selected.requestId} is already being tracked by Magent.</p></div>
<button type="button" onClick={() => router.push(`/requests/${selected.requestId}`)}>Open request</button>
</div>
) : loadingOptions ? (
<div className="request-flow-empty"><strong>Checking Seerr and {selected.type === 'tv' ? 'Sonarr' : 'Radarr'}</strong><p>Loading valid profiles and request choices.</p></div>
) : options ? (
<div className="request-options-layout">
{selected.type === 'tv' && (
<fieldset className="request-season-picker">
<legend>Which seasons?</legend>
<div className="request-season-actions">
<button type="button" onClick={() => setEverySeason(true)}>Select all</button>
<button type="button" onClick={() => setEverySeason(false)}>Clear</button>
</div>
<div className="request-season-grid">
{options.media.seasons.map((season) => (
<label key={season.seasonNumber} className={selectedSeasons.includes(season.seasonNumber) ? 'is-selected' : ''}>
<input
type="checkbox"
checked={selectedSeasons.includes(season.seasonNumber)}
onChange={(event) => setSelectedSeasons((current) => event.target.checked
? [...current, season.seasonNumber].sort((a, b) => a - b)
: current.filter((value) => value !== season.seasonNumber))}
/>
<span><strong>{season.name}</strong><small>{season.episodeCount} episode{season.episodeCount === 1 ? '' : 's'}</small></span>
</label>
))}
</div>
</fieldset>
)}
<label className="request-profile-field">
<span>Quality profile</span>
<select value={profileId ?? ''} onChange={(event) => setProfileId(Number(event.target.value))}>
{options.destination.profiles.map((profile) => <option key={profile.id} value={profile.id}>{profile.name}</option>)}
</select>
<small>Live options from {options.destination.collector}. Seerr will use {options.destination.serverName}.</small>
</label>
<div className="request-submit-bar">
<div><span>Delivery route</span><strong>Seerr {options.destination.collector} Grizzlyflix</strong><small>Only settings currently accepted by {options.destination.collector} are available.</small></div>
<button type="button" onClick={() => void submitRequest()} disabled={submitting || !profileId || (selected.type === 'tv' && selectedSeasons.length === 0)}>
{submitting ? 'Sending request…' : `Request ${selected.type === 'tv' ? 'show' : 'movie'}`}
</button>
</div>
</div>
) : null}
{operation && (
<div className={`request-submit-progress is-${operation.status}`} aria-live="polite">
<header><div><span>Remote activity</span><strong>{operation.status === 'running' ? 'Sending your request' : operation.status === 'complete' ? 'Request hand-off complete' : 'Request hand-off needs attention'}</strong></div>{formatDuration(operation.duration_ms) && <small>{formatDuration(operation.duration_ms)}</small>}</header>
<div>
{operation.events.map((event) => (
<p key={event.id} className={`is-${event.state}`}><i aria-hidden="true" /><span><strong>{event.service}</strong>{event.message}</span><small>{formatDuration(event.duration_ms)}{event.status_code ? ` · HTTP ${event.status_code}` : ''}</small></p>
))}
{operation.events.length === 0 && <p className="is-active"><i aria-hidden="true" /><span><strong>Magent</strong>Preparing the request</span></p>}
</div>
</div>
)}
{success && selected.requestId && (
<div className="request-complete-actions"><button type="button" onClick={() => router.push(`/requests/${selected.requestId}`)}>Track request #{selected.requestId}</button><button type="button" className="ghost-button" onClick={() => resetAfterType(selected.type)}>Request something else</button></div>
)}
</section>
)}
</main>
)
}
-9
View File
@@ -1,9 +0,0 @@
import NewRequestClient from './NewRequestClient'
export const metadata = {
title: 'New Requests | Magent',
}
export default function NewRequestsPage() {
return <NewRequestClient />
}
File diff suppressed because it is too large Load Diff
+344 -147
View File
@@ -64,6 +64,14 @@ export default function HomePage() {
const [recentDays, setRecentDays] = useState(90)
const [recentStage, setRecentStage] = useState('all')
const [authReady, setAuthReady] = useState(false)
const [servicesStatus, setServicesStatus] = useState<
{ overall: string; services: { name: string; status: string; message?: string }[] } | null
>(null)
const [servicesLoading, setServicesLoading] = useState(false)
const [servicesError, setServicesError] = useState<string | null>(null)
const [serviceTesting, setServiceTesting] = useState<Record<string, boolean>>({})
const [serviceTestResults, setServiceTestResults] = useState<Record<string, string | null>>({})
const [liveStreamConnected, setLiveStreamConnected] = useState(false)
const submit = (event: React.FormEvent) => {
event.preventDefault()
@@ -76,6 +84,61 @@ export default function HomePage() {
void runSearch(trimmed)
}
const toServiceSlug = (name: string) => name.toLowerCase().replace(/[^a-z0-9]/g, '')
const updateServiceStatus = (name: string, status: string, message?: string) => {
setServicesStatus((prev) => {
if (!prev) return prev
return {
...prev,
services: prev.services.map((service) =>
service.name === name ? { ...service, status, message } : service
),
}
})
}
const testService = async (name: string) => {
const slug = toServiceSlug(name)
setServiceTesting((prev) => ({ ...prev, [name]: true }))
setServiceTestResults((prev) => ({ ...prev, [name]: null }))
try {
const baseUrl = getApiBase()
const response = await authFetch(`${baseUrl}/status/services/${slug}/test`, {
method: 'POST',
})
if (!response.ok) {
if (response.status === 401) {
clearToken()
router.push('/login')
return
}
const text = await response.text()
throw new Error(text || `Service test failed: ${response.status}`)
}
const data = await response.json()
const status = data?.status ?? 'unknown'
const message =
data?.message ||
(status === 'up'
? 'API OK'
: status === 'down'
? 'API unreachable'
: status === 'degraded'
? 'Health warnings'
: status === 'not_configured'
? 'Not configured'
: 'Unknown')
setServiceTestResults((prev) => ({ ...prev, [name]: message }))
updateServiceStatus(name, status, data?.message)
} catch (error) {
console.error(error)
setServiceTestResults((prev) => ({ ...prev, [name]: 'Test failed' }))
} finally {
setServiceTesting((prev) => ({ ...prev, [name]: false }))
}
}
useEffect(() => {
if (!getToken()) {
router.push('/login')
@@ -135,7 +198,45 @@ export default function HomePage() {
if (!authReady) {
return
}
const load = async () => {
setServicesLoading(true)
setServicesError(null)
try {
const baseUrl = getApiBase()
const response = await authFetch(`${baseUrl}/status/services`)
if (!response.ok) {
if (response.status === 401) {
clearToken()
router.push('/login')
return
}
throw new Error(`Service status failed: ${response.status}`)
}
const data = await response.json()
setServicesStatus(data)
} catch (error) {
console.error(error)
setServicesError('Service status is not available right now.')
} finally {
setServicesLoading(false)
}
}
void load()
if (liveStreamConnected) {
return
}
const timer = setInterval(load, 30000)
return () => clearInterval(timer)
}, [authReady, liveStreamConnected, router])
useEffect(() => {
if (!authReady) {
setLiveStreamConnected(false)
return
}
if (!getToken()) {
setLiveStreamConnected(false)
return
}
const baseUrl = getApiBase()
@@ -156,8 +257,14 @@ export default function HomePage() {
const streamUrl = `${baseUrl}/events/stream?${params.toString()}`
source = new EventSource(streamUrl)
source.onopen = () => {
if (closed) return
setLiveStreamConnected(true)
}
source.onmessage = (event) => {
if (closed) return
setLiveStreamConnected(true)
try {
const payload = JSON.parse(event.data)
if (!payload || typeof payload !== 'object') {
@@ -174,14 +281,29 @@ export default function HomePage() {
}
return
}
if (payload.type === 'home_services') {
if (payload.status && typeof payload.status === 'object') {
setServicesStatus(payload.status)
setServicesError(null)
setServicesLoading(false)
} else if (typeof payload.error === 'string' && payload.error.trim()) {
setServicesError('Service status is not available right now.')
setServicesLoading(false)
}
}
} catch (error) {
console.error(error)
}
}
source.onerror = () => {
if (closed) return
setLiveStreamConnected(false)
}
} catch (error) {
if (closed) return
console.error(error)
setLiveStreamConnected(false)
}
}
@@ -189,6 +311,7 @@ export default function HomePage() {
return () => {
closed = true
setLiveStreamConnected(false)
source?.close()
}
}, [authReady, recentDays, recentStage])
@@ -239,156 +362,230 @@ export default function HomePage() {
return date.toLocaleString()
}
const activeRecentCount = recent.filter((item) => {
const label = String(item.statusLabel ?? '').toLowerCase()
return !label.includes('ready') && !label.includes('available') && !label.includes('declined')
}).length
const readyRecentCount = recent.filter((item) => {
const label = String(item.statusLabel ?? '').toLowerCase()
return label.includes('ready') || label.includes('available')
}).length
return (
<main className="card home-page">
<section className="home-command">
<div className="home-command-copy">
<span className="section-kicker">Request lookup</span>
<h1>My requests</h1>
<p>
Enter a title and year, or jump straight to a request using its request number.
</p>
</div>
<form onSubmit={submit} className="home-search">
<label htmlFor="request-search">Title, year, or request number</label>
<div className="home-search-row">
<input
id="request-search"
value={query}
onChange={(event) => setQuery(event.target.value)}
placeholder="Dune 2021 or 1289"
/>
<button type="submit">Find request</button>
</div>
</form>
</section>
{(searchError || searchResults.length > 0) && (
<section className="home-search-results" aria-live="polite">
<div className="home-section-heading">
<div>
<span className="section-kicker">Search results</span>
<h2>{searchError ? 'Search unavailable' : `${searchResults.length} match${searchResults.length === 1 ? '' : 'es'} found`}</h2>
</div>
<button type="button" className="ghost-button" onClick={() => {
setSearchResults([])
setSearchError(null)
}}>
Clear
</button>
</div>
{searchError ? (
<div className="error-banner">{searchError}</div>
) : (
<div className="home-result-grid">
{searchResults.map((item, index) => (
<button
key={`${item.title || 'Untitled'}-${index}`}
type="button"
className="home-result-card"
disabled={!item.requestId}
onClick={() => item.requestId && router.push(`/requests/${item.requestId}`)}
<main className="card">
<div className="layout-grid">
<section className="recent centerpiece">
<div className="system-status">
<div className="system-header">
<h2>System status</h2>
<span
className={`system-pill system-pill-${servicesStatus?.overall ?? 'unknown'}`}
>
<span>
<strong>{item.title || 'Untitled'}{item.year ? ` (${item.year})` : ''}</strong>
<small>{item.type?.toUpperCase() || 'MEDIA'}</small>
</span>
<span>{!item.requestId ? 'Not requested' : item.statusLabel || 'Already requested'}</span>
</button>
))}
</div>
)}
</section>
)}
<section className="home-metric-strip" aria-label="Request summary">
<div><span>In view</span><strong>{recent.length}</strong></div>
<div><span>In progress</span><strong>{activeRecentCount}</strong></div>
<div><span>Ready</span><strong>{readyRecentCount}</strong></div>
</section>
<section className="recent home-recent">
<div className="recent-header home-section-heading">
<div>
<span className="section-kicker">Request activity</span>
<h2>{role === 'admin' ? 'Recent requests' : 'My recent requests'}</h2>
</div>
{authReady && (
<div className="recent-filter-group">
<label className="recent-filter">
<span>Period</span>
<select value={recentDays} onChange={(event) => setRecentDays(Number(event.target.value))}>
<option value={0}>All time</option>
<option value={30}>30 days</option>
<option value={60}>60 days</option>
<option value={90}>90 days</option>
<option value={180}>180 days</option>
</select>
</label>
<label className="recent-filter">
<span>Stage</span>
<select value={recentStage} onChange={(event) => setRecentStage(event.target.value)}>
{REQUEST_STAGE_OPTIONS.map((option) => (
<option key={option.value} value={option.value}>{option.label}</option>
))}
</select>
</label>
</div>
)}
</div>
<div className="recent-grid home-recent-grid">
{recentLoading ? (
<div className="loading-center">
<div className="spinner" aria-hidden="true" />
<span className="loading-text">Loading recent requests...</span>
</div>
) : recentError ? (
<div className="error-banner">{recentError}</div>
) : recent.length === 0 ? (
<div className="home-empty-state">
<strong>No requests match these filters</strong>
<span>Try a wider period or a different stage.</span>
</div>
) : (
recent.map((item) => (
<button
key={item.id}
type="button"
onClick={() => router.push(`/requests/${item.id}`)}
className="recent-card"
>
{item.artwork?.poster_url ? (
<img
className="recent-poster"
src={resolveArtworkUrl(item.artwork.poster_url) ?? ''}
alt=""
loading="lazy"
/>
) : (
<span className="recent-poster recent-poster-placeholder" aria-hidden="true">#{item.id}</span>
)}
<span className="recent-info">
<span className="recent-title">{item.title || 'Untitled'}{item.year ? ` (${item.year})` : ''}</span>
<span className="recent-meta">
{item.statusLabel || 'Status not available yet'} · Request {item.id}
{item.createdAt ? ` · ${formatRequestTime(item.createdAt)}` : ''}
</span>
{servicesLoading
? 'Checking services...'
: servicesError
? 'Status not available yet'
: servicesStatus?.overall === 'up'
? 'Services are up and running'
: servicesStatus?.overall === 'down'
? 'Something is down'
: 'Some services need attention'}
</span>
<span className="recent-open-cue" aria-hidden="true">Open</span>
</button>
))
)}
</div>
</section>
</div>
<div className="system-list">
{(() => {
const order = [
'Seerr',
'Sonarr',
'Radarr',
'Prowlarr',
'qBittorrent',
'Jellyfin',
]
const items = servicesStatus?.services ?? []
return order.map((name) => {
const item = items.find((entry) => entry.name === name)
const status = item?.status ?? 'unknown'
const testing = serviceTesting[name] ?? false
return (
<div key={name} className={`system-item system-${status}`}>
<span className="system-dot" />
<div className="system-meta">
<span className="system-name">{name}</span>
{serviceTestResults[name] && (
<span className="system-test-message">{serviceTestResults[name]}</span>
)}
</div>
<div className="system-actions">
<span className="system-state">
{status === 'up'
? 'Up'
: status === 'down'
? 'Down'
: status === 'degraded'
? 'Needs attention'
: status === 'not_configured'
? 'Not configured'
: 'Unknown'}
</span>
<button
type="button"
className="system-test"
onClick={() => void testService(name)}
disabled={testing}
>
{testing ? 'Testing...' : 'Test'}
</button>
</div>
</div>
)
})
})()}
</div>
</div>
<div className="recent-header">
<h2>{role === 'admin' ? 'All requests' : 'My recent requests'}</h2>
{authReady && (
<div className="recent-filter-group">
<label className="recent-filter">
<span>Show</span>
<select
value={recentDays}
onChange={(event) => setRecentDays(Number(event.target.value))}
>
<option value={0}>All</option>
<option value={30}>30 days</option>
<option value={60}>60 days</option>
<option value={90}>90 days</option>
<option value={180}>180 days</option>
</select>
</label>
<label className="recent-filter">
<span>Stage</span>
<select
value={recentStage}
onChange={(event) => setRecentStage(event.target.value)}
>
{REQUEST_STAGE_OPTIONS.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
</label>
</div>
)}
</div>
<div className="recent-grid">
{recentLoading ? (
<div className="loading-center">
<div className="spinner" aria-hidden="true" />
<span className="loading-text">Loading recent requests</span>
</div>
) : recentError ? (
<button type="button" disabled>
{recentError}
</button>
) : recent.length === 0 ? (
<button type="button" disabled>
No recent requests found
</button>
) : (
recent.map((item) => (
<button
key={item.id}
type="button"
onClick={() => router.push(`/requests/${item.id}`)}
className="recent-card"
>
{item.artwork?.poster_url && (
<img
className="recent-poster"
src={resolveArtworkUrl(item.artwork.poster_url) ?? ''}
alt=""
loading="lazy"
/>
)}
<span className="recent-info">
<span className="recent-title">
{item.title || 'Untitled'}
{item.year ? ` (${item.year})` : ''}
</span>
<span className="recent-meta">
{item.statusLabel ? item.statusLabel : 'Status not available yet'} · Request{' '}
{item.id}
{item.createdAt ? ` · ${formatRequestTime(item.createdAt)}` : ''}
</span>
</span>
</button>
))
)}
</div>
</section>
<aside className="side-panel">
<section className="main-panel find-panel">
<div className="find-header">
<h1>Search all requests</h1>
<p className="lede">
Search any request by title + year or request number and see whether it already
exists in the system.
</p>
</div>
<div className="find-controls">
<form onSubmit={submit} className="search search-row">
<input
value={query}
onChange={(event) => setQuery(event.target.value)}
placeholder="e.g. Dune 2021 or 1289"
/>
<button type="submit">Check status</button>
</form>
<div className="filters filters-compact">
<div className="filter">
<span>Type</span>
<div className="pill-group">
<button type="button">TV</button>
<button type="button">Movie</button>
</div>
</div>
<div className="filter">
<span>Status</span>
<div className="pill-group">
<button type="button">Pending</button>
<button type="button">Approved</button>
<button type="button">Processing</button>
<button type="button">Failed</button>
<button type="button">Available</button>
</div>
</div>
</div>
</div>
<section className="recent results-panel">
<h2>Search results</h2>
<div className="recent-grid">
{searchError ? (
<button type="button" disabled>
{searchError}
</button>
) : searchResults.length === 0 ? (
<button type="button" disabled>
No matches yet
</button>
) : (
searchResults.map((item, index) => (
<button
key={`${item.title || 'Untitled'}-${index}`}
type="button"
disabled={!item.requestId}
onClick={() =>
item.requestId && router.push(`/requests/${item.requestId}`)
}
>
{item.title || 'Untitled'} {item.year ? `(${item.year})` : ''}{' '}
{!item.requestId
? '- not requested'
: item.statusLabel
? `- ${item.statusLabel}`
: '- already requested'}
</button>
))
)}
</div>
</section>
</section>
</aside>
</div>
</main>
)
}
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -1,5 +1,6 @@
import { redirect } from 'next/navigation'
export default function PortalIndexPage() {
redirect('/new-requests')
redirect('/portal/requests')
}
+3 -2
View File
@@ -1,5 +1,6 @@
import { redirect } from 'next/navigation'
import PortalClient from '../PortalClient'
export default function RequestPortalPage() {
redirect('/new-requests')
return <PortalClient workspace="request" />
}
+40 -2
View File
@@ -1,7 +1,7 @@
'use client'
import { useRouter } from 'next/navigation'
import { useEffect, useMemo, useState } from 'react'
import { useRouter } from 'next/navigation'
import { authFetch, clearToken, getApiBase, getToken } from '../../lib/auth'
type ProfileInfo = {
@@ -315,9 +315,47 @@ export default function ProfileInvitesPage() {
<main className="card">
<div className="user-directory-panel-header profile-page-header">
<div>
<h1>Invites</h1>
<h1>My invites</h1>
<p className="lede">Create invite links, email them directly, and track who you have invited.</p>
</div>
<div className="admin-inline-actions">
<button type="button" className="ghost-button" onClick={() => router.push('/profile')}>
Back to profile
</button>
</div>
</div>
{profile ? (
<div className="status-banner">
Signed in as <strong>{profile.username}</strong> ({profile.role}).
</div>
) : null}
<div className="profile-tabbar">
<div className="admin-segmented" role="tablist" aria-label="Profile sections">
<button type="button" role="tab" aria-selected={false} onClick={() => router.push('/profile')}>
Overview
</button>
<button
type="button"
role="tab"
aria-selected={false}
onClick={() => router.push('/profile?tab=activity')}
>
Activity
</button>
<button type="button" role="tab" aria-selected className="is-active">
My invites
</button>
<button
type="button"
role="tab"
aria-selected={false}
onClick={() => router.push('/profile?tab=security')}
>
Security
</button>
</div>
</div>
{inviteError && <div className="error-banner">{inviteError}</div>}
+6 -1
View File
@@ -1,7 +1,7 @@
'use client'
import { useRouter } from 'next/navigation'
import { useEffect, useMemo, useState } from 'react'
import { useRouter } from 'next/navigation'
import { authFetch, clearToken, getApiBase, getToken } from '../lib/auth'
type ProfileInfo = {
@@ -265,6 +265,11 @@ export default function ProfilePage() {
>
Activity
</button>
{canManageInvites ? (
<button type="button" role="tab" aria-selected={false} onClick={() => router.push(inviteLink)}>
My invites
</button>
) : null}
<button
type="button"
role="tab"
File diff suppressed because it is too large Load Diff
-1
View File
@@ -22,7 +22,6 @@ export default function AdminShell({ title, subtitle, actions, rail, children }:
<main className="card admin-card">
<div className="admin-header">
<div>
<span className="section-kicker">Beta stream</span>
<h1>{title}</h1>
{subtitle && <p className="lede">{subtitle}</p>}
</div>
+10 -27
View File
@@ -4,50 +4,35 @@ import { usePathname } from 'next/navigation'
const NAV_GROUPS = [
{
title: 'Configuration',
items: [
{ href: '/admin', label: 'Config overview' },
{ href: '/admin/general', label: 'Application & proxy' },
{ href: '/admin/site', label: 'Site & login' },
{ href: '/admin/notifications', label: 'Notifications' },
],
},
{
title: 'Media Services',
title: 'Services',
items: [
{ href: '/admin/general', label: 'General' },
{ href: '/admin/seerr', label: 'Seerr' },
{ href: '/admin/jellyfin', label: 'Jellyfin' },
{ href: '/admin/sonarr', label: 'Sonarr' },
{ href: '/admin/radarr', label: 'Radarr' },
{ href: '/admin/bazarr', label: 'Bazarr' },
{ href: '/admin/prowlarr', label: 'Prowlarr' },
{ href: '/admin/qbittorrent', label: 'qBittorrent' },
],
},
{
title: 'Request Pipeline',
title: 'Requests',
items: [
{ href: '/admin/requests', label: 'Sync & retention' },
{ href: '/admin/issue-workflow', label: 'Issue workflow' },
{ href: '/admin/cache', label: 'Request cache' },
{ href: '/admin/artwork', label: 'Artwork cache' },
{ href: '/admin/requests', label: 'Request sync' },
{ href: '/admin/requests-all', label: 'All requests' },
{ href: '/admin/cache', label: 'Cache Control' },
],
},
{
title: 'Users & Access',
title: 'Admin',
items: [
{ href: '/admin/notifications', label: 'Notifications' },
{ href: '/admin/system', label: 'How it works' },
{ href: '/admin/site', label: 'Site' },
{ href: '/users', label: 'Users' },
{ href: '/admin/invites', label: 'Invite management' },
],
},
{
title: 'System',
items: [
{ href: '/admin/diagnostics', label: 'System health' },
{ href: '/admin/logs', label: 'Activity log' },
{ href: '/admin/maintenance', label: 'Maintenance' },
{ href: '/admin/system', label: 'How it works' },
],
},
]
@@ -64,9 +49,7 @@ export default function AdminSidebar() {
{group.items.map((item) => {
const isActive =
pathname === item.href ||
(item.href !== '/' &&
item.href !== '/admin' &&
pathname.startsWith(`${item.href}/`))
(item.href !== '/' && pathname.startsWith(item.href))
return (
<a key={item.href} href={item.href} className={isActive ? 'is-active' : ''}>
{item.label}
+5 -35
View File
@@ -1,44 +1,14 @@
'use client'
import { useState } from 'react'
type BrandingLogoProps = {
className?: string
alt?: string
}
export default function BrandingLogo({ className, alt = 'Magent logo' }: BrandingLogoProps) {
const [loaded, setLoaded] = useState(false)
const [failed, setFailed] = useState(false)
return (
<span className={`${className ?? ''} branding-logo-shell`} role="img" aria-label={alt}>
{!failed ? (
<img
className={loaded ? 'is-loaded' : undefined}
src="/api/branding/logo.png"
alt=""
aria-hidden="true"
onLoad={() => setLoaded(true)}
onError={() => setFailed(true)}
/>
) : null}
{!loaded ? (
<svg aria-hidden="true" viewBox="0 0 64 64" focusable="false">
<defs>
<linearGradient id="magentLogoGlow" x1="0" y1="0" x2="1" y2="1">
<stop offset="0%" stopColor="#7ed7ff" />
<stop offset="100%" stopColor="#c6c1ff" />
</linearGradient>
</defs>
<rect width="64" height="64" rx="12" fill="#0b1328" />
<rect x="6" y="6" width="52" height="52" rx="9" fill="#111a33" />
<path
d="M16 48V16h8l8 13 8-13h8v32h-8V30l-8 12-8-12v18h-8z"
fill="url(#magentLogoGlow)"
/>
</svg>
) : null}
</span>
<img
className={className}
src="/api/branding/logo.png"
alt={alt}
/>
)
}
+14 -86
View File
@@ -1,46 +1,29 @@
'use client'
import { usePathname } from 'next/navigation'
import { useEffect, useState } from 'react'
import { authFetch, clearToken, getApiBase, getToken } from '../lib/auth'
export default function HeaderActions() {
const [signedIn, setSignedIn] = useState(false)
const [role, setRole] = useState<string | null>(null)
const [showRequestsNav, setShowRequestsNav] = useState(true)
const pathname = usePathname()
useEffect(() => {
const token = getToken()
setSignedIn(Boolean(token))
if (!token) {
setShowRequestsNav(true)
return
}
const load = async () => {
try {
const baseUrl = getApiBase()
const [response, siteResponse] = await Promise.all([
authFetch(`${baseUrl}/auth/me`),
fetch(`${baseUrl}/site/public`).catch(() => null),
])
const response = await authFetch(`${baseUrl}/auth/me`)
if (!response.ok) {
clearToken()
setSignedIn(false)
setRole(null)
return
}
const data = await response.json()
setRole(data?.role ?? null)
if (siteResponse?.ok) {
const siteData = await siteResponse.json()
setShowRequestsNav(siteData?.navigation?.showRequests !== false)
} else {
setShowRequestsNav(true)
}
await response.json()
} catch (err) {
console.error(err)
setShowRequestsNav(true)
}
}
void load()
@@ -50,73 +33,18 @@ export default function HeaderActions() {
return null
}
const roleItems =
role === null
? []
: role === 'admin'
? [
{
href: '/profile/invites',
label: 'Invites',
match: (path: string) => path.startsWith('/profile/invites'),
},
{
href: '/admin',
label: 'Config',
match: (path: string) => path.startsWith('/admin'),
},
]
: [
{
href: '/profile',
label: 'Profile',
match: (path: string) => path.startsWith('/profile') && !path.startsWith('/profile/invites'),
},
{
href: '/profile/invites',
label: 'Invites',
match: (path: string) => path.startsWith('/profile/invites'),
},
]
const commonItems = [
{
href: '/',
label: 'My Requests',
match: (path: string) => path === '/' || path.startsWith('/requests/'),
},
...(showRequestsNav
? [
{
href: '/new-requests',
label: 'New Requests',
match: (path: string) => path === '/new-requests',
},
]
: []),
{
href: '/portal/issues',
label: 'Issues',
match: (path: string) => path === '/portal/issues' || path === '/admin/issues',
},
]
const items = [
...commonItems,
...roleItems,
]
return (
<nav className="header-actions" aria-label="Primary">
{items.map((item, index) => {
const active = item.match(pathname)
return (
<a key={item.href} href={item.href} className={active ? 'is-active' : undefined}>
<span aria-hidden="true">{String(index + 1).padStart(2, '0')}</span>
{item.label}
</a>
)
})}
</nav>
<div className="header-actions">
<a className="header-cta header-cta--left" href="/feedback">Send feedback</a>
<div className="header-actions-center">
<a href="/how-it-works">How it works</a>
</div>
<div className="header-actions-right">
<a href="/">Requests</a>
<a href="/profile/invites">Invites</a>
<a href="/portal/requests">Portal</a>
<a href="/portal/issues">Issues</a>
</div>
</div>
)
}
+31 -52
View File
@@ -2,13 +2,11 @@
import { useEffect, useState } from 'react'
import { authFetch, clearToken, getApiBase, getToken, logout } from '../lib/auth'
import { setUserViewPreview, useUserViewPreview } from '../lib/viewMode'
export default function HeaderIdentity() {
const [identity, setIdentity] = useState<{ username: string; role?: string } | null>(null)
const [buildNumber, setBuildNumber] = useState<string | null>(null)
const [open, setOpen] = useState(false)
const viewAsUser = useUserViewPreview()
useEffect(() => {
const token = getToken()
@@ -29,9 +27,6 @@ export default function HeaderIdentity() {
const data = await response.json()
if (data?.username) {
setIdentity({ username: data.username, role: data.role })
if (data.role !== 'admin') {
setUserViewPreview(false)
}
}
const siteResponse = await fetch(`${baseUrl}/site/public`)
if (siteResponse.ok) {
@@ -55,7 +50,6 @@ export default function HeaderIdentity() {
const label = `${identity.username}${identity.role ? ` (${identity.role})` : ''}`
const initial = identity.username.slice(0, 1).toUpperCase()
const signOut = async () => {
setUserViewPreview(false)
await logout().catch(() => undefined)
clearToken()
if (typeof window !== 'undefined') {
@@ -64,54 +58,39 @@ export default function HeaderIdentity() {
}
return (
<div className="signed-in-context">
{identity.role === 'admin' ? (
<button
type="button"
className={`user-view-toggle ${viewAsUser ? 'is-active' : ''}`}
aria-pressed={viewAsUser}
onClick={() => setUserViewPreview(!viewAsUser)}
>
{viewAsUser ? 'Exit user view' : 'View as user'}
</button>
) : null}
<div className="signed-in-menu">
<button
type="button"
className="avatar-button"
onClick={() => setOpen((prev) => !prev)}
aria-haspopup="true"
aria-expanded={open}
title={label}
>
{initial}
</button>
{open && (
<div className="signed-in-dropdown">
<div className="signed-in-header">
Signed in as {label}
{viewAsUser ? <span>Previewing user view</span> : null}
</div>
<div className="signed-in-actions">
<a href="/profile" onClick={() => setOpen(false)}>
My profile
<div className="signed-in-menu">
<button
type="button"
className="avatar-button"
onClick={() => setOpen((prev) => !prev)}
aria-haspopup="true"
aria-expanded={open}
title={label}
>
{initial}
</button>
{open && (
<div className="signed-in-dropdown">
<div className="signed-in-header">Signed in as {label}</div>
<div className="signed-in-actions">
<a href="/profile" onClick={() => setOpen(false)}>
My profile
</a>
{identity.role === 'admin' ? (
<a href="/admin" onClick={() => setOpen(false)}>
Settings
</a>
{identity.role === 'admin' ? (
<a href="/admin" onClick={() => setOpen(false)}>
Settings
</a>
) : null}
<a href="/changelog" onClick={() => setOpen(false)}>
Changelog
</a>
<button type="button" className="signed-in-signout" onClick={() => void signOut()}>
Sign out
</button>
</div>
{buildNumber ? <div className="signed-in-build">Build {buildNumber}</div> : null}
) : null}
<a href="/changelog" onClick={() => setOpen(false)}>
Changelog
</a>
<button type="button" className="signed-in-signout" onClick={() => void signOut()}>
Sign out
</button>
</div>
)}
</div>
{buildNumber ? <div className="signed-in-build">Build {buildNumber}</div> : null}
</div>
)}
</div>
)
}
-21
View File
@@ -1,21 +0,0 @@
'use client'
import { setUserViewPreview, useUserViewPreview } from '../lib/viewMode'
export default function UserViewBanner() {
const enabled = useUserViewPreview()
if (!enabled) return null
return (
<div className="user-view-banner" role="status">
<div>
<strong>User view</strong>
<span>You are previewing the non-admin experience. Your account and backend permissions remain admin.</span>
</div>
<button type="button" onClick={() => setUserViewPreview(false)}>
Exit user view
</button>
</div>
)
}
-91
View File
@@ -101,10 +101,8 @@ export default function UserDetailPage() {
const [profiles, setProfiles] = useState<UserProfileOption[]>([])
const [profileSelection, setProfileSelection] = useState('')
const [expiryInput, setExpiryInput] = useState('')
const [emailInput, setEmailInput] = useState('')
const [savingProfile, setSavingProfile] = useState(false)
const [savingExpiry, setSavingExpiry] = useState(false)
const [savingEmail, setSavingEmail] = useState(false)
const [systemActionBusy, setSystemActionBusy] = useState(false)
const [actionStatus, setActionStatus] = useState<string | null>(null)
const [lineage, setLineage] = useState<UserLineage>(null)
@@ -167,7 +165,6 @@ export default function UserDetailPage() {
: String(nextUser.profile_id)
)
setExpiryInput(toLocalDateTimeInput(nextUser?.expires_at))
setEmailInput(nextUser?.email ?? '')
setError(null)
} catch (err) {
console.error(err)
@@ -221,47 +218,6 @@ export default function UserDetailPage() {
}
}
const saveUserEmail = async (clear = false) => {
if (!user) return
const email = clear ? '' : emailInput.trim()
if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
setError('Enter a valid email address.')
setActionStatus(null)
return
}
setSavingEmail(true)
setError(null)
setActionStatus(null)
try {
const response = await authFetch(
`${getApiBase()}/admin/users/${encodeURIComponent(user.username)}/email`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: email || null }),
}
)
const text = await response.text()
let data: any = null
try {
data = text ? JSON.parse(text) : null
} catch {
data = null
}
if (!response.ok) {
throw new Error(data?.detail || text || 'Email update failed')
}
setEmailInput(data?.user?.email ?? '')
await loadUser()
setActionStatus(email ? 'Contact email saved.' : 'Contact email removed.')
} catch (err) {
console.error(err)
setError(err instanceof Error ? err.message : 'Could not update the contact email.')
} finally {
setSavingEmail(false)
}
}
const updateAutoSearchEnabled = async (enabled: boolean) => {
if (!user) return
try {
@@ -590,53 +546,6 @@ export default function UserDetailPage() {
</div>
<div className="user-detail-side-column">
<div className="admin-panel user-detail-panel">
<div className="user-detail-panel-header">
<h2>Contact email</h2>
<p className="lede">Used by Magent for account recovery and issue updates.</p>
</div>
<form
className="user-detail-actions user-detail-actions--stacked"
onSubmit={(event) => {
event.preventDefault()
void saveUserEmail()
}}
>
<label>
<span className="user-bulk-label">Email address</span>
<input
type="email"
value={emailInput}
onChange={(event) => setEmailInput(event.target.value)}
placeholder="person@example.com"
autoComplete="off"
disabled={savingEmail}
/>
</label>
<div className="user-detail-helper">
This updates Magent only. It does not change the user&apos;s Jellyfin or Seerr account.
</div>
<div className="admin-inline-actions">
<button
type="submit"
disabled={savingEmail || !emailInput.trim() || emailInput.trim() === (user.email ?? '')}
>
{savingEmail ? 'Saving...' : user.email ? 'Save email' : 'Add email'}
</button>
{user.email && (
<button
type="button"
className="ghost-button"
onClick={() => void saveUserEmail(true)}
disabled={savingEmail}
>
Remove email
</button>
)}
</div>
</form>
</div>
<div className="admin-panel user-detail-panel">
<div className="user-detail-panel-header">
<h2>Access controls</h2>
-31
View File
@@ -1,31 +0,0 @@
{
"$schema": "https://biomejs.dev/schemas/2.5.6/schema.json",
"files": {
"includes": [
"app/**/*.{ts,tsx}",
"next.config.js",
"!node_modules",
"!.next"
]
},
"formatter": {
"enabled": false
},
"linter": {
"enabled": true,
"rules": {
"preset": "recommended",
"correctness": {
"useExhaustiveDependencies": "off"
},
"performance": {
"noImgElement": "off"
},
"suspicious": {
"noArrayIndexKey": "off",
"noDocumentCookie": "off",
"noExplicitAny": "off"
}
}
}
}
+214 -486
View File
File diff suppressed because it is too large Load Diff
+8 -10
View File
@@ -6,23 +6,21 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "biome lint ."
"lint": "next lint"
},
"dependencies": {
"next": "16.2.12",
"next": "16.1.6",
"react": "19.2.4",
"react-dom": "19.2.4"
},
"devDependencies": {
"@biomejs/biome": "2.5.6",
"typescript": "5.9.3",
"@types/node": "24.11.0",
"@types/react": "19.2.14",
"@types/react-dom": "19.2.3",
"typescript": "5.9.3"
},
"overrides": {
"nanoid": "3.3.18",
"postcss": "8.5.25",
"sharp": "0.35.3"
"@types/react-dom": "19.2.3"
}
}
-7
View File
@@ -1,7 +0,0 @@
<svg width="1024" height="1024" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg">
<g transform="translate(70 21.00012)">
<path d="M105.302 154.943L112.824 869.492C52.651 877.014 7.52158 846.927 7.52158 786.755L0 192.55C0 4.51106 172.996-40.6184 278.298 34.5974L812.33 342.982C887.546 395.633 902.589 493.413 864.981 561.107 857.46 508.456 834.895 478.37 789.765 448.284L188.039 109.813C142.91 79.7268 105.302 87.2484 105.302 154.943Z" fill="#24292E"/>
<path d="M0 376.079C45.1295 391.122 90.259 383.6 127.867 361.036L744.636 0C782.244 52.651 774.723 105.302 729.593 135.388L210.604 436.251C135.388 473.859 37.6079 436.251 0 376.079Z" transform="translate(60.17249 531.0214)" fill="#24292E"/>
<path d="M0 413.687L368.557 203.083 7.52157 0 0 413.687Z" transform="translate(240.6902 282.8092)" fill="#FFC230"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 846 B

-9
View File
@@ -1,9 +0,0 @@
<svg height="216.9" viewBox="0 0 216.7 216.9" width="216.7" xmlns="http://www.w3.org/2000/svg">
<path clip-rule="evenodd" d="M216.7 108.45c0 29.833-10.533 55.4-31.6 76.7-.7.833-1.483 1.6-2.35 2.3-3.466 3.4-7.133 6.484-11 9.25-18.267 13.467-39.367 20.2-63.3 20.2-23.967 0-45.033-6.733-63.2-20.2-4.8-3.4-9.3-7.25-13.5-11.55-16.367-16.266-26.417-35.167-30.15-56.7-.733-4.2-1.217-8.467-1.45-12.8-.1-2.4-.15-4.8-.15-7.2 0-2.533.05-4.95.15-7.25 0-.233.066-.467.2-.7 1.567-26.6 12.033-49.583 31.4-68.95C53.05 10.517 78.617 0 108.45 0c29.933 0 55.484 10.517 76.65 31.55 21.067 21.433 31.6 47.067 31.6 76.9z" fill="#EEE" fill-rule="evenodd"/>
<path clip-rule="evenodd" d="M194.65 42.5l-22.4 22.4C159.152 77.998 158 89.4 158 109.5c0 17.934 2.852 34.352 16.2 47.7 9.746 9.746 19 18.95 19 18.95-2.5 3.067-5.2 6.067-8.1 9-.7.833-1.483 1.6-2.35 2.3-2.533 2.5-5.167 4.817-7.9 6.95l-17.55-17.55c-15.598-15.6-27.996-17.1-48.6-17.1-19.77 0-33.223 1.822-47.7 16.3-8.647 8.647-18.55 18.6-18.55 18.6-3.767-2.867-7.333-6.034-10.7-9.5-2.8-2.8-5.417-5.667-7.85-8.6 0 0 9.798-9.848 19.15-19.2 13.852-13.853 16.1-29.916 16.1-47.85 0-17.5-2.874-33.823-15.6-46.55-8.835-8.836-21.05-21-21.05-21 2.833-3.6 5.917-7.067 9.25-10.4 2.934-2.867 5.934-5.55 9-8.05L61.1 43.85C74.102 56.852 90.767 60.2 108.7 60.2c18.467 0 35.077-3.577 48.6-17.1 8.32-8.32 19.3-19.25 19.3-19.25 2.9 2.367 5.733 4.933 8.5 7.7 3.467 3.533 6.65 7.183 9.55 10.95z" fill="#3A3F51" fill-rule="evenodd"/>
<g clip-rule="evenodd">
<path d="M78.7 114c-.2-1.167-.332-2.35-.4-3.55-.032-.667-.05-1.333-.05-2 0-.7.018-1.367.05-2 0-.067.018-.133.05-.2.435-7.367 3.334-13.733 8.7-19.1 5.9-5.833 12.984-8.75 21.25-8.75 8.3 0 15.384 2.917 21.25 8.75 5.834 5.934 8.75 13.033 8.75 21.3 0 8.267-2.916 15.35-8.75 21.25-.2.233-.416.45-.65.65-.966.933-1.982 1.783-3.05 2.55-5.065 3.733-10.916 5.6-17.55 5.6s-12.466-1.866-17.5-5.6c-1.332-.934-2.582-2-3.75-3.2-4.532-4.5-7.316-9.734-8.35-15.7z" fill="#0CF" fill-rule="evenodd"/>
<path d="M157.8 59.75l-15 14.65M30.785 32.526L71.65 73.25m84.6 84.25l27.808 28.78m1.855-153.894L157.8 59.75m-125.45 126l27.35-27.4" fill="none" stroke="#0CF" stroke-miterlimit="1" stroke-width="2"/>
<path d="M157.8 59.75l-16.95 17.2M58.97 60.604l17.2 17.15M59.623 158.43l16.75-17.4m61.928-1.396l18.028 17.945" fill="none" stroke="#0CF" stroke-miterlimit="1" stroke-width="7"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

-65
View File
@@ -1,65 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
deploy_host="${DEPLOY_HOST:-AMS-DEV01}"
deploy_user="${DEPLOY_USER:-zak}"
prod_path="${PROD_DEPLOY_PATH:-/home/${deploy_user}/magent}"
deploy_path="${BETA_DEPLOY_PATH:-/home/${deploy_user}/magent-beta}"
beta_frontend_bind="${BETA_FRONTEND_BIND:-10.30.1.32}"
ssh_opts="${DEPLOY_SSH_OPTS:-"-o StrictHostKeyChecking=accept-new"}"
timestamp="$(date -u +%Y%m%dT%H%M%SZ)"
remote="${deploy_user}@${deploy_host}"
echo "Deploying tracked beta repository contents to ${remote}:${deploy_path}"
git archive --format=tar HEAD | ssh ${ssh_opts} "${remote}" "
set -e
mkdir -p '${deploy_path}'
backup_root=\"\${HOME}/magent-beta-backups/${timestamp}\"
mkdir -p \"\${backup_root}\"
cd '${deploy_path}'
for path in backend frontend docker-compose.yml docker-compose.hub.yml docker-compose.beta.yml Dockerfile README.md docker scripts .build_number .gitattributes .gitignore; do
if [ -e \"\$path\" ]; then
cp -a \"\$path\" \"\${backup_root}/\"
fi
done
tar -xf - -C '${deploy_path}'
if [ ! -f '${deploy_path}/.env' ] && [ -f '${prod_path}/.env' ]; then
cp '${prod_path}/.env' '${deploy_path}/.env'
fi
mkdir -p '${deploy_path}/data'
if [ ! -f '${deploy_path}/data/magent.db' ] && [ -d '${prod_path}/data' ]; then
cp -a '${prod_path}/data/.' '${deploy_path}/data/'
fi
cd '${deploy_path}'
docker compose -p magent-beta -f docker-compose.beta.yml build
docker compose -p magent-beta -f docker-compose.beta.yml up -d
"
echo "Running remote beta smoke checks"
ssh ${ssh_opts} "${remote}" "
set -e
python3 - <<'PY'
from urllib import request
checks = [
('http://127.0.0.1:8100/health', 200),
('http://${beta_frontend_bind}:3100/login', 200),
]
for url, expected in checks:
with request.urlopen(url, timeout=20) as response:
if response.status != expected:
raise SystemExit(f'{url} returned {response.status}, expected {expected}')
print(url, response.status)
PY
"
echo "Beta deployment completed successfully"
-1
View File
@@ -2,7 +2,6 @@ $ErrorActionPreference = "Stop"
$repoRoot = Resolve-Path "$PSScriptRoot\.."
Set-Location $repoRoot
$env:PYTHONIOENCODING = "utf-8"
function Assert-LastExitCode {
param([Parameter(Mandatory = $true)][string]$CommandName)