Add DB values for seeding and zipped, pass to addtorrent

This commit is contained in:
Sam Heinz 2024-09-01 19:46:05 +10:00
parent 91dcdb9d7c
commit 70584d1acb
3 changed files with 17 additions and 6 deletions

View file

@ -55,7 +55,8 @@
<a href="https://www.premiumize.me/" target="_blank" rel="noopener" <a href="https://www.premiumize.me/" target="_blank" rel="noopener"
>Use this link to sign up to Premiumize.</a >Use this link to sign up to Premiumize.</a
> >
<a href="https://torbox.app/" target="_blank" rel="noopener">Use this link to sign up to Premiumize.</a> <a href="https://torbox.app/" target="_blank" rel="noopener"
>Use this link to sign up to TorBox.</a>
<br /> <br />
<small>(Referal links)</small> <small>(Referal links)</small>
</div> </div>

View file

@ -263,4 +263,12 @@ public class DbSettingsDefaults
[DisplayName("Priority")] [DisplayName("Priority")]
[Description("Set the priority of a torrent, 1 = highest, 0 = disabled.")] [Description("Set the priority of a torrent, 1 = highest, 0 = disabled.")]
public Int32 Priority { get; set; } = 0; public Int32 Priority { get; set; } = 0;
[DisplayName("Seeding")]
[Description("Set the priority of a torrent, 1 = Auto, 2 = Seed, 3 = disabled. [TorBox Only]")]
public Int32 Seeding { get; set; } = 3;
[DisplayName("Download as Zip")]
[Description("Whether to download the files individually or zipped. [TorBox Only]")]
public bool Zipped { get; set; } = true;
} }

View file

@ -4,14 +4,14 @@ using TorBoxNET;
using RdtClient.Data.Enums; using RdtClient.Data.Enums;
using RdtClient.Data.Models.TorrentClient; using RdtClient.Data.Models.TorrentClient;
using RdtClient.Service.Helpers; using RdtClient.Service.Helpers;
using MonoTorrent; using RdtClient.Data.Models.Internal;
namespace RdtClient.Service.Services.TorrentClients; namespace RdtClient.Service.Services.TorrentClients;
public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClientFactory httpClientFactory) : ITorrentClient public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClientFactory httpClientFactory) : ITorrentClient
{ {
private TimeSpan? _offset; private TimeSpan? _offset;
private DbSettingsDefaults _dbSettings = new DbSettingsDefaults();
private TorBoxNetClient GetClient() private TorBoxNetClient GetClient()
{ {
try try
@ -122,7 +122,8 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
public async Task<String> AddMagnet(String magnetLink) public async Task<String> AddMagnet(String magnetLink)
{ {
var result = await GetClient().Torrents.AddMagnetAsync(magnetLink, seeding: 2);
var result = await GetClient().Torrents.AddMagnetAsync(magnetLink, _dbSettings.Seeding, _dbSettings.Zipped);
if (result.Error == "ACTIVE_LIMIT") if (result.Error == "ACTIVE_LIMIT")
{ {
@ -137,7 +138,7 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
public async Task<String> AddFile(Byte[] bytes) public async Task<String> AddFile(Byte[] bytes)
{ {
var result = await GetClient().Torrents.AddFileAsync(bytes, seeding: 2); var result = await GetClient().Torrents.AddFileAsync(bytes, _dbSettings.Seeding, _dbSettings.Zipped);
if (result.Error == "ACTIVE_LIMIT") if (result.Error == "ACTIVE_LIMIT")
{ {
using (var stream = new MemoryStream(bytes)) using (var stream = new MemoryStream(bytes))
@ -145,7 +146,8 @@ public class TorBoxTorrentClient(ILogger<TorBoxTorrentClient> logger, IHttpClien
var torrent = MonoTorrent.Torrent.Load(stream); var torrent = MonoTorrent.Torrent.Load(stream);
return torrent!.InfoHash.ToHex()!.ToLowerInvariant(); return torrent!.InfoHash.ToHex()!.ToLowerInvariant();
} }
} else }
else
{ {
return result.Data!.Hash!; return result.Data!.Hash!;
} }