mirror of https://github.com/Radarr/Radarr
Series and Season folder format validation/error handling
This commit is contained in:
parent
40c2c0b533
commit
fc540067c2
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using FluentValidation;
|
||||
using FluentValidation.Results;
|
||||
using Nancy.Responses;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using Nancy.ModelBinding;
|
||||
using NzbDrone.Api.Mapping;
|
||||
|
@ -39,6 +40,7 @@ namespace NzbDrone.Api.Config
|
|||
SharedValidator.RuleFor(c => c.StandardEpisodeFormat).ValidEpisodeFormat();
|
||||
SharedValidator.RuleFor(c => c.DailyEpisodeFormat).ValidDailyEpisodeFormat();
|
||||
SharedValidator.RuleFor(c => c.SeriesFolderFormat).ValidSeriesFolderFormat();
|
||||
SharedValidator.RuleFor(c => c.SeasonFolderFormat).ValidSeasonFolderFormat();
|
||||
}
|
||||
|
||||
private void UpdateNamingConfig(NamingConfigResource resource)
|
||||
|
@ -72,7 +74,6 @@ namespace NzbDrone.Api.Config
|
|||
|
||||
private JsonResponse<NamingSampleResource> GetExamples(NamingConfigResource config)
|
||||
{
|
||||
//TODO: Validate that the format is valid
|
||||
var nameSpec = config.InjectTo<NamingConfig>();
|
||||
var sampleResource = new NamingSampleResource();
|
||||
|
||||
|
@ -92,8 +93,13 @@ namespace NzbDrone.Api.Config
|
|||
? "Invalid format"
|
||||
: dailyEpisodeSampleResult.Filename;
|
||||
|
||||
sampleResource.SeriesFolderExample = _filenameSampleService.GetSeriesFolderSample(nameSpec);
|
||||
sampleResource.SeasonFolderExample = _filenameSampleService.GetSeasonFolderSample(nameSpec);
|
||||
sampleResource.SeriesFolderExample = nameSpec.SeriesFolderFormat.IsNullOrWhiteSpace()
|
||||
? "Invalid format"
|
||||
: _filenameSampleService.GetSeriesFolderSample(nameSpec);
|
||||
|
||||
sampleResource.SeasonFolderExample = nameSpec.SeasonFolderFormat.IsNullOrWhiteSpace()
|
||||
? "Invalid format"
|
||||
: _filenameSampleService.GetSeasonFolderSample(nameSpec);
|
||||
|
||||
return sampleResource.AsResponse();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
using FluentValidation;
|
||||
using FluentValidation.Validators;
|
||||
|
||||
|
@ -6,6 +7,9 @@ namespace NzbDrone.Core.Organizer
|
|||
{
|
||||
public static class FileNameValidation
|
||||
{
|
||||
private static readonly Regex SeasonFolderRegex = new Regex(@"(\{season(\:\d+)?\})",
|
||||
RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
public static IRuleBuilderOptions<T, string> ValidEpisodeFormat<T>(this IRuleBuilder<T, string> ruleBuilder)
|
||||
{
|
||||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||
|
@ -23,6 +27,12 @@ namespace NzbDrone.Core.Organizer
|
|||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||
return ruleBuilder.SetValidator(new RegularExpressionValidator(FileNameBuilder.SeriesTitleRegex)).WithMessage("Must contain series title");
|
||||
}
|
||||
|
||||
public static IRuleBuilderOptions<T, string> ValidSeasonFolderFormat<T>(this IRuleBuilder<T, string> ruleBuilder)
|
||||
{
|
||||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||
return ruleBuilder.SetValidator(new RegularExpressionValidator(SeasonFolderRegex)).WithMessage("Must contain season number");
|
||||
}
|
||||
}
|
||||
|
||||
public class ValidDailyEpisodeFormatValidator : PropertyValidator
|
||||
|
|
Loading…
Reference in New Issue