From c50afe9e646a910fc20b95e0b0d938b6fb4415bd Mon Sep 17 00:00:00 2001 From: Cucumberrbob <128094686+Cucumberrbob@users.noreply.github.com> Date: Tue, 11 Mar 2025 12:14:15 +0000 Subject: [PATCH] [TB] `GetDownloadLinks` -> `GetDownloadInfos` --- .../TorrentClients/TorBoxTorrentClient.cs | 34 +++++-------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs index 556faa7..26d95e1 100644 --- a/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs +++ b/server/RdtClient.Service/Services/TorrentClients/TorBoxTorrentClient.cs @@ -1,9 +1,9 @@ +using System.Diagnostics; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using TorBoxNET; using RdtClient.Data.Enums; using RdtClient.Data.Models.TorrentClient; -using System.Web; using RdtClient.Data.Models.Data; using RdtClient.Service.Helpers; @@ -284,39 +284,21 @@ public class TorBoxTorrentClient(ILogger logger, IHttpClien return torrent; } - public async Task?> GetDownloadLinks(Torrent torrent) + public async Task?> GetDownloadInfos(Torrent torrent) { var torrentId = await GetClient().Torrents.GetHashInfoAsync(torrent.Hash, skipCache: true); return torrent.Files.Where(file => fileFilter.IsDownloadable(torrent, file.Path, file.Bytes)) - .Select(file => $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}") + .Select(file => new DownloadInfo { RestrictedLink = $"https://torbox.app/fakedl/{torrentId?.Id}/{file.Id}", FileName = Path.GetFileName(file.Path)}) .ToList(); } - public async Task GetFileName(String downloadUrl) + public Task GetFileName(Download download) { - if (String.IsNullOrWhiteSpace(downloadUrl)) - { - return ""; - } - - var uri = new Uri(downloadUrl); - - using (HttpClient client = new()) - { - var request = new HttpRequestMessage(HttpMethod.Head, uri); - var response = await client.SendAsync(request); - if (response.Content.Headers.ContentDisposition != null) - { - var fileName = response.Content.Headers.ContentDisposition.FileName; - if (!String.IsNullOrWhiteSpace(fileName)) - { - return fileName.Trim('"'); - } - } - } - - return HttpUtility.UrlDecode(uri.Segments.Last()); + // FileName is set in GetDownlaadInfos + Debug.Assert(download.FileName != null); + + return Task.FromResult(download.FileName); } private DateTimeOffset? ChangeTimeZone(DateTimeOffset? dateTimeOffset)