Skip to content

Commit

Permalink
fix: add back backdrops for filter presets in APIv2
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Oct 20, 2024
1 parent d79b2d5 commit 0da092d
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions Shoko.Server/API/v2/Models/common/Filter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
Expand Down Expand Up @@ -56,15 +56,11 @@ internal static Filter GenerateFromGroupFilter(HttpContext ctx, FilterPreset gf,
// Populate Random Art

List<SVR_AnimeSeries>? arts = null;
var seriesList = evaluatedResults.SelectMany(a => a).Select(RepoFactory.AnimeSeries.GetByID).ToList();
var groupsList = evaluatedResults.Select(r => RepoFactory.AnimeGroup.GetByID(r.Key)).ToList();
var seriesList = evaluatedResults.SelectMany(a => a).Select(RepoFactory.AnimeSeries.GetByID).WhereNotNull().ToList();
var groupsList = evaluatedResults.Select(r => RepoFactory.AnimeGroup.GetByID(r.Key)).WhereNotNull().ToList();
if (pic == 1)
{
arts = seriesList.Where(SeriesHasCompleteArt).WhereNotNull().ToList();
if (arts.Count == 0)
{
arts = seriesList.Where(SeriesHasMostlyCompleteArt).WhereNotNull().ToList();
}
arts = seriesList.Where(SeriesHasArt).ToList();

if (arts.Count == 0)
{
Expand All @@ -76,6 +72,16 @@ internal static Filter GenerateFromGroupFilter(HttpContext ctx, FilterPreset gf,
{
var rand = new Random();
var anime = arts[rand.Next(arts.Count)];
var backdrops = anime.GetImages(ImageEntityType.Backdrop);
if (backdrops.Count > 0)
{
var backdrop = backdrops[rand.Next(backdrops.Count)];
filter.art.fanart.Add(new Art
{
index = 0,
url = APIHelper.ConstructImageLinkFromTypeAndId(ctx, backdrop.ImageType, backdrop.Source, backdrop.ID),
});
}

filter.art.thumb.Add(new Art
{
Expand All @@ -101,13 +107,8 @@ internal static Filter GenerateFromGroupFilter(HttpContext ctx, FilterPreset gf,
return filter;
}

private static bool SeriesHasCompleteArt(SVR_AnimeSeries series)
{
return false;
}

private static bool SeriesHasMostlyCompleteArt(SVR_AnimeSeries series)
private static bool SeriesHasArt(SVR_AnimeSeries series)
{
return false;
return series.GetImages(ImageEntityType.Backdrop).Count is > 0;
}
}

0 comments on commit 0da092d

Please sign in to comment.