Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Limit queue and history frontend page to 100 items each.

nzbdav-devd08f26992c86
diff --git a/frontend/app/clients/backend-client.server.ts b/frontend/app/clients/backend-client.server.ts
index 874b4aac..9e6de450 100644
--- a/frontend/app/clients/backend-client.server.ts
+++ b/frontend/app/clients/backend-client.server.ts
@@ -67,8 +67,8 @@ class BackendClient {
return data.authenticated;
}
- public async getQueue(): Promise<QueueResponse> {
- const url = process.env.BACKEND_URL + "/api?mode=queue";
+ public async getQueue(limit: number): Promise<QueueResponse> {
+ const url = process.env.BACKEND_URL + `/api?mode=queue&limit=${limit}`;
const apiKey = process.env.FRONTEND_BACKEND_API_KEY || "";
const response = await fetch(url, { headers: { "x-api-key": apiKey } });
@@ -80,8 +80,8 @@ class BackendClient {
return data.queue;
}
- public async getHistory(): Promise<HistoryResponse> {
- const url = process.env.BACKEND_URL + "/api?mode=history";
+ public async getHistory(limit: number): Promise<HistoryResponse> {
+ const url = process.env.BACKEND_URL + `/api?mode=history&pageSize=${limit}`;
const apiKey = process.env.FRONTEND_BACKEND_API_KEY || "";
const response = await fetch(url, { headers: { "x-api-key": apiKey } });
@@ -228,7 +228,8 @@ class BackendClient {
export const backendClient = new BackendClient();
export type QueueResponse = {
- slots: QueueSlot[]
+ slots: QueueSlot[],
+ noofslots: number,
}
export type QueueSlot = {
@@ -244,7 +245,8 @@ export type QueueSlot = {
}
export type HistoryResponse = {
- slots: HistorySlot[]
+ slots: HistorySlot[],
+ noofslots: number,
}
export type HistorySlot = {
diff --git a/frontend/app/routes/queue/route.module.css b/frontend/app/routes/queue/route.module.css
index bb43c964..76839c13 100644
--- a/frontend/app/routes/queue/route.module.css
+++ b/frontend/app/routes/queue/route.module.css
@@ -15,4 +15,16 @@
display: flex;
gap: 10px;
align-items: baseline;
+}
+
+.alert {
+ margin-bottom: 35px;
+
+ .list {
+ margin-bottom: 0;
+ }
+
+ .listItem {
+ margin-top: 5px
+ }
}
\ No newline at end of file
diff --git a/frontend/app/routes/queue/route.module.css.d.ts b/frontend/app/routes/queue/route.module.css.d.ts
index 7b61e07e..4b64b250 100644
--- a/frontend/app/routes/queue/route.module.css.d.ts
+++ b/frontend/app/routes/queue/route.module.css.d.ts
@@ -2,6 +2,9 @@ declare const styles: {
readonly "container": string;
readonly "section": string;
readonly "section-title": string;
+ readonly "alert": string;
+ readonly "list": string;
+ readonly "listItem": string;
};
export = styles;
diff --git a/frontend/app/routes/queue/route.tsx b/frontend/app/routes/queue/route.tsx
index 6ab561ec..c4d1c853 100644
--- a/frontend/app/routes/queue/route.tsx
+++ b/frontend/app/routes/queue/route.tsx
@@ -1,4 +1,4 @@
-import { redirect } from "react-router";
+import { Link, redirect } from "react-router";
import type { Route } from "./+types/route";
import { sessionStorage } from "~/auth/authentication.server";
import styles from "./route.module.css"
@@ -27,20 +27,24 @@ const topicSubscriptions = {
[topicNames.historyItemRemoved]: 'event',
}
+const maxItems = 100;
export async function loader({ request }: Route.LoaderArgs) {
- var queuePromise = backendClient.getQueue();
- var historyPromise = backendClient.getHistory();
+ var queuePromise = backendClient.getQueue(maxItems);
+ var historyPromise = backendClient.getHistory(maxItems);
var queue = await queuePromise;
var history = await historyPromise;
return {
queueSlots: queue?.slots || [],
historySlots: history?.slots || [],
+ totalQueueCount: queue?.noofslots || 0,
+ totalHistoryCount: history?.noofslots || 0,
}
}
export default function Queue(props: Route.ComponentProps) {
const [queueSlots, setQueueSlots] = useState<PresentationQueueSlot[]>(props.loaderData.queueSlots);
const [historySlots, setHistorySlots] = useState<PresentationHistorySlot[]>(props.loaderData.historySlots);
+ const disableLiveView = queueSlots.length == maxItems || historySlots.length == maxItems;
const error = props.actionData?.error;
// queue events
@@ -89,6 +93,7 @@ export default function Queue(props: Route.ComponentProps) {
// websocket
const onWebsocketMessage = useCallback((topic: string, message: string) => {
+ if (disableLiveView) return;
if (topic == topicNames.queueItemAdded)
onAddQueueSlot(JSON.parse(message));
else if (topic == topicNames.queueItemRemoved)
@@ -108,9 +113,11 @@ export default function Queue(props: Route.ComponentProps) {
onChangeQueueSlotPercentage,
onAddHistorySlot,
onRemoveHistorySlots,
+ disableLiveView
]);
useEffect(() => {
+ if (disableLiveView) return;
let ws: WebSocket;
let disposed = false;
function connect() {
@@ -123,7 +130,7 @@ export default function Queue(props: Route.ComponentProps) {
}
return connect();
- }, [onWebsocketMessage]);
+ }, [onWebsocketMessage, disableLiveView]);
return (
<div className={styles.container}>
@@ -134,6 +141,27 @@ export default function Queue(props: Route.ComponentProps) {
</Alert>
}
+ {/* warning */}
+ {disableLiveView &&
+ <Alert className={styles.alert} variant="warning">
+ <b>Attention</b>
+ <ul className={styles.list}>
+ <li className={styles.listItem}>
+ Displaying the first {queueSlots.length} of {props.loaderData.totalQueueCount} queue items
+ </li>
+ <li className={styles.listItem}>
+ Displaying the first {historySlots.length} of {props.loaderData.totalHistoryCount} history items
+ </li>
+ <li className={styles.listItem}>
+ Live view is disabled. Manually <Link to={'/queue'}>refresh</Link> the page for updates.
+ </li>
+ <li className={styles.listItem}>
+ (This is a bandaid — Proper pagination will be added soon)
+ </li>
+ </ul>
+ </Alert>
+ }
+
{/* queue */}
<div className={styles.section}>
{queueSlots.length > 0 ?