mirror of
https://github.com/C9Glax/tranga.git
synced 2025-05-22 06:03:01 +02:00
Remove old covers from ImageCache
This commit is contained in:
parent
aa29c45094
commit
9b251169a5
@ -149,6 +149,7 @@ using (IServiceScope scope = app.Services.CreateScope())
|
||||
|
||||
TrangaSettings.Load();
|
||||
Tranga.StartLogger();
|
||||
Tranga.RemoveStaleFiles(app.Services);
|
||||
Tranga.JobStarterThread.Start(app.Services);
|
||||
//Tranga.NotificationSenderThread.Start(app.Services); //TODO RE-ENABLE
|
||||
|
||||
|
@ -32,6 +32,23 @@ public static class Tranga
|
||||
Log.Info(TRANGA);
|
||||
}
|
||||
|
||||
internal static void RemoveStaleFiles(IServiceProvider serviceProvider)
|
||||
{
|
||||
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)
|
||||
.Select(f => f.FullName)
|
||||
.ToArray();
|
||||
foreach (string path in extraneousFiles)
|
||||
{
|
||||
Log.Info($"Deleting {path}");
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
private static void NotificationSender(object? serviceProviderObj)
|
||||
{
|
||||
if (serviceProviderObj is null)
|
||||
|
Loading…
x
Reference in New Issue
Block a user