Add setting to store added torrents and magnets to a directory.
This commit is contained in:
parent
32dfca5fb1
commit
f4e7a9bcf7
2 changed files with 35 additions and 4 deletions
|
|
@ -70,6 +70,10 @@ Supports the following parameters:
|
||||||
[DisplayName("Authentication Type")]
|
[DisplayName("Authentication Type")]
|
||||||
[Description("How to authenticate with the client. WARNING: when set to None anyone with access to the URL can use the client without any credentials.")]
|
[Description("How to authenticate with the client. WARNING: when set to None anyone with access to the URL can use the client without any credentials.")]
|
||||||
public AuthenticationType AuthenticationType { get; set; } = AuthenticationType.UserNamePassword;
|
public AuthenticationType AuthenticationType { get; set; } = AuthenticationType.UserNamePassword;
|
||||||
|
|
||||||
|
[DisplayName("Copy added torrent files")]
|
||||||
|
[Description("When a torrent file or magnet is added, create a copy in this directory.")]
|
||||||
|
public String? CopyAddedTorrents { get; set; } = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DbSettingsDownloadClient
|
public class DbSettingsDownloadClient
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.IO;
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MonoTorrent;
|
using MonoTorrent;
|
||||||
|
|
@ -134,6 +133,23 @@ public class Torrents
|
||||||
|
|
||||||
Log($"Adding {hash} magnet link {magnetLink}", newTorrent);
|
Log($"Adding {hash} magnet link {magnetLink}", newTorrent);
|
||||||
|
|
||||||
|
if (!String.IsNullOrWhiteSpace(Settings.Get.General.CopyAddedTorrents))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(Settings.Get.General.CopyAddedTorrents))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(Settings.Get.General.CopyAddedTorrents);
|
||||||
|
}
|
||||||
|
|
||||||
|
await File.WriteAllTextAsync(Path.Combine(Settings.Get.General.CopyAddedTorrents, $"{torrent.Hash}.magnet"), magnetLink);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, $"Unable to create torrent blackhole directory: {Settings.Get.General.CopyAddedTorrents}: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return newTorrent;
|
return newTorrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,11 +175,22 @@ public class Torrents
|
||||||
|
|
||||||
var newTorrent = await Add(id, hash, fileAsBase64, true, torrent);
|
var newTorrent = await Add(id, hash, fileAsBase64, true, torrent);
|
||||||
|
|
||||||
if (!Directory.Exists("/data/db/blackhole/"))
|
if (!String.IsNullOrWhiteSpace(Settings.Get.General.CopyAddedTorrents))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory("/data/db/blackhole/");
|
try
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(Settings.Get.General.CopyAddedTorrents))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(Settings.Get.General.CopyAddedTorrents);
|
||||||
|
}
|
||||||
|
|
||||||
|
await File.WriteAllBytesAsync(Path.Combine(Settings.Get.General.CopyAddedTorrents, $"{torrent.Hash}.torrent"), bytes);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, $"Unable to create torrent blackhole directory: {Settings.Get.General.CopyAddedTorrents}: {ex.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
File.WriteAllBytes ("/data/db/blackhole/" + hash + ".torrent", bytes);
|
|
||||||
|
|
||||||
return newTorrent;
|
return newTorrent;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue