mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-22 05:50:56 +00:00
DownloadAllowed logic moved, using proper validation
This commit is contained in:
parent
689f27bee6
commit
a40ad82fa7
5 changed files with 13 additions and 13 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using FluentValidation;
|
||||
using Nancy;
|
||||
using NzbDrone.Api.Mapping;
|
||||
using NzbDrone.Api.REST;
|
||||
|
@ -38,18 +39,14 @@ public ReleaseModule(IFetchAndParseRss rssFetcherAndParser,
|
|||
_parsingService = parsingService;
|
||||
GetResourceAll = GetReleases;
|
||||
Post["/"] = x=> DownloadRelease(this.Bind<ReleaseResource>());
|
||||
|
||||
PostValidator.RuleFor(s => s.DownloadAllowed);
|
||||
}
|
||||
|
||||
private Response DownloadRelease(ReleaseResource release)
|
||||
{
|
||||
var remoteEpisode = _parsingService.Map(release.InjectTo<ParsedEpisodeInfo>(), 0);
|
||||
remoteEpisode.Release = release.InjectTo<ReleaseInfo>();
|
||||
|
||||
if (remoteEpisode.Series == null || remoteEpisode.Episodes == null || !remoteEpisode.Episodes.Any())
|
||||
{
|
||||
throw new BadRequestException(release);
|
||||
}
|
||||
|
||||
_downloadService.DownloadReport(remoteEpisode);
|
||||
|
||||
return release.AsResponse();
|
||||
|
@ -92,7 +89,6 @@ private static List<ReleaseResource> MapDecisions(IEnumerable<DownloadDecision>
|
|||
release.InjectFrom(downloadDecision.RemoteEpisode.ParsedEpisodeInfo);
|
||||
release.InjectFrom(downloadDecision);
|
||||
release.Rejections = downloadDecision.Rejections.ToList();
|
||||
release.DownloadAllowed = downloadDecision.RemoteEpisode.Series != null;
|
||||
|
||||
result.Add(release);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Common.EnsureThat.Resources;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
@ -73,7 +76,6 @@ public static Param<string> Matches(this Param<string> param, Regex match)
|
|||
return param;
|
||||
}
|
||||
|
||||
|
||||
[DebuggerStepThrough]
|
||||
public static Param<string> IsRelativePath(this Param<string> param)
|
||||
{
|
||||
|
@ -94,8 +96,6 @@ public static Param<string> IsRelativePath(this Param<string> param)
|
|||
return param;
|
||||
}
|
||||
|
||||
|
||||
|
||||
[DebuggerStepThrough]
|
||||
public static Param<string> IsValidPath(this Param<string> param)
|
||||
{
|
||||
|
|
|
@ -74,6 +74,7 @@ private IEnumerable<DownloadDecision> GetDecisions(List<ReleaseInfo> reports, Se
|
|||
}
|
||||
else
|
||||
{
|
||||
remoteEpisode.DownloadAllowed = false;
|
||||
decision = new DownloadDecision(remoteEpisode, "Unknown Series");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using NLog;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Core.Instrumentation;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
@ -27,6 +28,10 @@ public DownloadService(IProvideDownloadClient downloadClientProvider,
|
|||
|
||||
public void DownloadReport(RemoteEpisode remoteEpisode)
|
||||
{
|
||||
Ensure.That(() => remoteEpisode.Series).IsNotNull();
|
||||
Ensure.That(() => remoteEpisode.Episodes).IsNotNull();
|
||||
Ensure.That(() => remoteEpisode.Episodes).HasItems();
|
||||
|
||||
var downloadTitle = remoteEpisode.Release.Title;
|
||||
var downloadClient = _downloadClientProvider.GetDownloadClient();
|
||||
|
||||
|
|
|
@ -8,12 +8,10 @@ namespace NzbDrone.Core.Parser.Model
|
|||
public class RemoteEpisode
|
||||
{
|
||||
public ReleaseInfo Release { get; set; }
|
||||
|
||||
public ParsedEpisodeInfo ParsedEpisodeInfo { get; set; }
|
||||
|
||||
public Series Series { get; set; }
|
||||
|
||||
public List<Episode> Episodes { get; set; }
|
||||
public Boolean DownloadAllowed { get; set; }
|
||||
|
||||
public bool IsRecentEpisode()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue