Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
Co-authored-by: Fesaa <77553571+Fesaa@users.noreply.github.com>
This commit is contained in:
Joe Milazzo 2025-02-20 19:29:05 -06:00 committed by GitHub
parent 158c119247
commit 83c63a7904
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 126 additions and 61 deletions

View file

@ -537,8 +537,16 @@ public class CoverDbService : ICoverDbService
// Additional check to see if downloaded image is similar and we have a higher resolution
if (chooseBetterImage)
{
var betterImage = Path.Join(_directoryService.CoverImageDirectory, series.CoverImage).GetBetterImage(Path.Join(_directoryService.CoverImageDirectory, filePath))!;
filePath = Path.GetFileName(betterImage);
try
{
var betterImage = Path.Join(_directoryService.CoverImageDirectory, series.CoverImage)
.GetBetterImage(Path.Join(_directoryService.CoverImageDirectory, filePath))!;
filePath = Path.GetFileName(betterImage);
}
catch (Exception ex)
{
_logger.LogError(ex, "There was an issue trying to choose a better cover image for Series: {SeriesName} ({SeriesId})", series.Name, series.Id);
}
}
series.CoverImage = filePath;

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using API.Data;
using API.DTOs.Theme;
@ -32,6 +33,7 @@ internal class GitHubContent
[JsonProperty("type")]
public string Type { get; set; }
[JsonPropertyName("download_url")]
[JsonProperty("download_url")]
public string DownloadUrl { get; set; }
@ -151,6 +153,7 @@ public class ThemeService : IThemeService
// Fetch contents of the theme directory
var themeContents = await GetDirectoryContent(themeDir.Path);
// Find css and preview files
var cssFile = themeContents.FirstOrDefault(c => c.Name.EndsWith(".css"));
var previewUrls = GetPreviewUrls(themeContents);
@ -187,7 +190,7 @@ public class ThemeService : IThemeService
return themeDtos;
}
private static IList<string> GetPreviewUrls(IEnumerable<GitHubContent> themeContents)
private static List<string> GetPreviewUrls(IEnumerable<GitHubContent> themeContents)
{
return themeContents.Where(c => c.Name.ToLower().EndsWith(".jpg") || c.Name.ToLower().EndsWith(".png") )
.Select(p => p.DownloadUrl)
@ -196,10 +199,12 @@ public class ThemeService : IThemeService
private static async Task<IList<GitHubContent>> GetDirectoryContent(string path)
{
return await $"{GithubBaseUrl}/repos/Kareadita/Themes/contents/{path}"
var json = await $"{GithubBaseUrl}/repos/Kareadita/Themes/contents/{path}"
.WithHeader("Accept", "application/vnd.github+json")
.WithHeader("User-Agent", "Kavita")
.GetJsonAsync<List<GitHubContent>>();
.GetStringAsync();
return string.IsNullOrEmpty(json) ? [] : JsonConvert.DeserializeObject<List<GitHubContent>>(json);
}
/// <summary>