Skip to content

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

C#

Added frontend ui to configure Arr settings.

nzbdav-dev8f66d5e22adb
diff --git a/frontend/app/routes/settings/arrs/arrs.module.css b/frontend/app/routes/settings/arrs/arrs.module.css
new file mode 100644
index 00000000..7bdf7a39
--- /dev/null
+++ b/frontend/app/routes/settings/arrs/arrs.module.css
@@ -0,0 +1,89 @@
+.container {
+ max-width: 400px;
+}
+
+.section {
+ margin-bottom: 30px;
+}
+
+.sectionHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 20px;
+}
+
+.sectionHeader h5 {
+ margin: 0;
+}
+
+.sectionDivider {
+ margin: 40px 0;
+ border-color: #586e75;
+}
+
+.instanceCard {
+ color: #93a1a1;
+ background-color: #02181d;
+ border: 1px solid rgba(255, 255, 255, 0.1);
+ margin-bottom: 20px;
+ position: relative;
+}
+
+.instanceCard .card-body {
+ padding: 20px;
+}
+
+.closeButton {
+ line-height: 15px;
+ width: 15px;
+ height: 15px;
+ padding: 0;
+ text-align: center;
+ position: absolute;
+ top: 12px;
+ right: 12px;
+ background: none;
+ border: none;
+ color: #93a1a1;
+ font-size: 21px;
+ cursor: pointer;
+ transition: color 0.1s ease;
+}
+
+.closeButton:hover {
+ color: white;
+}
+
+.input {
+ margin-bottom: 8px;
+}
+
+.input::placeholder {
+ color: rgba(255, 255, 255, 0.25);
+}
+
+.error {
+ border: 1px solid red !important;
+}
+
+.removeButton {
+ margin-bottom: 8px;
+}
+
+.alertMessage {
+ color: #93a1a1;
+ font-style: italic;
+ padding: 20px;
+ background-color: #002b36;
+ border: 1px solid #586e75;
+ border-radius: 8px;
+}
+
+.listItem {
+ margin-bottom: 12px;
+}
+
+.statusMessage {
+ margin-bottom: 5px;
+}
\ No newline at end of file
diff --git a/frontend/app/routes/settings/arrs/arrs.module.css.d.ts b/frontend/app/routes/settings/arrs/arrs.module.css.d.ts
new file mode 100644
index 00000000..3b67a97e
--- /dev/null
+++ b/frontend/app/routes/settings/arrs/arrs.module.css.d.ts
@@ -0,0 +1,15 @@
+declare const styles: {
+ readonly container: string;
+ readonly section: string;
+ readonly sectionHeader: string;
+ readonly sectionDivider: string;
+ readonly instanceCard: string;
+ readonly closeButton: string;
+ readonly input: string;
+ readonly error: string;
+ readonly removeButton: string;
+ readonly alertMessage: string;
+ readonly listItem: string;
+ readonly statusMessage: string;
+};
+export default styles;
\ No newline at end of file
diff --git a/frontend/app/routes/settings/arrs/arrs.tsx b/frontend/app/routes/settings/arrs/arrs.tsx
new file mode 100644
index 00000000..4dceb8c8
--- /dev/null
+++ b/frontend/app/routes/settings/arrs/arrs.tsx
@@ -0,0 +1,262 @@
+import { Button, Form, Card } from "react-bootstrap";
+import styles from "./arrs.module.css"
+import { type Dispatch, type SetStateAction, useState, useCallback } from "react";
+
+type ArrsSettingsProps = {
+ config: Record<string, string>
+ setNewConfig: Dispatch<SetStateAction<Record<string, string>>>
+};
+
+interface ConnectionDetails {
+ Host: string;
+ ApiKey: string;
+}
+
+interface QueueRule {
+ Message: string;
+ Action: number;
+}
+
+interface ArrConfig {
+ RadarrInstances: ConnectionDetails[];
+ SonarrInstances: ConnectionDetails[];
+ QueueRules: QueueRule[];
+}
+
+const queueStatusMessages = [
+ "Found matching series via grab history, but release was matched to series by ID. Automatic import is not possible.",
+ "Found matching movie via grab history, but release was matched to movie by ID. Manual Import required.",
+ "Not an upgrade for existing episode file(s)",
+ "No files found are eligible for import",
+ "Episode file already imported",
+ "Sample"
+];
+
+export function ArrsSettings({ config, setNewConfig }: ArrsSettingsProps) {
+ const arrConfig = JSON.parse(config["arr.instances"]);
+
+ const updateConfig = useCallback((newArrConfig: ArrConfig) => {
+ setNewConfig({ ...config, "arr.instances": JSON.stringify(newArrConfig) });
+ }, [config, setNewConfig]);
+
+ const addRadarrInstance = useCallback(() => {
+ updateConfig({
+ ...arrConfig,
+ RadarrInstances: [
+ ...arrConfig.RadarrInstances,
+ { Host: "", ApiKey: "" }
+ ]
+ });
+ }, [arrConfig, updateConfig]);
+
+ const removeRadarrInstance = useCallback((index: number) => {
+ updateConfig({
+ ...arrConfig,
+ RadarrInstances: arrConfig.RadarrInstances
+ .filter((_: any, i: number) => i !== index)
+ });
+ }, [arrConfig, updateConfig]);
+
+ const updateRadarrInstance = useCallback((index: number, field: keyof ConnectionDetails, value: string) => {
+ updateConfig({
+ ...arrConfig,
+ RadarrInstances: arrConfig.RadarrInstances
+ .map((instance: any, i: number) =>
+ i === index ? { ...instance, [field]: value } : instance
+ )
+ });
+ }, [arrConfig, updateConfig]);
+
+ const addSonarrInstance = useCallback(() => {
+ updateConfig({
+ ...arrConfig,
+ SonarrInstances: [
+ ...arrConfig.SonarrInstances,
+ { Host: "", ApiKey: "" }
+ ]
+ });
+ }, [arrConfig, updateConfig]);
+
+ const removeSonarrInstance = useCallback((index: number) => {
+ updateConfig({
+ ...arrConfig,
+ SonarrInstances: arrConfig.SonarrInstances
+ .filter((_: any, i: number) => i !== index)
+ });
+ }, [arrConfig, updateConfig]);
+
+ const updateSonarrInstance = useCallback((index: number, field: keyof ConnectionDetails, value: string) => {
+ updateConfig({
+ ...arrConfig,
+ SonarrInstances: arrConfig.SonarrInstances
+ .map((instance: any, i: number) =>
+ i === index ? { ...instance, [field]: value } : instance
+ )
+ });
+ }, [arrConfig, updateConfig]);
+
+ const updateQueueAction = useCallback((message: string, action: number) => {
+ // update the queue rule if it already exists
+ var newQueueRules = (arrConfig.QueueRules || [])
+ .filter((queueRule: QueueRule) => queueStatusMessages.includes(queueRule.Message))
+ .map((queueRule: QueueRule) => queueRule.Message == message
+ ? { Message: message, Action: action }
+ : queueRule
+ );
+
+ // add the new queue rule if it doesn't already exist
+ if (!newQueueRules.find((queueRule: QueueRule) => queueRule.Message == message))
+ newQueueRules.push({ Message: message, Action: action });
+
+ // update the config
+ updateConfig({
+ ...arrConfig,
+ QueueRules: newQueueRules
+ })
+ }, [arrConfig, updateConfig])
+
+ return (
+ <div className={styles.container}>
+ <div className={styles.section}>
+ <div className={styles.sectionHeader}>
+ <div>Radarr Instances</div>
+ <Button variant="primary" size="sm" onClick={addRadarrInstance}>
+ Add
+ </Button>
+ </div>
+ {arrConfig.RadarrInstances.length === 0 ? (
+ <p className={styles.alertMessage}>No Radarr instances configured. Click on the "Add" button to get started.</p>
+ ) : (
+ arrConfig.RadarrInstances.map((instance: any, index: number) =>
+ renderInstanceForm(instance, index, 'radarr', updateRadarrInstance, removeRadarrInstance)
+ )
+ )}
+ </div>
+ <hr />
+ <div className={styles.section}>
+ <div className={styles.sectionHeader}>
+ <div>Sonarr Instances</div>
+ <Button variant="primary" size="sm" onClick={addSonarrInstance}>
+ Add
+ </Button>
+ </div>
+ {arrConfig.SonarrInstances.length === 0 ? (
+ <p className={styles.alertMessage}>No Sonarr instances configured. Click on the "Add" button to get started.</p>
+ ) : (
+ arrConfig.SonarrInstances.map((instance: any, index: number) =>
+ renderInstanceForm(instance, index, 'sonarr', updateSonarrInstance, removeSonarrInstance)
+ )
+ )}
+ </div>
+ <hr />
+ <div className={styles.section}>
+ <div className={styles.sectionHeader}>
+ <div>Automatic Queue Management</div>
+ </div>
+ <p className={styles.alertMessage}>
+ Configure what to do for items stuck in Radarr / Sonarr queues.
+ Different actions can be configured for different status messages.
+ Only `usenet` queue items will be acted upon.
+ </p>
+ <ul>
+ {queueStatusMessages.map((message, index) =>
+ <li key={index} className={styles.listItem}>
+ <div className={styles.statusMessage}>{message}</div>
+ <Form.Select
+ className={styles.input}
+ value={arrConfig.QueueRules.find((x: QueueRule) => x.Message == message)?.Action ?? "0"}
+ onChange={e => updateQueueAction(message, Number(e.target.value))}
+ >
+ <option value="0">Do Nothing</option>
+ <option value="1">Remove</option>
+ <option value="2">Remove and Blocklist</option>
+ <option value="3">Remove, Blocklist, and Search</option>
+ </Form.Select>
+ </li>
+ )}
+ </ul>
+ </div>
+ </div>
+ );
+}
+
+function renderInstanceForm(
+ instance: ConnectionDetails,
+ index: number,
+ type: 'radarr' | 'sonarr',
+ onUpdate: (index: number, field: keyof ConnectionDetails, value: string) => void,
+ onRemove: (index: number) => void
+) {
+ return (
+ <Card key={index} className={styles.instanceCard}>
+ <button
+ className={styles.closeButton}
+ onClick={() => onRemove(index)}
+ aria-label="Remove instance"
+ >
+ ×
+ </button>
+ <Card.Body>
+ <Form.Group>
+ <Form.Label>Host</Form.Label>
+ <Form.Control
+ type="text"
+ className={styles.input}
+ placeholder={type === "radarr" ? "http://localhost:7878" : "http://localhost:8989"}
+ value={instance.Host}
+ onChange={e => onUpdate(index, 'Host', e.target.value)} />
+ </Form.Group>
+ <Form.Group>
+ <Form.Label>API Key</Form.Label>
+ <Form.Control
+ type="password"
+ className={styles.input}
+ value={instance.ApiKey}
+ onChange={e => onUpdate(index, 'ApiKey', e.target.value)} />
+ </Form.Group>
+ </Card.Body>
+ </Card>
+ );
+}
+
+export function isArrsSettingsUpdated(config: Record<string, string>, newConfig: Record<string, string>) {
+ return config["arr.instances"] !== newConfig["arr.instances"];
+}
+
+export function isArrsSettingsValid(newConfig: Record<string, string>) {
+ try {
+ const arrConfig: ArrConfig = JSON.parse(newConfig["arr.instances"] || "{}");
+
+ // Validate all Radarr instances
+ for (const instance of arrConfig.RadarrInstances || []) {
+ if (!isValidHost(instance.Host) || !isValidApiKey(instance.ApiKey)) {
+ return false;
+ }
+ }
+
+ // Validate all Sonarr instances
+ for (const instance of arrConfig.SonarrInstances || []) {
+ if (!isValidHost(instance.Host) || !isValidApiKey(instance.ApiKey)) {
+ return false;
+ }
+ }
+
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+function isValidHost(host: string): boolean {
+ if (host.trim().length === 0) return false;
+ try {
+ new URL(host);
+ return true;
+ } catch {
+ return false;
+ }
+}
+
+function isValidApiKey(apiKey: string): boolean {
+ return apiKey.trim().length > 0;
+}
\ No newline at end of file
diff --git a/frontend/app/routes/settings/route.tsx b/frontend/app/routes/settings/route.tsx
index 01748805..dbff8f06 100644
--- a/frontend/app/routes/settings/route.tsx
+++ b/frontend/app/routes/settings/route.tsx
@@ -7,6 +7,7 @@ import React, { useEffect } from "react";
import { isSabnzbdSettingsUpdated, isSabnzbdSettingsValid, SabnzbdSettings } from "./sabnzbd/sabnzbd";
import { isWebdavSettingsUpdated, isWebdavSettingsValid, WebdavSettings } from "./webdav/webdav";
import { isLibrarySettingsUpdated, LibrarySettings } from "./library/library";
+import { isArrsSettingsUpdated, isArrsSettingsValid, ArrsSettings } from "./arrs/arrs";
import { Maintenance } from "./maintenance/maintenance";
const defaultConfig = {
@@ -29,6 +30,7 @@ const defaultConfig = {
"webdav.preview-par2-files": "false",
"rclone.mount-dir": "",
"media.library-dir": "",
+ "arr.instances": "{\"RadarrInstances\":[],\"SonarrInstances\":[],\"QueueRules\":[]}",
}
const advancedTabs = ["library", "maintenance"];
@@ -70,11 +72,13 @@ function Body(props: BodyProps) {
const isSabnzbdUpdated = isSabnzbdSettingsUpdated(config, newConfig);
const isWebdavUpdated = isWebdavSettingsUpdated(config, newConfig);
const isLibraryUpdated = isLibrarySettingsUpdated(config, newConfig);
- const isUpdated = iseUsenetUpdated || isSabnzbdUpdated || isWebdavUpdated || isLibraryUpdated;
+ const isArrsUpdated = isArrsSettingsUpdated(config, newConfig);
+ const isUpdated = iseUsenetUpdated || isSabnzbdUpdated || isWebdavUpdated || isLibraryUpdated || isArrsUpdated;
const usenetTitle = iseUsenetUpdated ? "Usenet ✏️" : "Usenet";
const sabnzbdTitle = isSabnzbdUpdated ? "SABnzbd ✏️" : "SABnzbd";
const webdavTitle = isWebdavUpdated ? "WebDAV ✏️" : "WebDAV";
+ const arrsTitle = isArrsUpdated ? "Arrs ✏️" : "Arrs";
const libraryTitle = isLibraryUpdated ? "Library ✏️" : "Library";
const saveButtonLabel = isSaving ? "Saving..."
@@ -83,6 +87,7 @@ function Body(props: BodyProps) {
: iseUsenetUpdated && !isUsenetSettingsReadyToSave ? "Must test the usenet connection to save"
: isSabnzbdUpdated && !isSabnzbdSettingsValid(newConfig) ? "Invalid SABnzbd settings"
: isWebdavUpdated && !isWebdavSettingsValid(newConfig) ? "Invalid WebDAV settings"
+ : isArrsUpdated && !isArrsSettingsValid(newConfig) ? "Invalid Arrs settings"
: "Save";
const saveButtonVariant = saveButtonLabel === "Save" ? "primary"
: saveButtonLabel === "Saved ✅" ? "success"
@@ -150,10 +155,13 @@ function Body(props: BodyProps) {
<Tab eventKey="webdav" title={webdavTitle}>
<WebdavSettings config={newConfig} setNewConfig={setNewConfig} />
</Tab>
- {!showAdvanced &&
+ <Tab eventKey="arrs" title={arrsTitle}>
+ <ArrsSettings config={newConfig} setNewConfig={setNewConfig} />
+ </Tab>
+ {/* {!showAdvanced &&
<Tab eventKey="*" title={"🚀"}>
</Tab>
- }
+ } */}
{showAdvanced &&
<Tab eventKey="library" title={libraryTitle}>
<LibrarySettings savedConfig={config} config={newConfig} setNewConfig={setNewConfig} />