Fixed: issue with DownloadStationTaskProxyV2 if no destination folder specified in settings

This commit is contained in:
TwentyNine78 2021-07-02 22:22:22 +02:00 committed by Qstick
parent 28e9d112c8
commit 94c685a5ca
4 changed files with 72 additions and 0 deletions

View File

@ -7,6 +7,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation
DownloadStationInfo,
DownloadStationTask,
DownloadStation2Task,
DownloadStation2SettingsLocation,
FileStationList,
DSMInfo,
}

View File

@ -0,0 +1,31 @@
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Http;
using NzbDrone.Core.Download.Clients.DownloadStation.Responses;
namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{
public interface IDownloadStation2SettingsLocationProxy
{
string GetDefaultDestination(DownloadStationSettings settings);
}
public class DownloadStation2SettingsLocationProxy : DiskStationProxyBase, IDownloadStation2SettingsLocationProxy
{
public DownloadStation2SettingsLocationProxy(IHttpClient httpClient, ICacheManager cacheManager, Logger logger)
: base(DiskStationApi.DownloadStation2SettingsLocation, "SYNO.DownloadStation2.Settings.Location", httpClient, cacheManager, logger)
{
}
public string GetDefaultDestination(DownloadStationSettings settings)
{
var info = GetApiInfo(settings);
var requestBuilder = BuildRequest(settings, "get", info.MinVersion);
var response = ProcessRequest<DownloadStation2SettingsLocationResponse>(requestBuilder, "get default destination folder", settings);
return response.Data.Default_Destination;
}
}
}

View File

@ -10,9 +10,12 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{
public class DownloadStationTaskProxyV2 : DiskStationProxyBase, IDownloadStationTaskProxy
{
private readonly IDownloadStation2SettingsLocationProxy _defaultDestinationProxy;
public DownloadStationTaskProxyV2(IHttpClient httpClient, ICacheManager cacheManager, Logger logger)
: base(DiskStationApi.DownloadStation2Task, "SYNO.DownloadStation2.Task", httpClient, cacheManager, logger)
{
_defaultDestinationProxy = new DownloadStation2SettingsLocationProxy(httpClient, cacheManager, logger);
}
public bool IsApiSupported(DownloadStationSettings settings)
@ -32,6 +35,21 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{
requestBuilder.AddFormParameter("destination", $"\"{downloadDirectory}\"");
}
else
{
_logger.Trace("No directory configured in settings; falling back to client default destination folder.");
string defaultDestination = _defaultDestinationProxy.GetDefaultDestination(settings);
if (defaultDestination.IsNotNullOrWhiteSpace())
{
_logger.Trace($"Default destination folder found: {defaultDestination}.");
requestBuilder.AddFormParameter("destination", $"\"{defaultDestination}\"");
}
else
{
_logger.Error("Unable to get default destination folder from DownloadStation.");
}
}
requestBuilder.AddFormUpload("fileData", filename, data);
@ -50,6 +68,21 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
{
requestBuilder.AddQueryParam("destination", downloadDirectory);
}
else
{
_logger.Trace("No directory configured in settings; falling back to client default destination folder.");
string defaultDestination = _defaultDestinationProxy.GetDefaultDestination(settings);
if (defaultDestination.IsNotNullOrWhiteSpace())
{
_logger.Trace($"Default destination folder found: {defaultDestination}.");
requestBuilder.AddQueryParam("destination", $"\"{defaultDestination}\"");
}
else
{
_logger.Error("Unable to get default destination folder from DownloadStation.");
}
}
ProcessRequest<object>(requestBuilder, $"add task from url {url}", settings);
}

View File

@ -0,0 +1,7 @@
namespace NzbDrone.Core.Download.Clients.DownloadStation.Responses
{
public class DownloadStation2SettingsLocationResponse
{
public string Default_Destination { get; set; }
}
}