Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
feat: add ui setting to schedule the RemoveOrphanedFiles task.
nzbdav-dev807573bd7411
diff --git a/frontend/app/routes/settings/maintenance/maintenance.tsx b/frontend/app/routes/settings/maintenance/maintenance.tsxindex 3f3ec813..597042f2 100644--- a/frontend/app/routes/settings/maintenance/maintenance.tsx+++ b/frontend/app/routes/settings/maintenance/maintenance.tsx@@ -1,4 +1,4 @@-import { Accordion, Form } from "react-bootstrap";+import { Accordion, Form, InputGroup } from "react-bootstrap";import styles from "./maintenance.module.css"import { RemoveUnlinkedFiles } from "./remove-unlinked-files/remove-unlinked-files";import { ConvertStrmToSymlinks } from "./strm-to-symlinks/strm-to-symlinks";@@ -28,6 +28,68 @@ export function Maintenance({ savedConfig, config, setNewConfig }: MaintenancePrWhen enabled, nzbdav will run a SQLite VACUUM on the database at every startup. This reclaims unused disk space and can improve query performance over time, but may increase startup time for large databases.</Form.Text></Form.Group>+ <hr />+ <Form.Group>+ <Form.Check+ className={styles.input}+ type="checkbox"+ id="remove-orphaned-schedule-enabled-checkbox"+ aria-describedby="remove-orphaned-schedule-help"+ label={'Schedule "Remove Orphaned Files" Task Daily'}+ checked={isScheduledOrphanTaskEnabled(config)}+ onChange={e => setNewConfig({ ...config, "maintenance.remove-orphaned-schedule-enabled": "" + e.target.checked })} />+ <InputGroup className={styles.input} style={{ marginTop: '15px' }}>+ <Form.Select+ disabled={!isScheduledOrphanTaskEnabled(config)}+ value={getScheduledTime(config).hour}+ onChange={e => setNewConfig({+ ...config,+ "maintenance.remove-orphaned-schedule-time": buildScheduledTime(+ parseInt(e.target.value),+ getScheduledTime(config).minute,+ getScheduledTime(config).period+ )+ })}>+ {Array.from({ length: 12 }, (_, i) => i + 1).map(h => (+ <option key={h} value={h}>{h}</option>+ ))}+ </Form.Select>+ <Form.Select+ disabled={!isScheduledOrphanTaskEnabled(config)}+ value={getScheduledTime(config).minute}+ onChange={e => setNewConfig({+ ...config,+ "maintenance.remove-orphaned-schedule-time": buildScheduledTime(+ getScheduledTime(config).hour,+ parseInt(e.target.value),+ getScheduledTime(config).period+ )+ })}>+ <option value={0}>00</option>+ <option value={15}>15</option>+ <option value={30}>30</option>+ <option value={45}>45</option>+ </Form.Select>+ <Form.Select+ disabled={!isScheduledOrphanTaskEnabled(config)}+ value={getScheduledTime(config).period}+ onChange={e => setNewConfig({+ ...config,+ "maintenance.remove-orphaned-schedule-time": buildScheduledTime(+ getScheduledTime(config).hour,+ getScheduledTime(config).minute,+ e.target.value as "am" | "pm"+ )+ })}>+ <option value="am">am</option>+ <option value="pm">pm</option>+ </Form.Select>+ </InputGroup>+ <Form.Text id="remove-orphaned-schedule-help" muted>+ When enabled, the "Remove Orphaned Files" task will run every day at the specified time.+ You may need to set the TZ env variable to ensure the correct timezone.+ </Form.Text>+ </Form.Group></div><div className={styles.tasksContainer}><hr />@@ -63,5 +125,26 @@ export function Maintenance({ savedConfig, config, setNewConfig }: MaintenancePr}export function isMaintenanceSettingsUpdated(config: Record<string, string>, newConfig: Record<string, string>) {- return config["db.is-startup-vacuum-enabled"] !== newConfig["db.is-startup-vacuum-enabled"];+ return config["db.is-startup-vacuum-enabled"] !== newConfig["db.is-startup-vacuum-enabled"]+ || config["maintenance.remove-orphaned-schedule-enabled"] !== newConfig["maintenance.remove-orphaned-schedule-enabled"]+ || config["maintenance.remove-orphaned-schedule-time"] !== newConfig["maintenance.remove-orphaned-schedule-time"];+}++function isScheduledOrphanTaskEnabled(config: Record<string, string>) {+ return config["maintenance.remove-orphaned-schedule-enabled"] === "true";+}++function getScheduledTime(config: Record<string, string>): { hour: number, minute: number, period: "am" | "pm" } {+ const totalMinutes = parseInt(config["maintenance.remove-orphaned-schedule-time"] || "0");+ const hour24 = Math.floor(totalMinutes / 60);+ return {+ hour: hour24 % 12 || 12, // 0→12 (midnight), 1→1, ..., 12→12 (noon), 13→1, ...+ minute: totalMinutes % 60,+ period: Math.floor(totalMinutes / 60) >= 12 ? "pm" : "am"+ };+}++function buildScheduledTime(hour: number, minute: number, period: "am" | "pm"): string {+ const hour24 = (hour % 12) + (period === "pm" ? 12 : 0);+ return "" + (hour24 * 60 + minute);}\ No newline at end of filediff --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.tsxindex 34677f1a..e9fce619 100644--- 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@@ -117,8 +117,11 @@ export function RemoveUnlinkedFiles({ savedConfig }: RemoveUnlinkedFilesProps) {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.+ Note: Files still present in the History table will not be removed when running this task.+ It is assumed that files still present in the History table have not yet been imported by Arrs+ and they are expected to not yet have a corresponding symlink/strm in the Library folder.+ These files will remain intact until Arrs have a chance to process them and remove them from the+ History table.</Form.Text></Form.Group></div>diff --git a/frontend/app/routes/settings/route.tsx b/frontend/app/routes/settings/route.tsxindex 27dc8d89..0a8f4274 100644--- a/frontend/app/routes/settings/route.tsx+++ b/frontend/app/routes/settings/route.tsx@@ -44,6 +44,8 @@ const defaultConfig = {"arr.instances": "{\"RadarrInstances\":[],\"SonarrInstances\":[],\"QueueRules\":[]}","repair.enable": "false","db.is-startup-vacuum-enabled": "false",+ "maintenance.remove-orphaned-schedule-enabled": "false",+ "maintenance.remove-orphaned-schedule-time": "0","api.nzb-backup-enabled": "false","api.nzb-backup-location": "",}