Skip to content

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

C#

Refactored maintenance page to make room for multiple tasks.

nzbdav-dev251c2241b797
diff --git a/frontend/app/routes/settings/maintenance/maintenance.module.css b/frontend/app/routes/settings/maintenance/maintenance.module.css
index fe647239..072ebbcf 100644
--- a/frontend/app/routes/settings/maintenance/maintenance.module.css
+++ b/frontend/app/routes/settings/maintenance/maintenance.module.css
@@ -2,39 +2,24 @@
max-width: 600px;
}
-.task {
- background-color: #02181d;
- padding: 1rem;
- color: #dee2e6;
- border-radius: .375rem;
- box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.25);
-}
-
-.run {
- margin-top: 12px;
- display: flex;
- flex-direction: row;
- gap: 10px;
- align-items: center;
+.accordionItem {
+ border: 1px solid rgba(255, 255, 255, 0.01);
+ overflow: hidden;
}
-.run-button {
- flex-shrink: 0;
-}
-
-.dryrun-button {
- padding: 0 5px;
-}
-
-.task-progress {
- font-size:12px;
- white-space: pre-line;
-}
+.accordionHeader button {
+ background-color: #02181d;
+ color: #dee2e6;
+ box-shadow: none !important;
-.list {
- margin-bottom: 0;
+ &[aria-expanded="true"] {
+ background-color: #02181d;
+ color: #dee2e6;
+ }
}
-.list-item {
- margin-top: 5px
+.accordionBody {
+ background-color: #02181d;
+ color: #dee2e6;
+ border-top: 1px solid rgba(255, 255, 255, 0.1);
}
\ No newline at end of file
diff --git a/frontend/app/routes/settings/maintenance/maintenance.module.css.d.ts b/frontend/app/routes/settings/maintenance/maintenance.module.css.d.ts
index 16fd0330..f8a24096 100644
--- a/frontend/app/routes/settings/maintenance/maintenance.module.css.d.ts
+++ b/frontend/app/routes/settings/maintenance/maintenance.module.css.d.ts
@@ -1,13 +1,9 @@
declare const styles: {
readonly "container": string;
- readonly "task": string;
- readonly "title": string;
- readonly "run": string;
- readonly "run-button": string;
- readonly "dryrun-button": string;
- readonly "task-progress": string;
- readonly "list": string;
- readonly "list-item": string;
+ readonly "accordion": string;
+ readonly "accordionItem": string;
+ readonly "accordionHeader": string;
+ readonly "accordionBody": string;
};
export = styles;
diff --git a/frontend/app/routes/settings/maintenance/maintenance.tsx b/frontend/app/routes/settings/maintenance/maintenance.tsx
index 24674fb2..b91065af 100644
--- a/frontend/app/routes/settings/maintenance/maintenance.tsx
+++ b/frontend/app/routes/settings/maintenance/maintenance.tsx
@@ -1,128 +1,24 @@
-import { Alert, Button, Form } from "react-bootstrap";
+import { Accordion } from "react-bootstrap";
import styles from "./maintenance.module.css"
-import { useCallback, useEffect, useState } from "react";
-import { receiveMessage } from "~/utils/websocket-util";
-
-const cleanupTaskTopic = { 'ctp': 'state' };
+import { RemoveUnlinkedFiles } from "./remove-unlinked-files/remove-unlinked-files";
type MaintenanceProps = {
savedConfig: Record<string, string>
};
export function Maintenance({ savedConfig }: MaintenanceProps) {
- // stateful variables
- const [connected, setConnected] = useState<boolean>(false);
- const [progress, setProgress] = useState<string | null>(null);
- const [isFetching, setIsFetching] = useState<boolean>(false);
-
- // derived variables
- const libraryDir = savedConfig["media.library-dir"];
- const isDone = progress?.startsWith("Done");
- const isFinished = progress?.startsWith("Done") || progress?.startsWith("Failed") || progress?.startsWith("Aborted");
- const isRunning = !isFinished && (isFetching || progress !== null);
- const isRunButtonEnabled = !!libraryDir && connected && !isRunning;
- const runButtonVariant = isRunButtonEnabled ? 'success' : 'secondary';
- const runButtonLabel = isRunning ? "⌛ Running.." : '▶ Run Task';
-
- // effects
- useEffect(() => {
- let ws: WebSocket;
- let disposed = false;
- function connect() {
- ws = new WebSocket(window.location.origin.replace(/^http/, 'ws'));
- ws.onmessage = receiveMessage((_, message) => setProgress(message));
- ws.onopen = () => { setConnected(true); ws.send(JSON.stringify(cleanupTaskTopic)); }
- ws.onclose = () => { !disposed && setTimeout(() => connect(), 1000); setProgress(null) };
- ws.onerror = () => { ws.close() };
- return () => { disposed = true; ws.close(); }
- }
- return connect();
- }, [setProgress, setConnected]);
-
- // events
- const onRun = useCallback(async () => {
- setIsFetching(true);
- await fetch("/api/remove-unlinked-files");
- setIsFetching(false);
- }, [setIsFetching]);
-
- const onDryRun = useCallback(async (event: any) => {
- setIsFetching(true);
- await fetch("/api/remove-unlinked-files/dry-run");
- setIsFetching(false);
- }, [setIsFetching]);
-
- // view
- const dryRunButton =
- <Button
- className={styles["dryrun-button"]}
- disabled={!isRunButtonEnabled}
- onClick={onDryRun}
- variant="secondary"
- size="sm"
- >
- perform a dry-run
- </Button>;
-
return (
<div className={styles.container}>
- {!libraryDir &&
- <Alert variant="warning">
- Warning
- <ul className={styles.list}>
- <li className={styles["list-item"]}>
- You must first configure the Library Directory setting before running this task.
- Head over to the Repairs tab.
- </li>
- </ul>
- </Alert>
- }
- {libraryDir &&
- <Alert variant="danger">
- <span style={{ fontWeight: 'bold' }}>Danger</span>
- <ul className={styles.list}>
- <li className={styles["list-item"]}>
- Make a backup of your NzbDAV database prior to running this task
- </li>
- <li className={styles["list-item"]}>
- Files will be removed from the webdav and will not be recoverable without a backup
- </li>
- </ul>
- </Alert>
- }
- <div className={styles.task}>
- <Form.Group>
- <Form.Label className={styles.title}>Removed Unlinked Files</Form.Label>
- <div className={styles.run}>
- <Button
- className={styles["run-button"]}
- variant={runButtonVariant}
- onClick={onRun}
- disabled={!isRunButtonEnabled}
- >
- {runButtonLabel}
- </Button>
- <div className={styles["task-progress"]}>
- {progress}
- {isDone && <>
- &nbsp;<a href="/api/remove-unlinked-files/audit">Audit.</a>
- </>}
- </div>
- </div>
- <Form.Text id="cleanup-task-progress-help" muted>
- <br />
- This task will scan your organized media library for all symlinked or *.strm linked files.
- Any file on the webdav that is not pointed to by your library will be deleted.
- If you would like to see what would be deleted without running the task, you can {dryRunButton}.
- The dry-run will not delete anything.
- <br />
- <br />
- Note: This task is intended to cleanup old, abandoned, files.
- Files added less than twenty-four hours ago will not be deleted.
- </Form.Text>
- </Form.Group>
- </div>
+ <Accordion className={styles.accordion} defaultActiveKey="remove-unlinked-files">
+ <Accordion.Item className={styles.accordionItem} eventKey="remove-unlinked-files">
+ <Accordion.Header className={styles.accordionHeader}>
+ Remove Orphaned Files
+ </Accordion.Header>
+ <Accordion.Body className={styles.accordionBody}>
+ <RemoveUnlinkedFiles savedConfig={savedConfig} />
+ </Accordion.Body>
+ </Accordion.Item>
+ </Accordion>
</div>
-
);
}
\ No newline at end of file
diff --git a/frontend/app/routes/settings/maintenance/remove-unlinked-files/remove-unlinked-files.module.css b/frontend/app/routes/settings/maintenance/remove-unlinked-files/remove-unlinked-files.module.css
new file mode 100644
index 00000000..9fef52c0
--- /dev/null
+++ b/frontend/app/routes/settings/maintenance/remove-unlinked-files/remove-unlinked-files.module.css
@@ -0,0 +1,42 @@
+.container {
+ max-width: 600px;
+}
+
+.task {
+ background-color: #02181d;
+ padding: 5px;
+ color: #dee2e6;
+}
+
+.alert {
+ margin-top: 8px;
+}
+
+.run {
+ margin-top: 12px;
+ display: flex;
+ flex-direction: row;
+ gap: 10px;
+ align-items: center;
+}
+
+.run-button {
+ flex-shrink: 0;
+}
+
+.dryrun-button {
+ padding: 0 5px;
+}
+
+.task-progress {
+ font-size:12px;
+ white-space: pre-line;
+}
+
+.list {
+ margin-bottom: 0;
+}
+
+.list-item {
+ margin-top: 5px
+}
\ No newline at end of file
diff --git a/frontend/app/routes/settings/maintenance/remove-unlinked-files/remove-unlinked-files.module.css.d.ts b/frontend/app/routes/settings/maintenance/remove-unlinked-files/remove-unlinked-files.module.css.d.ts
new file mode 100644
index 00000000..77563f20
--- /dev/null
+++ b/frontend/app/routes/settings/maintenance/remove-unlinked-files/remove-unlinked-files.module.css.d.ts
@@ -0,0 +1,14 @@
+declare const styles: {
+ readonly "container": string;
+ readonly "task": string;
+ readonly "title": string;
+ readonly "run": string;
+ readonly "run-button": string;
+ readonly "dryrun-button": string;
+ readonly "task-progress": string;
+ readonly "list": string;
+ readonly "list-item": string;
+ readonly "alert": string;
+};
+export = styles;
+
diff --git a/frontend/app/routes/settings/maintenance/remove-unlinked-files/remove-unlinked-files.tsx b/frontend/app/routes/settings/maintenance/remove-unlinked-files/remove-unlinked-files.tsx
new file mode 100644
index 00000000..fc787611
--- /dev/null
+++ b/frontend/app/routes/settings/maintenance/remove-unlinked-files/remove-unlinked-files.tsx
@@ -0,0 +1,126 @@
+import { Alert, Button, Form } from "react-bootstrap";
+import styles from "./remove-unlinked-files.module.css"
+import { useCallback, useEffect, useState } from "react";
+import { receiveMessage } from "~/utils/websocket-util";
+
+const cleanupTaskTopic = { 'ctp': 'state' };
+
+type RemoveUnlinkedFilesProps = {
+ savedConfig: Record<string, string>
+};
+
+export function RemoveUnlinkedFiles({ savedConfig }: RemoveUnlinkedFilesProps) {
+ // stateful variables
+ const [connected, setConnected] = useState<boolean>(false);
+ const [progress, setProgress] = useState<string | null>(null);
+ const [isFetching, setIsFetching] = useState<boolean>(false);
+
+ // derived variables
+ const libraryDir = savedConfig["media.library-dir"];
+ const isDone = progress?.startsWith("Done");
+ const isFinished = progress?.startsWith("Done") || progress?.startsWith("Failed") || progress?.startsWith("Aborted");
+ const isRunning = !isFinished && (isFetching || progress !== null);
+ const isRunButtonEnabled = !!libraryDir && connected && !isRunning;
+ const runButtonVariant = isRunButtonEnabled ? 'success' : 'secondary';
+ const runButtonLabel = isRunning ? "⌛ Running.." : '▶ Run Task';
+
+ // effects
+ useEffect(() => {
+ let ws: WebSocket;
+ let disposed = false;
+ function connect() {
+ ws = new WebSocket(window.location.origin.replace(/^http/, 'ws'));
+ ws.onmessage = receiveMessage((_, message) => setProgress(message));
+ ws.onopen = () => { setConnected(true); ws.send(JSON.stringify(cleanupTaskTopic)); }
+ ws.onclose = () => { !disposed && setTimeout(() => connect(), 1000); setProgress(null) };
+ ws.onerror = () => { ws.close() };
+ return () => { disposed = true; ws.close(); }
+ }
+ return connect();
+ }, [setProgress, setConnected]);
+
+ // events
+ const onRun = useCallback(async () => {
+ setIsFetching(true);
+ await fetch("/api/remove-unlinked-files");
+ setIsFetching(false);
+ }, [setIsFetching]);
+
+ const onDryRun = useCallback(async (event: any) => {
+ setIsFetching(true);
+ await fetch("/api/remove-unlinked-files/dry-run");
+ setIsFetching(false);
+ }, [setIsFetching]);
+
+ // view
+ const dryRunButton =
+ <Button
+ className={styles["dryrun-button"]}
+ disabled={!isRunButtonEnabled}
+ onClick={onDryRun}
+ variant="secondary"
+ size="sm"
+ >
+ perform a dry-run
+ </Button>;
+
+ return (
+ <>
+ {!libraryDir &&
+ <Alert className={styles.alert} variant="warning">
+ Warning
+ <ul className={styles.list}>
+ <li className={styles["list-item"]}>
+ You must first configure the Library Directory setting before running this task.
+ Head over to the Repairs tab.
+ </li>
+ </ul>
+ </Alert>
+ }
+ {libraryDir &&
+ <Alert className={styles.alert} variant="danger">
+ <span style={{ fontWeight: 'bold' }}>Danger</span>
+ <ul className={styles.list}>
+ <li className={styles["list-item"]}>
+ Make a backup of your NzbDAV database prior to running this task
+ </li>
+ <li className={styles["list-item"]}>
+ Files will be removed from the webdav and will not be recoverable without a backup
+ </li>
+ </ul>
+ </Alert>
+ }
+ <div className={styles.task}>
+ <Form.Group>
+ <div className={styles.run}>
+ <Button
+ className={styles["run-button"]}
+ variant={runButtonVariant}
+ onClick={onRun}
+ disabled={!isRunButtonEnabled}
+ >
+ {runButtonLabel}
+ </Button>
+ <div className={styles["task-progress"]}>
+ {progress}
+ {isDone && <>
+ &nbsp;<a href="/api/remove-unlinked-files/audit">Audit.</a>
+ </>}
+ </div>
+ </div>
+ <Form.Text id="cleanup-task-progress-help" muted>
+ <br />
+ This task will scan your organized media library for all symlinked or *.strm linked files.
+ Any file on the webdav that is not pointed to by your library will be deleted.
+ If you would like to see what would be deleted without running the task, you can {dryRunButton}.
+ The dry-run will not delete anything.
+ <br />
+ <br />
+ Note: This task is intended to cleanup old, abandoned, files.
+ Files added less than twenty-four hours ago will not be deleted.
+ </Form.Text>
+ </Form.Group>
+ </div>
+ </>
+ );
+}
\ No newline at end of file