1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-16 21:15:33 -04:00

Fixed: Validation for Movie Info language

This commit is contained in:
Bogdan
2024-08-18 00:21:04 +03:00
parent 0ad4d7ea9a
commit c9f28fdc4f
5 changed files with 26 additions and 12 deletions

View File

@@ -177,6 +177,8 @@ namespace NzbDrone.Core.Languages
}
}
private static readonly Dictionary<int, Language> Lookup = All.ToDictionary(v => v.Id);
public static Language FindById(int id)
{
if (id == 0)
@@ -184,9 +186,7 @@ namespace NzbDrone.Core.Languages
return Unknown;
}
var language = All.FirstOrDefault(v => v.Id == id);
if (language == null)
if (!Lookup.TryGetValue(id, out var language))
{
throw new ArgumentException("ID does not match a known language", nameof(id));
}

View File

@@ -797,6 +797,7 @@
"InteractiveSearchResultsFailedErrorMessage": "Search failed because its {message}. Try refreshing the movie info and verify the necessary information is present before searching again.",
"Interval": "Interval",
"InvalidFormat": "Invalid Format",
"InvalidMovieInfoLanguageLanguage": "Your Movie Info Language is set to an invalid value, correct it and save your settings",
"InvalidUILanguage": "Your UI is set to an invalid language, correct it and save your settings",
"KeepAndUnmonitorMovie": "Keep and Unmonitor Movie",
"KeyboardShortcuts": "Keyboard Shortcuts",

View File

@@ -19,17 +19,21 @@ namespace Radarr.Api.V3.Config
{
_configFileProvider = configFileProvider;
SharedValidator.RuleFor(c => c.UILanguage).Custom((value, context) =>
{
if (!Language.All.Any(o => o.Id == value))
{
context.AddFailure("Invalid UI Language ID");
}
});
SharedValidator.RuleFor(c => c.MovieInfoLanguage)
.GreaterThanOrEqualTo(1)
.WithMessage("The Movie Info Language value cannot be less than 1");
SharedValidator.RuleFor(c => c.MovieInfoLanguage)
.Must(value => Language.All.Any(o => o.Id == value))
.WithMessage("Invalid Movie Info Language ID");
SharedValidator.RuleFor(c => c.UILanguage)
.GreaterThanOrEqualTo(1)
.WithMessage("The UI Language value cannot be less than 1");
.GreaterThanOrEqualTo(1)
.WithMessage("The UI Language value cannot be less than 1");
SharedValidator.RuleFor(c => c.UILanguage)
.Must(value => Language.All.Any(o => o.Id == value))
.WithMessage("Invalid UI Language ID");
}
[RestPutById]