DownloadAllowed logic moved, using proper validation

pull/2/head
Mark McDowall 11 years ago
parent 689f27bee6
commit a40ad82fa7

@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using FluentValidation;
using Nancy; using Nancy;
using NzbDrone.Api.Mapping; using NzbDrone.Api.Mapping;
using NzbDrone.Api.REST; using NzbDrone.Api.REST;
@ -38,18 +39,14 @@ namespace NzbDrone.Api.Indexers
_parsingService = parsingService; _parsingService = parsingService;
GetResourceAll = GetReleases; GetResourceAll = GetReleases;
Post["/"] = x=> DownloadRelease(this.Bind<ReleaseResource>()); Post["/"] = x=> DownloadRelease(this.Bind<ReleaseResource>());
PostValidator.RuleFor(s => s.DownloadAllowed);
} }
private Response DownloadRelease(ReleaseResource release) private Response DownloadRelease(ReleaseResource release)
{ {
var remoteEpisode = _parsingService.Map(release.InjectTo<ParsedEpisodeInfo>(), 0); var remoteEpisode = _parsingService.Map(release.InjectTo<ParsedEpisodeInfo>(), 0);
remoteEpisode.Release = release.InjectTo<ReleaseInfo>(); remoteEpisode.Release = release.InjectTo<ReleaseInfo>();
if (remoteEpisode.Series == null || remoteEpisode.Episodes == null || !remoteEpisode.Episodes.Any())
{
throw new BadRequestException(release);
}
_downloadService.DownloadReport(remoteEpisode); _downloadService.DownloadReport(remoteEpisode);
return release.AsResponse(); return release.AsResponse();
@ -92,7 +89,6 @@ namespace NzbDrone.Api.Indexers
release.InjectFrom(downloadDecision.RemoteEpisode.ParsedEpisodeInfo); release.InjectFrom(downloadDecision.RemoteEpisode.ParsedEpisodeInfo);
release.InjectFrom(downloadDecision); release.InjectFrom(downloadDecision);
release.Rejections = downloadDecision.Rejections.ToList(); release.Rejections = downloadDecision.Rejections.ToList();
release.DownloadAllowed = downloadDecision.RemoteEpisode.Series != null;
result.Add(release); result.Add(release);
} }

@ -1,4 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NzbDrone.Common.EnsureThat.Resources; using NzbDrone.Common.EnsureThat.Resources;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
@ -73,7 +76,6 @@ namespace NzbDrone.Common.EnsureThat
return param; return param;
} }
[DebuggerStepThrough] [DebuggerStepThrough]
public static Param<string> IsRelativePath(this Param<string> param) public static Param<string> IsRelativePath(this Param<string> param)
{ {
@ -94,8 +96,6 @@ namespace NzbDrone.Common.EnsureThat
return param; return param;
} }
[DebuggerStepThrough] [DebuggerStepThrough]
public static Param<string> IsValidPath(this Param<string> param) public static Param<string> IsValidPath(this Param<string> param)
{ {

@ -74,6 +74,7 @@ namespace NzbDrone.Core.DecisionEngine
} }
else else
{ {
remoteEpisode.DownloadAllowed = false;
decision = new DownloadDecision(remoteEpisode, "Unknown Series"); decision = new DownloadDecision(remoteEpisode, "Unknown Series");
} }
} }

@ -1,4 +1,5 @@
using NLog; using NLog;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Core.Instrumentation; using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
@ -27,6 +28,10 @@ namespace NzbDrone.Core.Download
public void DownloadReport(RemoteEpisode remoteEpisode) 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 downloadTitle = remoteEpisode.Release.Title;
var downloadClient = _downloadClientProvider.GetDownloadClient(); var downloadClient = _downloadClientProvider.GetDownloadClient();

@ -8,12 +8,10 @@ namespace NzbDrone.Core.Parser.Model
public class RemoteEpisode public class RemoteEpisode
{ {
public ReleaseInfo Release { get; set; } public ReleaseInfo Release { get; set; }
public ParsedEpisodeInfo ParsedEpisodeInfo { get; set; } public ParsedEpisodeInfo ParsedEpisodeInfo { get; set; }
public Series Series { get; set; } public Series Series { get; set; }
public List<Episode> Episodes { get; set; } public List<Episode> Episodes { get; set; }
public Boolean DownloadAllowed { get; set; }
public bool IsRecentEpisode() public bool IsRecentEpisode()
{ {

Loading…
Cancel
Save