Adding a security for only int resources & adding a silent fail

This commit is contained in:
Zoe Roux 2020-09-21 00:36:22 +02:00
parent 522d253e9c
commit 5a1826d01d
19 changed files with 176 additions and 148 deletions

View File

@ -93,6 +93,19 @@ namespace Kyoo.Controllers
Task<T> Create([NotNull] T obj);
Task<T> CreateIfNotExists([NotNull] T obj);
Task<T> CreateIfNotExists([NotNull] T obj, bool silentFail)
{
try
{
return CreateIfNotExists(obj);
}
catch
{
if (!silentFail)
throw;
return null;
}
}
Task<T> Edit([NotNull] T edited, bool resetOld);
Task Delete(int id);

View File

@ -28,11 +28,11 @@ namespace Kyoo.CommonApi
[JsonDetailed]
public virtual async Task<ActionResult<T>> Get(int id)
{
T ressource = await _repository.Get(id);
if (ressource == null)
T resource = await _repository.Get(id);
if (resource == null)
return NotFound();
return ressource;
return resource;
}
[HttpGet("{slug}")]
@ -60,11 +60,11 @@ namespace Kyoo.CommonApi
try
{
ICollection<T> ressources = await _repository.GetAll(ApiHelper.ParseWhere<T>(where),
ICollection<T> resources = await _repository.GetAll(ApiHelper.ParseWhere<T>(where),
new Sort<T>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ArgumentException ex)
{
@ -72,10 +72,10 @@ namespace Kyoo.CommonApi
}
}
protected Page<TResult> Page<TResult>(ICollection<TResult> ressources, int limit)
protected Page<TResult> Page<TResult>(ICollection<TResult> resources, int limit)
where TResult : IResource
{
return new Page<TResult>(ressources,
return new Page<TResult>(resources,
_baseURL + Request.Path,
Request.Query.ToDictionary(x => x.Key, x => x.Value.ToString(), StringComparer.InvariantCultureIgnoreCase),
limit);
@ -83,11 +83,11 @@ namespace Kyoo.CommonApi
[HttpPost]
[Authorize(Policy = "Write")]
public virtual async Task<ActionResult<T>> Create([FromBody] T ressource)
public virtual async Task<ActionResult<T>> Create([FromBody] T resource)
{
try
{
return await _repository.Create(ressource);
return await _repository.Create(resource);
}
catch (ArgumentException ex)
{
@ -95,34 +95,34 @@ namespace Kyoo.CommonApi
}
catch (DuplicatedItemException)
{
T existing = await _repository.Get(ressource.Slug);
T existing = await _repository.Get(resource.Slug);
return Conflict(existing);
}
}
[HttpPut]
[Authorize(Policy = "Write")]
public virtual async Task<ActionResult<T>> Edit([FromQuery] bool resetOld, [FromBody] T ressource)
public virtual async Task<ActionResult<T>> Edit([FromQuery] bool resetOld, [FromBody] T resource)
{
if (ressource.ID > 0)
return await _repository.Edit(ressource, resetOld);
if (resource.ID > 0)
return await _repository.Edit(resource, resetOld);
T old = await _repository.Get(ressource.Slug);
T old = await _repository.Get(resource.Slug);
if (old == null)
return NotFound();
ressource.ID = old.ID;
return await _repository.Edit(ressource, resetOld);
resource.ID = old.ID;
return await _repository.Edit(resource, resetOld);
}
[HttpPut("{id:int}")]
[Authorize(Policy = "Write")]
public virtual async Task<ActionResult<T>> Edit(int id, [FromQuery] bool resetOld, [FromBody] T ressource)
public virtual async Task<ActionResult<T>> Edit(int id, [FromQuery] bool resetOld, [FromBody] T resource)
{
ressource.ID = id;
resource.ID = id;
try
{
return await _repository.Edit(ressource, resetOld);
return await _repository.Edit(resource, resetOld);
}
catch (ItemNotFound)
{
@ -132,13 +132,13 @@ namespace Kyoo.CommonApi
[HttpPut("{slug}")]
[Authorize(Policy = "Write")]
public virtual async Task<ActionResult<T>> Edit(string slug, [FromQuery] bool resetOld, [FromBody] T ressource)
public virtual async Task<ActionResult<T>> Edit(string slug, [FromQuery] bool resetOld, [FromBody] T resource)
{
T old = await _repository.Get(slug);
if (old == null)
return NotFound();
ressource.ID = old.ID;
return await _repository.Edit(ressource, resetOld);
resource.ID = old.ID;
return await _repository.Edit(resource, resetOld);
}
[HttpDelete("{id:int}")]

View File

@ -138,7 +138,7 @@ namespace Kyoo.Controllers
T old = await Get(edited.Slug);
if (old == null)
throw new ItemNotFound($"No ressource found with the slug {edited.Slug}.");
throw new ItemNotFound($"No resource found with the slug {edited.Slug}.");
if (resetOld)
Utility.Nullify(old);
@ -148,34 +148,49 @@ namespace Kyoo.Controllers
return old;
}
protected virtual Task Validate(T ressource)
protected virtual Task Validate(T resource)
{
if (ressource.Slug == null)
throw new ArgumentException("Ressource can't have null as a slug.");
if (string.IsNullOrEmpty(resource.Slug))
throw new ArgumentException("Resource can't have null as a slug.");
if (int.TryParse(resource.Slug, out int _))
{
try
{
MethodInfo setter = typeof(T).GetProperty(nameof(resource.Slug))!.GetSetMethod();
if (setter != null)
setter.Invoke(resource, new object[] {resource.Slug + '!'});
else
throw new ArgumentException("Resources slug can't be number only.");
}
catch
{
throw new ArgumentException("Resources slug can't be number only.");
}
}
foreach (PropertyInfo property in typeof(T).GetProperties()
.Where(x => typeof(IEnumerable).IsAssignableFrom(x.PropertyType)
&& !typeof(string).IsAssignableFrom(x.PropertyType)))
{
object value = property.GetValue(ressource);
object value = property.GetValue(resource);
if (value is ICollection || value == null)
continue;
value = Utility.RunGenericMethod(typeof(Enumerable), "ToList", Utility.GetEnumerableType((IEnumerable)value), value);
property.SetValue(ressource, value);
property.SetValue(resource, value);
}
return Task.CompletedTask;
}
public virtual async Task Delete(int id)
{
T ressource = await Get(id);
await Delete(ressource);
T resource = await Get(id);
await Delete(resource);
}
public virtual async Task Delete(string slug)
{
T ressource = await Get(slug);
await Delete(ressource);
T resource = await Get(slug);
await Delete(resource);
}
public abstract Task Delete(T obj);

View File

@ -110,17 +110,17 @@ namespace Kyoo.Controllers
return obj;
}
protected override async Task Validate(Episode obj)
protected override async Task Validate(Episode resource)
{
if (obj.ShowID <= 0)
throw new InvalidOperationException($"Can't store an episode not related to any show (showID: {obj.ShowID}).");
if (resource.ShowID <= 0)
throw new InvalidOperationException($"Can't store an episode not related to any show (showID: {resource.ShowID}).");
await base.Validate(obj);
await base.Validate(resource);
if (obj.ExternalIDs != null)
if (resource.ExternalIDs != null)
{
foreach (MetadataID link in obj.ExternalIDs)
link.Provider = await _providers.CreateIfNotExists(link.Provider);
foreach (MetadataID link in resource.ExternalIDs)
link.Provider = await _providers.CreateIfNotExists(link.Provider, true);
}
}

View File

@ -94,7 +94,7 @@ namespace Kyoo.Controllers
public override Task<LibraryItem> Create(LibraryItem obj) => throw new InvalidOperationException();
public override Task<LibraryItem> CreateIfNotExists(LibraryItem obj) => throw new InvalidOperationException();
public override Task<LibraryItem> Edit(LibraryItem obj, bool reset) => throw new InvalidOperationException();
protected override Task Validate(LibraryItem obj) => throw new InvalidOperationException();
protected override Task Validate(LibraryItem resource) => throw new InvalidOperationException();
public override Task Delete(int id) => throw new InvalidOperationException();
public override Task Delete(string slug) => throw new InvalidOperationException();
public override Task Delete(LibraryItem obj) => throw new InvalidOperationException();

View File

@ -63,20 +63,20 @@ namespace Kyoo.Controllers
return obj;
}
protected override async Task Validate(LibraryDE obj)
protected override async Task Validate(LibraryDE resource)
{
if (string.IsNullOrEmpty(obj.Slug))
if (string.IsNullOrEmpty(resource.Slug))
throw new ArgumentException("The library's slug must be set and not empty");
if (string.IsNullOrEmpty(obj.Name))
if (string.IsNullOrEmpty(resource.Name))
throw new ArgumentException("The library's name must be set and not empty");
if (obj.Paths == null || !obj.Paths.Any())
if (resource.Paths == null || !resource.Paths.Any())
throw new ArgumentException("The library should have a least one path.");
await base.Validate(obj);
await base.Validate(resource);
if (obj.ProviderLinks != null)
foreach (ProviderLink link in obj.ProviderLinks)
link.Provider = await _providers.CreateIfNotExists(link.Provider);
if (resource.ProviderLinks != null)
foreach (ProviderLink link in resource.ProviderLinks)
link.Provider = await _providers.CreateIfNotExists(link.Provider, true);
}
public override async Task Delete(LibraryDE obj)

View File

@ -69,13 +69,13 @@ namespace Kyoo.Controllers
return obj;
}
protected override async Task Validate(People obj)
protected override async Task Validate(People resource)
{
await base.Validate(obj);
await base.Validate(resource);
if (obj.ExternalIDs != null)
foreach (MetadataID link in obj.ExternalIDs)
link.Provider = await _providers.CreateIfNotExists(link.Provider);
if (resource.ExternalIDs != null)
foreach (MetadataID link in resource.ExternalIDs)
link.Provider = await _providers.CreateIfNotExists(link.Provider, true);
}
public override async Task Delete(People obj)

View File

@ -94,17 +94,17 @@ namespace Kyoo.Controllers
return obj;
}
protected override async Task Validate(Season obj)
protected override async Task Validate(Season resource)
{
if (obj.ShowID <= 0)
throw new InvalidOperationException($"Can't store a season not related to any show (showID: {obj.ShowID}).");
if (resource.ShowID <= 0)
throw new InvalidOperationException($"Can't store a season not related to any show (showID: {resource.ShowID}).");
await base.Validate(obj);
await base.Validate(resource);
if (obj.ExternalIDs != null)
if (resource.ExternalIDs != null)
{
foreach (MetadataID link in obj.ExternalIDs)
link.Provider = await _providers.CreateIfNotExists(link.Provider);
foreach (MetadataID link in resource.ExternalIDs)
link.Provider = await _providers.CreateIfNotExists(link.Provider, true);
}
}

