Add settings to specify the ErrorPath and ProcessedPath for the watcher.

This commit is contained in:
Roger Far 2023-03-08 20:03:35 -07:00
parent 56050877e7
commit ab64e5dcbd
2 changed files with 21 additions and 2 deletions

View file

@ -165,6 +165,14 @@ public class DbSettingsWatch
[Description("Watch this path for .torrent or .magnet files. When a file is found it will be automatically imported.")]
public String? Path { get; set; } = null;
[DisplayName("Error Path")]
[Description("When an error occurs the torrent file is moved to this directory. When unset it will be moved to /error in the watchpath.")]
public String? ErrorPath { get; set; } = null;
[DisplayName("Processed Path")]
[Description("When a torrent file is added succesfully it will be moved to this directory. When unset it will be moved to /processed in the watchpath.")]
public String? ProcessedPath { get; set; } = null;
[DisplayName("Check Interval")]
[Description("Time in seconds to check the folder for new files.")]
public Int32 Interval { get; set; } = 60;

View file

@ -47,9 +47,14 @@ public class WatchFolderChecker : BackgroundService
var processedStorePath = Path.Combine(Settings.Get.Watch.Path, "processed");
var errorStorePath = Path.Combine(Settings.Get.Watch.Path, "error");
if (!Directory.Exists(processedStorePath))
if (!String.IsNullOrWhiteSpace(Settings.Get.Watch.ProcessedPath))
{
Directory.CreateDirectory(processedStorePath);
processedStorePath = Settings.Get.Watch.ProcessedPath;
}
if (!String.IsNullOrWhiteSpace(Settings.Get.Watch.ErrorPath))
{
errorStorePath = Settings.Get.Watch.ErrorPath;
}
var nextCheck = _prevCheck.AddSeconds(Settings.Get.Watch.Interval);
@ -109,6 +114,12 @@ public class WatchFolderChecker : BackgroundService
}
var processedPath = Path.Combine(processedStorePath, fileInfo.Name);
if (!Directory.Exists(processedStorePath))
{
Directory.CreateDirectory(processedStorePath);
}
File.Move(torrentFile, processedPath);
_logger.Log(LogLevel.Debug, "Moved {torrentFile} to {processedPath}", torrentFile, processedPath);