mirror of
https://github.com/Radarr/Radarr.git
synced 2024-09-11 12:02:35 +02:00
Fixed: issue with DownloadStationTaskProxyV2 if no destination folder specified in settings
This commit is contained in:
parent
28e9d112c8
commit
94c685a5ca
@ -7,6 +7,7 @@ public enum DiskStationApi
|
||||
DownloadStationInfo,
|
||||
DownloadStationTask,
|
||||
DownloadStation2Task,
|
||||
DownloadStation2SettingsLocation,
|
||||
FileStationList,
|
||||
DSMInfo,
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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 @@ public void AddTaskFromData(byte[] data, string filename, string downloadDirecto
|
||||
{
|
||||
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 @@ public void AddTaskFromUrl(string url, string downloadDirectory, DownloadStation
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
namespace NzbDrone.Core.Download.Clients.DownloadStation.Responses
|
||||
{
|
||||
public class DownloadStation2SettingsLocationResponse
|
||||
{
|
||||
public string Default_Destination { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user