DownloadHelper: use IFileSystem for testable filesystem access

This commit is contained in:
Cucumberrbob 2025-02-17 21:57:02 +00:00
parent 95307f2933
commit daf8a9c6da
No known key found for this signature in database
GPG key ID: 2B935C47401C3614
2 changed files with 8 additions and 4 deletions

View file

@ -1,11 +1,12 @@
using RdtClient.Data.Models.Data;
using System.IO.Abstractions;
using RdtClient.Data.Models.Data;
using System.Web;
namespace RdtClient.Service.Helpers;
public static class DownloadHelper
{
public static String? GetDownloadPath(String downloadPath, Torrent torrent, Download download)
public static String? GetDownloadPath(String downloadPath, Torrent torrent, Download download, IFileSystem? fileSystem = null)
{
var fileUrl = download.Link;
@ -41,9 +42,11 @@ public static class DownloadHelper
}
}
if (!Directory.Exists(torrentPath))
fileSystem ??= new FileSystem();
if (!fileSystem.Directory.Exists(torrentPath))
{
Directory.CreateDirectory(torrentPath);
fileSystem.Directory.CreateDirectory(torrentPath);
}
var filePath = Path.Combine(torrentPath, fileName);

View file

@ -24,6 +24,7 @@
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="SharpCompress" Version="0.39.0" />
<PackageReference Include="Synology.Api.Client" Version="0.3.87" />
<PackageReference Include="TestableIO.System.IO.Abstractions" Version="21.3.1" />
<PackageReference Include="TorBox.NET" Version="1.4.0" />
</ItemGroup>