Hide header actions when signed out

This commit is contained in:
2026-01-23 19:16:17 +13:00
parent 49e9ee771f
commit 24685a5371
4 changed files with 21 additions and 13 deletions

View File

@@ -56,6 +56,9 @@ class QBittorrentClient(ApiClient):
async def get_torrents_by_hashes(self, hashes: str) -> Optional[Any]: async def get_torrents_by_hashes(self, hashes: str) -> Optional[Any]:
return await self._get("/api/v2/torrents/info", params={"hashes": hashes}) return await self._get("/api/v2/torrents/info", params={"hashes": hashes})
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_app_version(self) -> Optional[Any]: async def get_app_version(self) -> Optional[Any]:
return await self._get_text("/api/v2/app/version") return await self._get_text("/api/v2/app/version")

View File

@@ -1591,7 +1591,7 @@ async def action_grab(
if not qbit.configured(): if not qbit.configured():
raise HTTPException(status_code=400, detail="qBittorrent not configured") raise HTTPException(status_code=400, detail="qBittorrent not configured")
try: try:
await qbit.add_torrent_url(str(download_url)) await qbit.add_torrent_url(str(download_url), category=f"magent-{request_id}")
except httpx.HTTPStatusError as qbit_exc: except httpx.HTTPStatusError as qbit_exc:
raise HTTPException(status_code=502, detail=str(qbit_exc)) from qbit_exc raise HTTPException(status_code=502, detail=str(qbit_exc)) from qbit_exc
await asyncio.to_thread( await asyncio.to_thread(
@@ -1625,7 +1625,7 @@ async def action_grab(
if not qbit.configured(): if not qbit.configured():
raise HTTPException(status_code=400, detail="qBittorrent not configured") raise HTTPException(status_code=400, detail="qBittorrent not configured")
try: try:
await qbit.add_torrent_url(str(download_url)) await qbit.add_torrent_url(str(download_url), category=f"magent-{request_id}")
except httpx.HTTPStatusError as qbit_exc: except httpx.HTTPStatusError as qbit_exc:
raise HTTPException(status_code=502, detail=str(qbit_exc)) from qbit_exc raise HTTPException(status_code=502, detail=str(qbit_exc)) from qbit_exc
await asyncio.to_thread( await asyncio.to_thread(

View File

@@ -465,9 +465,14 @@ async def build_snapshot(request_id: str) -> Snapshot:
try: try:
download_ids = _download_ids(_queue_records(arr_queue)) download_ids = _download_ids(_queue_records(arr_queue))
torrent_list: List[Dict[str, Any]] = [] torrent_list: List[Dict[str, Any]] = []
if download_ids and qbittorrent.configured(): if qbittorrent.configured():
torrents = await qbittorrent.get_torrents_by_hashes("|".join(download_ids)) if download_ids:
torrent_list = torrents if isinstance(torrents, list) else [] torrents = await qbittorrent.get_torrents_by_hashes("|".join(download_ids))
torrent_list = torrents if isinstance(torrents, list) else []
else:
category = f"magent-{request_id}"
torrents = await qbittorrent.get_torrents_by_category(category)
torrent_list = torrents if isinstance(torrents, list) else []
summary = _summarize_qbit(torrent_list) summary = _summarize_qbit(torrent_list)
qbit_state = summary.get("state") qbit_state = summary.get("state")
qbit_message = summary.get("message") qbit_message = summary.get("message")

View File

@@ -40,19 +40,19 @@ export default function HeaderActions() {
} }
} }
if (!signedIn) {
return null
}
return ( return (
<div className="header-actions"> <div className="header-actions">
<a href="/">Requests</a> <a href="/">Requests</a>
<a href="/how-it-works">How it works</a> <a href="/how-it-works">How it works</a>
{signedIn && <a href="/profile">My profile</a>} <a href="/profile">My profile</a>
{role === 'admin' && <a href="/admin">Settings</a>} {role === 'admin' && <a href="/admin">Settings</a>}
{signedIn ? ( <button type="button" className="header-link" onClick={signOut}>
<button type="button" className="header-link" onClick={signOut}> Sign out
Sign out </button>
</button>
) : (
<a href="/login">Sign in</a>
)}
</div> </div>
) )
} }