Skip to content

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

C#

Added toggle setting to enable rclone server notifications in backend.

nzbdav-deve39987761e74
diff --git a/backend/Clients/Rclone/RcloneClient.cs b/backend/Clients/Rclone/RcloneClient.cs
index 880cbf29..0e39d54e 100644
--- a/backend/Clients/Rclone/RcloneClient.cs
+++ b/backend/Clients/Rclone/RcloneClient.cs
@@ -27,19 +27,23 @@ public class RcloneClient
public static string? Host { get; private set; }
private static string? User { get; set; }
private static string? Pass { get; set; }
+ public static bool IsRemoteControlEnabled { get; private set; } = false;
public static void Initialize(ConfigManager configManager)
{
Host = configManager.GetRcloneHost();
User = configManager.GetRcloneUser();
Pass = configManager.GetRclonePass();
+ IsRemoteControlEnabled = configManager.IsRcloneRemoteControlEnabled();
configManager.OnConfigChanged += (_, configEventArgs) =>
{
var changedConfig = configEventArgs.ChangedConfig;
if (changedConfig.TryGetValue("rclone.host", out var host)) Host = host;
- if (changedConfig.TryGetValue("rclone.user", out var user)) Host = user;
- if (changedConfig.TryGetValue("rclone.pass", out var pass)) Host = pass;
+ if (changedConfig.TryGetValue("rclone.user", out var user)) User = user;
+ if (changedConfig.TryGetValue("rclone.pass", out var pass)) Pass = pass;
+ if (changedConfig.ContainsKey("rclone.rc-enabled"))
+ IsRemoteControlEnabled = configManager.IsRcloneRemoteControlEnabled();
};
}
diff --git a/backend/Config/ConfigManager.cs b/backend/Config/ConfigManager.cs
index e5f5f426..e4ffde36 100644
--- a/backend/Config/ConfigManager.cs
+++ b/backend/Config/ConfigManager.cs
@@ -239,6 +239,13 @@ public class ConfigManager
return GetConfigValue("general.base-url") ?? "http://localhost:3000";
}
+ public bool IsRcloneRemoteControlEnabled()
+ {
+ var defaultValue = false;
+ var configValue = StringUtil.EmptyToNull(GetConfigValue("rclone.rc-enabled"));
+ return (configValue != null ? bool.Parse(configValue) : defaultValue);
+ }
+
public string? GetRcloneHost()
{
return GetConfigValue("rclone.host");
diff --git a/backend/Database/DavDatabaseClient.cs b/backend/Database/DavDatabaseClient.cs
index 7a5e3574..324e2f83 100644
--- a/backend/Database/DavDatabaseClient.cs
+++ b/backend/Database/DavDatabaseClient.cs
@@ -198,9 +198,17 @@ public sealed class DavDatabaseClient(DavDatabaseContext ctx)
{
if (deleteFiles)
{
- var historyItems = await Ctx.HistoryItems.Where(x => ids.Contains(x.Id)).ToListAsync(ct);
- foreach (var historyItem in historyItems.Where(h => h.DownloadDirId is not null))
- Ctx.Items.Remove(new DavItem() { Id = historyItem.DownloadDirId!.Value });
+ var results = await (
+ from h in Ctx.HistoryItems
+ where ids.Contains(h.Id)
+ join d in Ctx.Items on h.DownloadDirId equals d.Id into items
+ from d in items.DefaultIfEmpty()
+ select new { HistoryItem = h, DavItem = d }
+ ).ToListAsync(ct).ConfigureAwait(false);
+
+ var historyItems = results.Select(r => r.HistoryItem).ToList();
+ var davItems = results.Where(r => r.DavItem != null).Select(r => r.DavItem!).ToList();
+ Ctx.Items.RemoveRange(davItems);
Ctx.HistoryItems.RemoveRange(historyItems);
Ctx.HistoryCleanupItems.AddRange(historyItems.Select(x => new HistoryCleanupItem
{
diff --git a/backend/Database/DavDatabaseContext.cs b/backend/Database/DavDatabaseContext.cs
index 853128dc..18594053 100644
--- a/backend/Database/DavDatabaseContext.cs
+++ b/backend/Database/DavDatabaseContext.cs
@@ -535,6 +535,7 @@ public sealed class DavDatabaseContext() : DbContext(Options.Value)
private Task RcloneVfsForget(List<string> paths)
{
+ if (!RcloneClient.IsRemoteControlEnabled) return Task.CompletedTask;
if (RcloneClient.Host == null) return Task.CompletedTask;
if (paths.Count == 0) return Task.CompletedTask;
return RcloneClient.ForgetVfsPaths(paths);