Fixed: Re-Clean Release Endpoints, we have ReadResourceFromRequest!

This commit is contained in:
Qstick
2019-04-05 23:51:21 -04:00
parent f0365eaaa7
commit 7bd96ae75c
3 changed files with 24 additions and 53 deletions
+4 -16
View File
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentValidation;
using Nancy;
using Nancy.ModelBinding;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Core.DecisionEngine;
@@ -14,7 +12,6 @@ using NzbDrone.Core.IndexerSearch;
using NzbDrone.Core.Parser.Model;
using NzbDrone.Core.Validation;
using Lidarr.Http.Extensions;
using Lidarr.Http.REST;
using HttpStatusCode = System.Net.HttpStatusCode;
namespace Lidarr.Api.V1.Indexers
@@ -27,7 +24,6 @@ namespace Lidarr.Api.V1.Indexers
private readonly IPrioritizeDownloadDecision _prioritizeDownloadDecision;
private readonly IDownloadService _downloadService;
private readonly Logger _logger;
private ResourceValidator<ReleaseResource> _releaseValidator;
private readonly ICached<RemoteAlbum> _remoteAlbumCache;
@@ -46,25 +42,17 @@ namespace Lidarr.Api.V1.Indexers
_downloadService = downloadService;
_logger = logger;
_releaseValidator = new ResourceValidator<ReleaseResource>();
_releaseValidator.RuleFor(s => s.IndexerId).ValidId();
_releaseValidator.RuleFor(s => s.Guid).NotEmpty();
GetResourceAll = GetReleases;
Post["/"] = x => DownloadRelease(this.Bind<ReleaseResource>());
Post["/"] = x => DownloadRelease(ReadResourceFromRequest());
PostValidator.RuleFor(s => s.IndexerId).ValidId();
PostValidator.RuleFor(s => s.Guid).NotEmpty();
_remoteAlbumCache = cacheManager.GetCache<RemoteAlbum>(GetType(), "remoteAlbums");
}
private Response DownloadRelease(ReleaseResource release)
{
var validationFailures = _releaseValidator.Validate(release).Errors;
if (validationFailures.Any())
{
throw new ValidationException(validationFailures);
}
var remoteAlbum = _remoteAlbumCache.Find(GetCacheKey(release));
if (remoteAlbum == null)