View File

@ -106,24 +106,24 @@ namespace Kyoo.Controllers
return obj;
}
protected override async Task Validate(ShowDE obj)
protected override async Task Validate(ShowDE resource)
{
await base.Validate(obj);
await base.Validate(resource);
if (obj.Studio != null)
obj.Studio = await _studios.CreateIfNotExists(obj.Studio);
if (resource.Studio != null)
resource.Studio = await _studios.CreateIfNotExists(resource.Studio, true);
if (obj.GenreLinks != null)
foreach (GenreLink link in obj.GenreLinks)
link.Genre = await _genres.CreateIfNotExists(link.Genre);
if (resource.GenreLinks != null)
foreach (GenreLink link in resource.GenreLinks)
link.Genre = await _genres.CreateIfNotExists(link.Genre, true);
if (obj.People != null)
foreach (PeopleRole link in obj.People)
link.People = await _people.CreateIfNotExists(link.People);
if (resource.People != null)
foreach (PeopleRole link in resource.People)
link.People = await _people.CreateIfNotExists(link.People, true);
if (obj.ExternalIDs != null)
foreach (MetadataID link in obj.ExternalIDs)
link.Provider = await _providers.CreateIfNotExists(link.Provider);
if (resource.ExternalIDs != null)
foreach (MetadataID link in resource.ExternalIDs)
link.Provider = await _providers.CreateIfNotExists(link.Provider, true);
}
public async Task AddShowLink(int showID, int? libraryID, int? collectionID)

