diff --git a/server/RdtClient.Service/RdtClient.Service.csproj b/server/RdtClient.Service/RdtClient.Service.csproj index d1b47e2..578fdd6 100644 --- a/server/RdtClient.Service/RdtClient.Service.csproj +++ b/server/RdtClient.Service/RdtClient.Service.csproj @@ -22,11 +22,11 @@ - + diff --git a/server/RdtClient.Service/Services/Downloaders/DownloadStationDownloader.cs b/server/RdtClient.Service/Services/Downloaders/DownloadStationDownloader.cs index 44375b8..f2f0c33 100644 --- a/server/RdtClient.Service/Services/Downloaders/DownloadStationDownloader.cs +++ b/server/RdtClient.Service/Services/Downloaders/DownloadStationDownloader.cs @@ -94,7 +94,6 @@ public class DownloadStationDownloader : IDownloader } } - var retryCount = 0; while (retryCount < 5) { @@ -106,8 +105,6 @@ public class DownloadStationDownloader : IDownloader } try { - await CheckFolderOrCreate(path); - var createResult = await _synologyClient .DownloadStationApi() .TaskEndpoint() @@ -115,32 +112,25 @@ public class DownloadStationDownloader : IDownloader _logger.Debug($"Added download to DownloadStation, received ID {_gid}"); - if (createResult.Success) + _gid = createResult.TaskId?.FirstOrDefault(); + if (_gid == null) _gid = await GetGidFromUri(); + + if (_gid != null) { - _gid = await GetGidFromUri(); - if (_gid != null) - { - _logger.Debug($"Download with ID {_gid} found in DownloadStation"); - return _gid; - } - else - { - retryCount++; - _logger.Debug($"Task not found in DownloadStation after creat Sucess. Retrying {retryCount}/{RetryCount}"); - await Task.Delay(retryCount * 1000); - } + _logger.Debug($"Download with ID {_gid} found in DownloadStation"); + return _gid; } else { retryCount++; - _logger.Debug($"Error starting download: {createResult.Error.Code}. Retrying {retryCount}/{RetryCount}"); + _logger.Error($"Task not found in DownloadStation after creat Sucess. Retrying {retryCount}/{RetryCount}"); await Task.Delay(retryCount * 1000); } } catch (Exception e) { retryCount++; - _logger.Debug($"Error starting download: {e.Message}. Retrying {retryCount}/{RetryCount}"); + _logger.Error($"Error starting download: {e.Message}. Retrying {retryCount}/{RetryCount}"); await Task.Delay(retryCount * 1000); } } @@ -151,7 +141,7 @@ public class DownloadStationDownloader : IDownloader private async Task GetGidFromUri() { var tasks = await _synologyClient.DownloadStationApi().TaskEndpoint().ListAsync(); - return tasks.Tasks.FirstOrDefault(t => t.Additional?.Detail?.Uri == _uri)?.Id; + return tasks.Task.FirstOrDefault(t => t.Additional?.Detail?.Uri == _uri)?.Id; } public async Task Pause() @@ -181,7 +171,7 @@ public class DownloadStationDownloader : IDownloader return; } - if (task.Status == "finished") + if (task.Status == DownloadStationTaskStatus.Finished) { DownloadComplete?.Invoke(this, new() { Error = null }); return; diff --git a/server/RdtClient.sln b/server/RdtClient.sln index 58f8ccd..f341cfd 100644 --- a/server/RdtClient.sln +++ b/server/RdtClient.sln @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RdtClient.Service", "RdtCli EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RdtClient.Data", "RdtClient.Data\RdtClient.Data.csproj", "{92EF8817-AD73-4301-93BD-745D7D61DD74}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Synology.Api.Client", "..\..\Synology.Api.Client\src\Synology.Api.Client\Synology.Api.Client.csproj", "{FDAAD49C-126C-4612-81C2-3CEB6D7A1105}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {92EF8817-AD73-4301-93BD-745D7D61DD74}.Debug|Any CPU.Build.0 = Debug|Any CPU {92EF8817-AD73-4301-93BD-745D7D61DD74}.Release|Any CPU.ActiveCfg = Release|Any CPU {92EF8817-AD73-4301-93BD-745D7D61DD74}.Release|Any CPU.Build.0 = Release|Any CPU + {FDAAD49C-126C-4612-81C2-3CEB6D7A1105}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDAAD49C-126C-4612-81C2-3CEB6D7A1105}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDAAD49C-126C-4612-81C2-3CEB6D7A1105}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDAAD49C-126C-4612-81C2-3CEB6D7A1105}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE