Skip to content

Commit

Permalink
hotfix: fix up the series episode endpoint
Browse files Browse the repository at this point in the history
fix up the series episode endpoint to match the old default behaviour
prior to ea90899 and 36ae037, while also including the new behaviour
to let the user include everything, exclude everything, or only include
the episodes that match the specified condidition.

the current behaviour previous to this fixwas breaking both the v2
web ui and shokofin, while the new behaviour after this commit will not
break them but still allow for more filtering.

[no ci] [skip ci]
  • Loading branch information
revam committed Mar 30, 2023
1 parent 727ff1a commit 767ee7e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
32 changes: 25 additions & 7 deletions Shoko.Server/API/v3/Controllers/TreeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,9 @@ public ActionResult<Series> GetMainSeriesInGroup([FromRoute] int groupID, [FromQ
[HttpGet("Series/{seriesID}/Episode")]
public ActionResult<ListResult<Episode>> GetEpisodes([FromRoute] int seriesID,
[FromQuery] [Range(0, 1000)] int pageSize = 20, [FromQuery] [Range(1, int.MaxValue)] int page = 1,
[FromQuery] bool? includeMissing = null, [FromQuery] bool includeHidden = false,
[FromQuery] IncludeOnlyFilter includeMissing = IncludeOnlyFilter.False, [FromQuery] IncludeOnlyFilter includeHidden = IncludeOnlyFilter.False,
[FromQuery, ModelBinder(typeof(CommaDelimitedModelBinder))] HashSet<DataSource> includeDataFrom = null,
[FromQuery] bool? includeWatched = null, [FromQuery] EpisodeType? type = null)
[FromQuery] IncludeOnlyFilter includeWatched = IncludeOnlyFilter.True, [FromQuery] EpisodeType? type = null)
{
var series = RepoFactory.AnimeSeries.GetByID(seriesID);
if (series == null)
Expand All @@ -557,20 +557,38 @@ [FromQuery] [Range(0, 1000)] int pageSize = 20, [FromQuery] [Range(1, int.MaxVal
return Forbid(SeriesController.SeriesForbiddenForUser);
}

return series.GetAnimeEpisodes(orderList: true, includeHidden: includeHidden)
return series.GetAnimeEpisodes(orderList: true, includeHidden: includeHidden != IncludeOnlyFilter.False)
.Where(a =>
{
// Filter by hidden state, if spesified
if (includeHidden == IncludeOnlyFilter.Only && !a.IsHidden)
return false;
// Filter by episode type, if specified
if (type.HasValue && type.Value != Episode.MapAniDBEpisodeType((AniDBEpisodeType)a.AniDB_Episode.EpisodeType))
return false;
// Filter by availability, if specified
if (includeMissing.HasValue && includeMissing.Value == a.GetVideoLocals().Count > 0)
return false;
if (includeMissing != IncludeOnlyFilter.True)
{
// If we should hide missing episodes and the episode has no files, then hide it.
// Or if we should only show missing episodes and the episode has files, the hide it.
var shouldHideMissing = includeMissing == IncludeOnlyFilter.False;
var noFiles = a.GetVideoLocals().Count == 0;
if (shouldHideMissing == noFiles)
return false;
}
// Filter by user watched status, if specified
if (includeWatched.HasValue && includeWatched.Value == (a.GetUserRecord(User.JMMUserID)?.WatchedDate != null))
return false;
if (includeWatched != IncludeOnlyFilter.True)
{
// If we should hide watched episodes and the episode is watched, then hide it.
// Or if we should only show watched episodes and the the episode is not watched, then hide it.
var shouldHideWatched = includeWatched == IncludeOnlyFilter.False;
var isWatched = a.GetUserRecord(User.JMMUserID)?.WatchedDate != null;
if (shouldHideWatched == isWatched)
return false;
}
return true;
})
Expand Down
25 changes: 25 additions & 0 deletions Shoko.Server/API/v3/Models/Common/IncludeOnlyFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;

namespace Shoko.Server.API.v3.Models.Common;

[JsonConverter(typeof(StringEnumConverter), typeof(CamelCaseNamingStrategy))]
public enum IncludeOnlyFilter
{
/// <summary>
/// Include nothing.
/// </summary>
False = 0,

/// <summary>
/// Include everything.
/// </summary>
True = 1,

/// <summary>
/// Include only the elements that fit the specified condition.
/// </summary>
Only = 2,
}

0 comments on commit 767ee7e

Please sign in to comment.