diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/DiskStationApi.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/DiskStationApi.cs index 9b3cbfc33..6c831fb3b 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/DiskStationApi.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/DiskStationApi.cs @@ -7,6 +7,7 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation DownloadStationInfo, DownloadStationTask, DownloadStation2Task, + DownloadStation2SettingsLocation, FileStationList, DSMInfo, } diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStation2SettingsLocationProxy.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStation2SettingsLocationProxy.cs new file mode 100644 index 000000000..7ca124e9c --- /dev/null +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStation2SettingsLocationProxy.cs @@ -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(requestBuilder, "get default destination folder", settings); + + return response.Data.Default_Destination; + } + } +} diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStationTaskProxyV2.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStationTaskProxyV2.cs index 5e5dc2a02..261f76e19 100644 --- a/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStationTaskProxyV2.cs +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/Proxies/DownloadStationTaskProxyV2.cs @@ -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(requestBuilder, $"add task from url {url}", settings); } diff --git a/src/NzbDrone.Core/Download/Clients/DownloadStation/Responses/DownloadStation2SettingsLocationResponse.cs b/src/NzbDrone.Core/Download/Clients/DownloadStation/Responses/DownloadStation2SettingsLocationResponse.cs new file mode 100644 index 000000000..70598e050 --- /dev/null +++ b/src/NzbDrone.Core/Download/Clients/DownloadStation/Responses/DownloadStation2SettingsLocationResponse.cs @@ -0,0 +1,7 @@ +namespace NzbDrone.Core.Download.Clients.DownloadStation.Responses +{ + public class DownloadStation2SettingsLocationResponse + { + public string Default_Destination { get; set; } + } +}