Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Added download option to filter blacklisted extensions.
nzbdav-devbf1ad3d0fdc9
diff --git a/backend/Config/ConfigManager.cs b/backend/Config/ConfigManager.csindex 9e0a58a2..42c23281 100644--- a/backend/Config/ConfigManager.cs+++ b/backend/Config/ConfigManager.cs@@ -194,6 +194,12 @@ public class ConfigManagerreturn GetConfigValue("api.duplicate-nzb-behavior") ?? defaultValue;}+ public string GetDownloadExtensionBlacklist()+ {+ var defaultValue = ".nfo, .par2, .sfv";+ return GetConfigValue("api.download-extension-blacklist") ?? defaultValue;+ }+public class ConfigEventArgs : EventArgs{public Dictionary<string, string> ChangedConfig { get; set; } = new();diff --git a/backend/Queue/PostProcessors/BlacklistedExtensionPostProcessor.cs b/backend/Queue/PostProcessors/BlacklistedExtensionPostProcessor.csnew file mode 100644index 00000000..a5e56b83--- /dev/null+++ b/backend/Queue/PostProcessors/BlacklistedExtensionPostProcessor.cs@@ -0,0 +1,71 @@+using Microsoft.EntityFrameworkCore;+using NzbWebDAV.Config;+using NzbWebDAV.Database;+using NzbWebDAV.Database.Models;+using Serilog;++namespace NzbWebDAV.Queue.PostProcessors;++public class BlacklistedExtensionPostProcessor(ConfigManager configManager, DavDatabaseClient dbClient)+{+ public void RemoveBlacklistedExtensions()+ {+ var blacklistedExtensions = GetBlacklistedExtensions();+ var blacklistedFiles = dbClient.Ctx.ChangeTracker.Entries<DavItem>()+ .Where(x => x.State == EntityState.Added)+ .Select(x => x.Entity)+ .Where(x => x.Type != DavItem.ItemType.Directory)+ .Where(x => blacklistedExtensions.Contains(Path.GetExtension(x.Name)));++ foreach (var blacklistedFile in blacklistedFiles)+ RemoveBlacklistedFile(blacklistedFile);+ }++ private HashSet<string> GetBlacklistedExtensions()+ {+ return configManager.GetDownloadExtensionBlacklist()+ .Split(',', StringSplitOptions.RemoveEmptyEntries)+ .Select(x => x.Trim())+ .Where(x => !string.IsNullOrWhiteSpace(x))+ .Select(x => x.ToLower())+ .ToHashSet();+ }++ private void RemoveBlacklistedFile(DavItem davItem)+ {+ if (davItem.Type == DavItem.ItemType.NzbFile)+ {+ var file = dbClient.Ctx.ChangeTracker.Entries<DavNzbFile>()+ .Where(x => x.State == EntityState.Added)+ .Select(x => x.Entity)+ .First(x => x.Id == davItem.Id);+ dbClient.Ctx.NzbFiles.Remove(file);+ }++ else if (davItem.Type == DavItem.ItemType.RarFile)+ {+ var file = dbClient.Ctx.ChangeTracker.Entries<DavRarFile>()+ .Where(x => x.State == EntityState.Added)+ .Select(x => x.Entity)+ .First(x => x.Id == davItem.Id);+ dbClient.Ctx.RarFiles.Remove(file);+ }++ else if (davItem.Type == DavItem.ItemType.MultipartFile)+ {+ var file = dbClient.Ctx.ChangeTracker.Entries<DavMultipartFile>()+ .Where(x => x.State == EntityState.Added)+ .Select(x => x.Entity)+ .First(x => x.Id == davItem.Id);+ dbClient.Ctx.MultipartFiles.Remove(file);+ }++ else+ {+ Log.Error("Error filtering blacklisted extensions from downloading.");+ return;+ }++ dbClient.Ctx.Items.Remove(davItem);+ }+}\ No newline at end of filediff --git a/backend/Queue/Validators/EnsureImportableVideoValidator.cs b/backend/Queue/PostProcessors/EnsureImportableVideoValidator.cssimilarity index 94%rename from backend/Queue/Validators/EnsureImportableVideoValidator.csrename to backend/Queue/PostProcessors/EnsureImportableVideoValidator.csindex c38a38a7..ff026557 100644--- a/backend/Queue/Validators/EnsureImportableVideoValidator.cs+++ b/backend/Queue/PostProcessors/EnsureImportableVideoValidator.cs@@ -4,7 +4,7 @@ using NzbWebDAV.Database.Models;using NzbWebDAV.Exceptions;using NzbWebDAV.Utils;-namespace NzbWebDAV.Queue.Validators;+namespace NzbWebDAV.Queue.PostProcessors;public class EnsureImportableVideoValidator(DavDatabaseClient dbClient){diff --git a/backend/Queue/QueueItemProcessor.cs b/backend/Queue/QueueItemProcessor.csindex 46dca6ec..5733843e 100644--- a/backend/Queue/QueueItemProcessor.cs+++ b/backend/Queue/QueueItemProcessor.cs@@ -13,7 +13,7 @@ using NzbWebDAV.Queue.DeobfuscationSteps._2.GetPar2FileDescriptors;using NzbWebDAV.Queue.DeobfuscationSteps._3.GetFileInfos;using NzbWebDAV.Queue.FileAggregators;using NzbWebDAV.Queue.FileProcessors;-using NzbWebDAV.Queue.Validators;+using NzbWebDAV.Queue.PostProcessors;using NzbWebDAV.Utils;using NzbWebDAV.Websocket;using Serilog;@@ -167,6 +167,9 @@ public class QueueItemProcessor(new SevenZipAggregator(dbClient, mountFolder, checkedFullHealth).UpdateDatabase(fileProcessingResults);new MultipartMkvAggregator(dbClient, mountFolder, checkedFullHealth).UpdateDatabase(fileProcessingResults);+ // post-processing+ new BlacklistedExtensionPostProcessor(configManager, dbClient).RemoveBlacklistedExtensions();+// validate video files foundif (configManager.IsEnsureImportableVideoEnabled())new EnsureImportableVideoValidator(dbClient).ThrowIfValidationFails();diff --git a/frontend/app/routes/queue/components/history-table/history-table.tsx b/frontend/app/routes/queue/components/history-table/history-table.tsxindex 48ebfee3..acbc3232 100644--- a/frontend/app/routes/queue/components/history-table/history-table.tsx+++ b/frontend/app/routes/queue/components/history-table/history-table.tsx@@ -6,7 +6,7 @@ import { ConfirmModal } from "../confirm-modal/confirm-modal"import { Link } from "react-router"import { type TriCheckboxState } from "../tri-checkbox/tri-checkbox"import type { PresentationHistorySlot } from "../../route"-import { getDirectoryName, getLeafDirectoryName } from "~/utils/path"+import { getLeafDirectoryName } from "~/utils/path"export type HistoryTableProps = {historySlots: PresentationHistorySlot[],diff --git a/frontend/app/routes/settings/route.tsx b/frontend/app/routes/settings/route.tsxindex 6a38e8c5..0934e1fd 100644--- a/frontend/app/routes/settings/route.tsx+++ b/frontend/app/routes/settings/route.tsx@@ -17,6 +17,7 @@ const defaultConfig = {"api.ensure-importable-video": "true","api.ensure-article-existence": "false","api.ignore-history-limit": "true",+ "api.download-extension-blacklist": ".nfo, .par2, .sfv","api.duplicate-nzb-behavior": "increment","usenet.host": "","usenet.port": "",diff --git a/frontend/app/routes/settings/sabnzbd/sabnzbd.tsx b/frontend/app/routes/settings/sabnzbd/sabnzbd.tsxindex 99b3401c..963e47a3 100644--- a/frontend/app/routes/settings/sabnzbd/sabnzbd.tsx+++ b/frontend/app/routes/settings/sabnzbd/sabnzbd.tsx@@ -80,6 +80,21 @@ export function SabnzbdSettings({ config, setNewConfig }: SabnzbdSettingsProps)</Form.Text></Form.Group><hr />+ <Form.Group>+ <Form.Label htmlFor="ignored-file-extensions-input">Ignored File Extensions</Form.Label>+ <Form.Control+ className={styles.input}+ type="text"+ id="ignored-file-extensions-input"+ aria-describedby="ignored-file-extensions-help"+ placeholder=".nfo, .par2, .sfv"+ value={config["api.download-extension-blacklist"]}+ onChange={e => setNewConfig({ ...config, "api.download-extension-blacklist": e.target.value })} />+ <Form.Text id="ignored-file-extensions-help" muted>+ Files with these extensions will be ignored and not mounted onto the webdav when processing an nzb.+ </Form.Text>+ </Form.Group>+ <hr /><Form.Group><Form.Label htmlFor="duplicate-nzb-input">Behavior for Duplicate NZBs</Form.Label><Form.Select@@ -150,6 +165,7 @@ export function isSabnzbdSettingsUpdated(config: Record<string, string>, newConf|| config["api.ensure-article-existence"] !== newConfig["api.ensure-article-existence"]|| config["api.ignore-history-limit"] !== newConfig["api.ignore-history-limit"]|| config["api.duplicate-nzb-behavior"] !== newConfig["api.duplicate-nzb-behavior"]+ || config["api.download-extension-blacklist"] !== newConfig["api.download-extension-blacklist"]}export function isSabnzbdSettingsValid(newConfig: Record<string, string>) {