|
|
@ -34,14 +34,16 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
|
|
|
|
protected DiskStationResponse<object> ProcessRequest(DiskStationApi api,
|
|
|
|
protected DiskStationResponse<object> ProcessRequest(DiskStationApi api,
|
|
|
|
Dictionary<string, object> arguments,
|
|
|
|
Dictionary<string, object> arguments,
|
|
|
|
DownloadStationSettings settings,
|
|
|
|
DownloadStationSettings settings,
|
|
|
|
|
|
|
|
string operation,
|
|
|
|
HttpMethod method = HttpMethod.GET)
|
|
|
|
HttpMethod method = HttpMethod.GET)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ProcessRequest<object>(api, arguments, settings, method);
|
|
|
|
return ProcessRequest<object>(api, arguments, settings, operation, method);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected DiskStationResponse<T> ProcessRequest<T>(DiskStationApi api,
|
|
|
|
protected DiskStationResponse<T> ProcessRequest<T>(DiskStationApi api,
|
|
|
|
Dictionary<string, object> arguments,
|
|
|
|
Dictionary<string, object> arguments,
|
|
|
|
DownloadStationSettings settings,
|
|
|
|
DownloadStationSettings settings,
|
|
|
|
|
|
|
|
string operation,
|
|
|
|
HttpMethod method = HttpMethod.GET,
|
|
|
|
HttpMethod method = HttpMethod.GET,
|
|
|
|
int retries = 0) where T : new()
|
|
|
|
int retries = 0) where T : new()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -58,18 +60,28 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
|
|
|
|
var request = BuildRequest(settings, api, arguments, method);
|
|
|
|
var request = BuildRequest(settings, api, arguments, method);
|
|
|
|
var response = _httpClient.Execute(request);
|
|
|
|
var response = _httpClient.Execute(request);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Trying to {0}", operation);
|
|
|
|
|
|
|
|
|
|
|
|
if (response.StatusCode == HttpStatusCode.OK)
|
|
|
|
if (response.StatusCode == HttpStatusCode.OK)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var responseContent = Json.Deserialize<DiskStationResponse<T>>(response.Content);
|
|
|
|
var responseContent = Json.Deserialize<DiskStationResponse<T>>(response.Content);
|
|
|
|
|
|
|
|
|
|
|
|
if (!responseContent.Success && responseContent.Error.SessionError)
|
|
|
|
if (responseContent.Success)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_authenticated = false;
|
|
|
|
return responseContent;
|
|
|
|
return ProcessRequest<T>(api, arguments, settings, method, retries++);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return responseContent;
|
|
|
|
if (responseContent.Error.SessionError)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_authenticated = false;
|
|
|
|
|
|
|
|
return ProcessRequest<T>(api, arguments, settings, operation, method, retries++);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var msg = $"Failed to {operation}. Reason: {responseContent.Error.GetMessage(api)}";
|
|
|
|
|
|
|
|
_logger.Error(msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw new DownloadClientException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -166,42 +178,35 @@ namespace NzbDrone.Core.Download.Clients.DownloadStation.Proxies
|
|
|
|
{ "query", "SYNO.API.Auth, SYNO.DownloadStation.Info, SYNO.DownloadStation.Task, SYNO.FileStation.List, SYNO.DSM.Info" },
|
|
|
|
{ "query", "SYNO.API.Auth, SYNO.DownloadStation.Info, SYNO.DownloadStation.Task, SYNO.FileStation.List, SYNO.DSM.Info" },
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var infoResponse = ProcessRequest<DiskStationApiInfoResponse>(DiskStationApi.Info, arguments, settings);
|
|
|
|
var infoResponse = ProcessRequest<DiskStationApiInfoResponse>(DiskStationApi.Info, arguments, settings, "Get api version");
|
|
|
|
|
|
|
|
|
|
|
|
if (infoResponse.Success == true)
|
|
|
|
//TODO: Refactor this into more elegant code
|
|
|
|
{
|
|
|
|
var infoResponeDSAuth = infoResponse.Data["SYNO.API.Auth"];
|
|
|
|
//TODO: Refactor this into more elegant code
|
|
|
|
var infoResponeDSInfo = infoResponse.Data["SYNO.DownloadStation.Info"];
|
|
|
|
var infoResponeDSAuth = infoResponse.Data["SYNO.API.Auth"];
|
|
|
|
var infoResponeDSTask = infoResponse.Data["SYNO.DownloadStation.Task"];
|
|
|
|
var infoResponeDSInfo = infoResponse.Data["SYNO.DownloadStation.Info"];
|
|
|
|
var infoResponseFSList = infoResponse.Data["SYNO.FileStation.List"];
|
|
|
|
var infoResponeDSTask = infoResponse.Data["SYNO.DownloadStation.Task"];
|
|
|
|
var infoResponseDSMInfo = infoResponse.Data["SYNO.DSM.Info"];
|
|
|
|
var infoResponseFSList = infoResponse.Data["SYNO.FileStation.List"];
|
|
|
|
|
|
|
|
var infoResponseDSMInfo = infoResponse.Data["SYNO.DSM.Info"];
|
|
|
|
Resources[DiskStationApi.Auth] = infoResponeDSAuth.Path;
|
|
|
|
|
|
|
|
Resources[DiskStationApi.DownloadStationInfo] = infoResponeDSInfo.Path;
|
|
|
|
Resources[DiskStationApi.Auth] = infoResponeDSAuth.Path;
|
|
|
|
Resources[DiskStationApi.DownloadStationTask] = infoResponeDSTask.Path;
|
|
|
|
Resources[DiskStationApi.DownloadStationInfo] = infoResponeDSInfo.Path;
|
|
|
|
Resources[DiskStationApi.FileStationList] = infoResponseFSList.Path;
|
|
|
|
Resources[DiskStationApi.DownloadStationTask] = infoResponeDSTask.Path;
|
|
|
|
Resources[DiskStationApi.DSMInfo] = infoResponseDSMInfo.Path;
|
|
|
|
Resources[DiskStationApi.FileStationList] = infoResponseFSList.Path;
|
|
|
|
|
|
|
|
Resources[DiskStationApi.DSMInfo] = infoResponseDSMInfo.Path;
|
|
|
|
switch (api)
|
|
|
|
|
|
|
|
|
|
|
|
switch (api)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
case DiskStationApi.Auth:
|
|
|
|
|
|
|
|
return Enumerable.Range(infoResponeDSAuth.MinVersion, infoResponeDSAuth.MaxVersion - infoResponeDSAuth.MinVersion + 1);
|
|
|
|
|
|
|
|
case DiskStationApi.DownloadStationInfo:
|
|
|
|
|
|
|
|
return Enumerable.Range(infoResponeDSInfo.MinVersion, infoResponeDSInfo.MaxVersion - infoResponeDSInfo.MinVersion + 1);
|
|
|
|
|
|
|
|
case DiskStationApi.DownloadStationTask:
|
|
|
|
|
|
|
|
return Enumerable.Range(infoResponeDSTask.MinVersion, infoResponeDSTask.MaxVersion - infoResponeDSTask.MinVersion + 1);
|
|
|
|
|
|
|
|
case DiskStationApi.FileStationList:
|
|
|
|
|
|
|
|
return Enumerable.Range(infoResponseFSList.MinVersion, infoResponseFSList.MaxVersion - infoResponseFSList.MinVersion + 1);
|
|
|
|
|
|
|
|
case DiskStationApi.DSMInfo:
|
|
|
|
|
|
|
|
return Enumerable.Range(infoResponseDSMInfo.MinVersion, infoResponseDSMInfo.MaxVersion - infoResponseDSMInfo.MinVersion + 1);
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
throw new DownloadClientException("Api not implemented");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new DownloadClientException(infoResponse.Error.GetMessage(DiskStationApi.Info));
|
|
|
|
case DiskStationApi.Auth:
|
|
|
|
|
|
|
|
return Enumerable.Range(infoResponeDSAuth.MinVersion, infoResponeDSAuth.MaxVersion - infoResponeDSAuth.MinVersion + 1);
|
|
|
|
|
|
|
|
case DiskStationApi.DownloadStationInfo:
|
|
|
|
|
|
|
|
return Enumerable.Range(infoResponeDSInfo.MinVersion, infoResponeDSInfo.MaxVersion - infoResponeDSInfo.MinVersion + 1);
|
|
|
|
|
|
|
|
case DiskStationApi.DownloadStationTask:
|
|
|
|
|
|
|
|
return Enumerable.Range(infoResponeDSTask.MinVersion, infoResponeDSTask.MaxVersion - infoResponeDSTask.MinVersion + 1);
|
|
|
|
|
|
|
|
case DiskStationApi.FileStationList:
|
|
|
|
|
|
|
|
return Enumerable.Range(infoResponseFSList.MinVersion, infoResponseFSList.MaxVersion - infoResponseFSList.MinVersion + 1);
|
|
|
|
|
|
|
|
case DiskStationApi.DSMInfo:
|
|
|
|
|
|
|
|
return Enumerable.Range(infoResponseDSMInfo.MinVersion, infoResponseDSMInfo.MaxVersion - infoResponseDSMInfo.MinVersion + 1);
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
throw new DownloadClientException("Api not implemented");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|