mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-11 04:18:18 +02:00
Resize Covers on download
This commit is contained in:
@@ -200,18 +200,19 @@ public class DownloadChapterFromMangaconnectorWorker(MangaConnectorId<Chapter> c
|
||||
|
||||
Log.Info($"Copying cover to {publicationFolder}");
|
||||
await DbContext.Entry(mangaConnectorId).Navigation(nameof(MangaConnectorId<Manga>.Obj)).LoadAsync(CancellationToken);
|
||||
string? fileInCache = manga.CoverFileNameInCache ?? mangaConnector.SaveCoverImageToCache(mangaConnectorId);
|
||||
if (fileInCache is null)
|
||||
string? coverFileNameInCache = manga.CoverFileNameInCache ?? mangaConnector.SaveCoverImageToCache(mangaConnectorId);
|
||||
if (coverFileNameInCache is null)
|
||||
{
|
||||
Log.Error($"File {fileInCache} does not exist");
|
||||
Log.Error($"File {coverFileNameInCache} does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(fileInCache).Split('.')[^1]}" );
|
||||
File.Copy(fileInCache, newFilePath, true);
|
||||
string fullCoverPath = Path.Join(TrangaSettings.coverImageCacheOriginal, coverFileNameInCache);
|
||||
string newFilePath = Path.Join(publicationFolder, $"cover.{Path.GetFileName(coverFileNameInCache).Split('.')[^1]}" );
|
||||
File.Copy(fullCoverPath, newFilePath, true);
|
||||
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
File.SetUnixFileMode(newFilePath, GroupRead | GroupWrite | UserRead | UserWrite | OtherRead | OtherWrite);
|
||||
Log.Debug($"Copied cover from {fileInCache} to {newFilePath}");
|
||||
Log.Debug($"Copied cover from {fullCoverPath} to {newFilePath}");
|
||||
}
|
||||
|
||||
private bool DownloadImage(string imageUrl, string savePath)
|
||||
|
@@ -11,11 +11,22 @@ public class CleanupMangaCoversWorker(TimeSpan? interval = null, IEnumerable<Bas
|
||||
protected override Task<BaseWorker[]> DoWorkInternal()
|
||||
{
|
||||
Log.Info("Removing stale files...");
|
||||
if (!Directory.Exists(TrangaSettings.coverImageCache))
|
||||
return new Task<BaseWorker[]>(() => []);
|
||||
string[] usedFiles = DbContext.Mangas.Select(m => m.CoverFileNameInCache).Where(s => s != null).ToArray()!;
|
||||
string[] extraneousFiles = new DirectoryInfo(TrangaSettings.coverImageCache).GetFiles()
|
||||
.Where(f => usedFiles.Contains(f.FullName) == false)
|
||||
CleanupImageCache(usedFiles, TrangaSettings.coverImageCacheOriginal);
|
||||
CleanupImageCache(usedFiles, TrangaSettings.coverImageCacheLarge);
|
||||
CleanupImageCache(usedFiles, TrangaSettings.coverImageCacheMedium);
|
||||
CleanupImageCache(usedFiles, TrangaSettings.coverImageCacheSmall);
|
||||
return new Task<BaseWorker[]>(() => []);
|
||||
}
|
||||
|
||||
private void CleanupImageCache(string[] retainFilenames, string imageCachePath)
|
||||
{
|
||||
DirectoryInfo directory = new(imageCachePath);
|
||||
if (!directory.Exists)
|
||||
return;
|
||||
string[] extraneousFiles = directory
|
||||
.GetFiles()
|
||||
.Where(f => retainFilenames.Contains(f.Name) == false)
|
||||
.Select(f => f.FullName)
|
||||
.ToArray();
|
||||
foreach (string path in extraneousFiles)
|
||||
@@ -23,6 +34,5 @@ public class CleanupMangaCoversWorker(TimeSpan? interval = null, IEnumerable<Bas
|
||||
Log.Info($"Deleting {path}");
|
||||
File.Delete(path);
|
||||
}
|
||||
return new Task<BaseWorker[]>(() => []);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user