mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-22 06:50:33 -04:00
Fix random seed parsing when non uint where specifed
This commit is contained in:
parent
9f42c29714
commit
dee3af3016
@ -102,7 +102,11 @@ public record Sort<T> : Sort
|
|||||||
return new Conglomerate(sortBy.Split(',').Select(x => From(x, seed)).ToArray());
|
return new Conglomerate(sortBy.Split(',').Select(x => From(x, seed)).ToArray());
|
||||||
|
|
||||||
if (sortBy.StartsWith("random:"))
|
if (sortBy.StartsWith("random:"))
|
||||||
return new Random(uint.Parse(sortBy["random:".Length..]));
|
{
|
||||||
|
if (uint.TryParse(sortBy["random:".Length..], out uint sseed))
|
||||||
|
return new Random(sseed);
|
||||||
|
throw new ValidationException("Invalid random seed specified. Expected a number.");
|
||||||
|
}
|
||||||
|
|
||||||
string key = sortBy.Contains(':') ? sortBy[..sortBy.IndexOf(':')] : sortBy;
|
string key = sortBy.Contains(':') ? sortBy[..sortBy.IndexOf(':')] : sortBy;
|
||||||
string? order = sortBy.Contains(':') ? sortBy[(sortBy.IndexOf(':') + 1)..] : null;
|
string? order = sortBy.Contains(':') ? sortBy[(sortBy.IndexOf(':') + 1)..] : null;
|
||||||
|
@ -43,7 +43,7 @@ public class SortBinder : IModelBinder
|
|||||||
{
|
{
|
||||||
object sort = bindingContext
|
object sort = bindingContext
|
||||||
.ModelType.GetMethod(nameof(Sort<Movie>.From))!
|
.ModelType.GetMethod(nameof(Sort<Movie>.From))!
|
||||||
.Invoke(null, new object?[] { sortBy.FirstValue, seed })!;
|
.Invoke(null, [sortBy.FirstValue, seed])!;
|
||||||
bindingContext.Result = ModelBindingResult.Success(sort);
|
bindingContext.Result = ModelBindingResult.Success(sort);
|
||||||
bindingContext.HttpContext.Items["seed"] = seed;
|
bindingContext.HttpContext.Items["seed"] = seed;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user