Add UpdateCoverJob.cs

Covers get updated on every pull
If a Manga has no DownloadAvailableChaptersJob, Cover is removed
Add endpoint POST Settings/CleanupCovers that removed covers not associated to any Manga
This commit is contained in:
2025-05-18 17:05:01 +02:00
parent 9b251169a5
commit 49bd66ccab
6 changed files with 99 additions and 5 deletions

View File

@ -32,11 +32,9 @@ public static class Tranga
Log.Info(TRANGA);
}
internal static void RemoveStaleFiles(IServiceProvider serviceProvider)
internal static void RemoveStaleFiles(PgsqlContext context)
{
Log.Info($"Removing stale files...");
using IServiceScope scope = serviceProvider.CreateScope();
PgsqlContext context = scope.ServiceProvider.GetRequiredService<PgsqlContext>();
string[] usedFiles = context.Mangas.Select(m => m.CoverFileNameInCache).Where(s => s != null).ToArray()!;
string[] extraneousFiles = new DirectoryInfo(TrangaSettings.coverImageCache).GetFiles()
.Where(f => usedFiles.Contains(f.FullName) == false)