Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Redirect to `/login` when session is no longer valid.
nzbdav-dev0fef4721b443
diff --git a/frontend/app/routes/_index/components/live-usenet-connections/live-usenet-connections.tsx b/frontend/app/routes/_index/components/live-usenet-connections/live-usenet-connections.tsxindex e63f0c1e..3bea6f21 100644--- a/frontend/app/routes/_index/components/live-usenet-connections/live-usenet-connections.tsx+++ b/frontend/app/routes/_index/components/live-usenet-connections/live-usenet-connections.tsx@@ -1,10 +1,12 @@import { useEffect, useState } from "react";import styles from "./live-usenet-connections.module.css";import { receiveMessage } from "~/utils/websocket-util";+import { useNavigate } from "react-router";const usenetConnectionsTopic = {'cxs': 'state'};export function LiveUsenetConnections() {+ const navigate = useNavigate();const [connections, setConnections] = useState<string | null>(null);const parts = (connections || "0|1|0").split("|");const [live, max, idle] = parts.map(x => Number(x));@@ -19,10 +21,15 @@ export function LiveUsenetConnections() {ws = new WebSocket(window.location.origin.replace(/^http/, 'ws'));ws.onmessage = receiveMessage((_, message) => setConnections(message));ws.onopen = () => ws.send(JSON.stringify(usenetConnectionsTopic));- ws.onclose = () => { !disposed && setTimeout(() => connect(), 1000); setConnections(null) };ws.onerror = () => { ws.close() };+ ws.onclose = onClose;return () => { disposed = true; ws.close(); }}+ function onClose(e: CloseEvent) {+ if (e.code == 1008) navigate('/login');+ !disposed && setTimeout(() => connect(), 1000);+ setConnections(null);+ }return connect();}, [setConnections]);diff --git a/frontend/server/websocket.server.ts b/frontend/server/websocket.server.tsindex b4986b1d..c5086aed 100644--- a/frontend/server/websocket.server.ts+++ b/frontend/server/websocket.server.ts@@ -17,7 +17,6 @@ function initializeWebsocketServer(wss: WebSocketServer) {const session = await sessionStorage.getSession(cookieHeader);const user = session.get("user");if (!user) {- console.warn("Websocket authentication failed. Sign in required.");ws.close(1008, "Unauthorized");return;}@@ -58,7 +57,6 @@ function initializeWebsocketServer(wss: WebSocketServer) {return;}} else {- console.warn("Websocket authentication failed. Sign in required.");ws.close(1008, "Unauthorized");return;}