View File

@ -75,7 +75,7 @@ namespace Kyoo.Controllers
return obj;
}
protected override Task Validate(Track ressource)
protected override Task Validate(Track resource)
{
return Task.CompletedTask;
}

View File

@ -40,12 +40,12 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShows(
ICollection<Show> resources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Collections.Any(y => y.ID == id)),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -72,12 +72,12 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShows(
ICollection<Show> resources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Collections.Any(y => y.Slug == slug)),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -104,12 +104,12 @@ namespace Kyoo.Api
try
{
ICollection<Library> ressources = await _libraryManager.GetLibraries(
ICollection<Library> resources = await _libraryManager.GetLibraries(
ApiHelper.ParseWhere<Library>(where, x => x.Collections.Any(y => y.ID == id)),
new Sort<Library>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -136,12 +136,12 @@ namespace Kyoo.Api
try
{
ICollection<Library> ressources = await _libraryManager.GetLibraries(
ICollection<Library> resources = await _libraryManager.GetLibraries(
ApiHelper.ParseWhere<Library>(where, x => x.Collections.Any(y => y.Slug == slug)),
new Sort<Library>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{

View File

@ -82,12 +82,12 @@ namespace Kyoo.Api
try
{
ICollection<Track> ressources = await _libraryManager.GetTracks(
ICollection<Track> resources = await _libraryManager.GetTracks(
ApiHelper.ParseWhere<Track>(where, x => x.Episode.ID == episodeID),
new Sort<Track>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -116,14 +116,14 @@ namespace Kyoo.Api
try
{
ICollection<Track> ressources = await _libraryManager.GetTracks(
ICollection<Track> resources = await _libraryManager.GetTracks(
ApiHelper.ParseWhere<Track>(where, x => x.Episode.ShowID == showID
&& x.Episode.SeasonNumber == seasonNumber
&& x.Episode.EpisodeNumber == episodeNumber),
new Sort<Track>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -152,13 +152,13 @@ namespace Kyoo.Api
try
{
ICollection<Track> ressources = await _libraryManager.GetTracks(ApiHelper.ParseWhere<Track>(where, x => x.Episode.Show.Slug == showSlug
ICollection<Track> resources = await _libraryManager.GetTracks(ApiHelper.ParseWhere<Track>(where, x => x.Episode.Show.Slug == showSlug
&& x.Episode.SeasonNumber == seasonNumber
&& x.Episode.EpisodeNumber == episodeNumber),
new Sort<Track>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{

View File

@ -40,14 +40,14 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShows(
ICollection<Show> resources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Genres.Any(y => y.ID == id)),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
if (!ressources.Any() && await _libraryManager.GetGenre(id) == null)
if (!resources.Any() && await _libraryManager.GetGenre(id) == null)
return NotFound();
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -74,14 +74,14 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShows(
ICollection<Show> resources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Genres.Any(y => y.Slug == slug)),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
if (!ressources.Any() && await _libraryManager.GetGenre(slug) == null)
if (!resources.Any() && await _libraryManager.GetGenre(slug) == null)
return NotFound();
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{

View File

@ -28,9 +28,9 @@ namespace Kyoo.Api
}
[Authorize(Policy = "Admin")]
public override async Task<ActionResult<Library>> Create(Library ressource)
public override async Task<ActionResult<Library>> Create(Library resource)
{
ActionResult<Library> result = await base.Create(ressource);
ActionResult<Library> result = await base.Create(resource);
if (result.Value != null)
_taskManager.StartTask("scan", result.Value.Slug);
return result;
@ -51,12 +51,12 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShows(
ICollection<Show> resources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Libraries.Any(y => y.ID == id)),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -83,12 +83,12 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShows(
ICollection<Show> resources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Libraries.Any(y => y.Slug == slug)),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -115,12 +115,12 @@ namespace Kyoo.Api
try
{
ICollection<Collection> ressources = await _libraryManager.GetCollections(
ICollection<Collection> resources = await _libraryManager.GetCollections(
ApiHelper.ParseWhere<Collection>(where, x => x.Libraries.Any(y => y.ID == id)),
new Sort<Collection>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -147,12 +147,12 @@ namespace Kyoo.Api
try
{
ICollection<Collection> ressources = await _libraryManager.GetCollections(
ICollection<Collection> resources = await _libraryManager.GetCollections(
ApiHelper.ParseWhere<Collection>(where, x => x.Libraries.Any(y => y.Slug == slug)),
new Sort<Collection>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -179,12 +179,12 @@ namespace Kyoo.Api
try
{
ICollection<LibraryItem> ressources = await _libraryManager.GetItemsFromLibrary(id,
ICollection<LibraryItem> resources = await _libraryManager.GetItemsFromLibrary(id,
ApiHelper.ParseWhere<LibraryItem>(where),
new Sort<LibraryItem>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -211,12 +211,12 @@ namespace Kyoo.Api
try
{
ICollection<LibraryItem> ressources = await _libraryManager.GetItemsFromLibrary(slug,
ICollection<LibraryItem> resources = await _libraryManager.GetItemsFromLibrary(slug,
ApiHelper.ParseWhere<LibraryItem>(where),
new Sort<LibraryItem>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{

View File

@ -40,12 +40,12 @@ namespace Kyoo.Api
try
{
ICollection<LibraryItem> ressources = await _libraryItems.GetAll(
ICollection<LibraryItem> resources = await _libraryItems.GetAll(
ApiHelper.ParseWhere<LibraryItem>(where),
new Sort<LibraryItem>(sortBy),
new Pagination(limit, afterID));
return new Page<LibraryItem>(ressources,
return new Page<LibraryItem>(resources,
_baseURL + Request.Path,
Request.Query.ToDictionary(x => x.Key, x => x.Value.ToString(), StringComparer.InvariantCultureIgnoreCase),
limit);

View File

@ -73,12 +73,12 @@ namespace Kyoo.Api
try
{
ICollection<ShowRole> ressources = await _libraryManager.GetRolesFromPeople(slug,
ICollection<ShowRole> resources = await _libraryManager.GetRolesFromPeople(slug,
ApiHelper.ParseWhere<ShowRole>(where),
new Sort<ShowRole>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{

View File

@ -40,12 +40,12 @@ namespace Kyoo.Api
try
{
ICollection<Episode> ressources = await _libraryManager.GetEpisodes(
ICollection<Episode> resources = await _libraryManager.GetEpisodes(
ApiHelper.ParseWhere<Episode>(where, x => x.SeasonID == seasonID),
new Sort<Episode>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -73,13 +73,13 @@ namespace Kyoo.Api
try
{
ICollection<Episode> ressources = await _libraryManager.GetEpisodes(
ICollection<Episode> resources = await _libraryManager.GetEpisodes(
ApiHelper.ParseWhere<Episode>(where, x => x.Show.Slug == showSlug
&& x.SeasonNumber == seasonNumber),
new Sort<Episode>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -107,12 +107,12 @@ namespace Kyoo.Api
try
{
ICollection<Episode> ressources = await _libraryManager.GetEpisodes(
ICollection<Episode> resources = await _libraryManager.GetEpisodes(
ApiHelper.ParseWhere<Episode>(where, x => x.ShowID == showID && x.SeasonNumber == seasonNumber),
new Sort<Episode>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{

View File

@ -40,12 +40,12 @@ namespace Kyoo.Api
try
{
ICollection<Season> ressources = await _libraryManager.GetSeasons(
ICollection<Season> resources = await _libraryManager.GetSeasons(
ApiHelper.ParseWhere<Season>(where, x => x.ShowID == showID),
new Sort<Season>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -72,12 +72,12 @@ namespace Kyoo.Api
try
{
ICollection<Season> ressources = await _libraryManager.GetSeasons(
ICollection<Season> resources = await _libraryManager.GetSeasons(
ApiHelper.ParseWhere<Season>(where, x => x.Show.Slug == slug),
new Sort<Season>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -104,12 +104,12 @@ namespace Kyoo.Api
try
{
ICollection<Episode> ressources = await _libraryManager.GetEpisodes(
ICollection<Episode> resources = await _libraryManager.GetEpisodes(
ApiHelper.ParseWhere<Episode>(where, x => x.ShowID == showID),
new Sort<Episode>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -136,12 +136,12 @@ namespace Kyoo.Api
try
{
ICollection<Episode> ressources = await _libraryManager.GetEpisodes(
ICollection<Episode> resources = await _libraryManager.GetEpisodes(
ApiHelper.ParseWhere<Episode>(where, x => x.Show.Slug == slug),
new Sort<Episode>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -167,12 +167,12 @@ namespace Kyoo.Api
try
{
ICollection<PeopleRole> ressources = await _libraryManager.GetPeopleFromShow(showID,
ICollection<PeopleRole> resources = await _libraryManager.GetPeopleFromShow(showID,
ApiHelper.ParseWhere<PeopleRole>(where),
new Sort<PeopleRole>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -198,12 +198,12 @@ namespace Kyoo.Api
try
{
ICollection<PeopleRole> ressources = await _libraryManager.GetPeopleFromShow(slug,
ICollection<PeopleRole> resources = await _libraryManager.GetPeopleFromShow(slug,
ApiHelper.ParseWhere<PeopleRole>(where),
new Sort<PeopleRole>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -230,12 +230,12 @@ namespace Kyoo.Api
try
{
ICollection<Genre> ressources = await _libraryManager.GetGenres(
ICollection<Genre> resources = await _libraryManager.GetGenres(
ApiHelper.ParseWhere<Genre>(where, x => x.Shows.Any(y => y.ID == showID)),
new Sort<Genre>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -262,12 +262,12 @@ namespace Kyoo.Api
try
{
ICollection<Genre> ressources = await _libraryManager.GetGenres(
ICollection<Genre> resources = await _libraryManager.GetGenres(
ApiHelper.ParseWhere<Genre>(where, x => x.Shows.Any(y => y.Slug == slug)),
new Sort<Genre>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -322,12 +322,12 @@ namespace Kyoo.Api
try
{
ICollection<Library> ressources = await _libraryManager.GetLibraries(
ICollection<Library> resources = await _libraryManager.GetLibraries(
ApiHelper.ParseWhere<Library>(where, x => x.Shows.Any(y => y.ID == showID)),
new Sort<Library>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -354,12 +354,12 @@ namespace Kyoo.Api
try
{
ICollection<Library> ressources = await _libraryManager.GetLibraries(
ICollection<Library> resources = await _libraryManager.GetLibraries(
ApiHelper.ParseWhere<Library>(where, x => x.Shows.Any(y => y.Slug == slug)),
new Sort<Library>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -386,12 +386,12 @@ namespace Kyoo.Api
try
{
ICollection<Collection> ressources = await _libraryManager.GetCollections(
ICollection<Collection> resources = await _libraryManager.GetCollections(
ApiHelper.ParseWhere<Collection>(where, x => x.Shows.Any(y => y.ID == showID)),
new Sort<Collection>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -418,12 +418,12 @@ namespace Kyoo.Api
try
{
ICollection<Collection> ressources = await _libraryManager.GetCollections(
ICollection<Collection> resources = await _libraryManager.GetCollections(
ApiHelper.ParseWhere<Collection>(where, x => x.Shows.Any(y => y.Slug == slug)),
new Sort<Collection>(sortBy),
new Pagination(limit, afterID));
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{

View File

@ -40,14 +40,14 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShows(
ICollection<Show> resources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.StudioID == id),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
if (!ressources.Any() && await _libraryManager.GetStudio(id) == null)
if (!resources.Any() && await _libraryManager.GetStudio(id) == null)
return NotFound();
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{
@ -74,14 +74,14 @@ namespace Kyoo.Api
try
{
ICollection<Show> ressources = await _libraryManager.GetShows(
ICollection<Show> resources = await _libraryManager.GetShows(
ApiHelper.ParseWhere<Show>(where, x => x.Studio.Slug == slug),
new Sort<Show>(sortBy),
new Pagination(limit, afterID));
if (!ressources.Any() && await _libraryManager.GetStudio(slug) == null)
if (!resources.Any() && await _libraryManager.GetStudio(slug) == null)
return NotFound();
return Page(ressources, limit);
return Page(resources, limit);
}
catch (ItemNotFound)
{