From 98bd8a983baae0f1752d7bb9e2b10cb185825ff0 Mon Sep 17 00:00:00 2001 From: Glax Date: Sun, 26 May 2024 18:34:45 +0200 Subject: [PATCH 1/2] Possible Fix #182 --- Tranga/MangaConnectors/MangaConnector.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Tranga/MangaConnectors/MangaConnector.cs b/Tranga/MangaConnectors/MangaConnector.cs index fdbec1c..7038715 100644 --- a/Tranga/MangaConnectors/MangaConnector.cs +++ b/Tranga/MangaConnectors/MangaConnector.cs @@ -287,8 +287,9 @@ public abstract class MangaConnector : GlobalBase protected string SaveCoverImageToCache(string url, RequestType requestType) { - string filetype = url.Split('/')[^1].Split('?')[0].Split('.')[^1]; - string filename = $"{DateTime.Now.Ticks.ToString()}.{filetype}"; + Regex urlRex = new (@"https?:\/\/((?:[a-zA-Z0-9]+\.)+[a-zA-Z]+)\/(?:.+\/)*(.+\.[a-zA-Z]+)"); + Match match = urlRex.Match(url); + string filename = $"{match.Groups[1].Value}-{match.Groups[2].Value}"; string saveImagePath = Path.Join(settings.coverImageCache, filename); if (File.Exists(saveImagePath)) From e3211b95e2c5906b31be6b88d096b9e821d64880 Mon Sep 17 00:00:00 2001 From: Glax Date: Sun, 26 May 2024 18:46:40 +0200 Subject: [PATCH 2/2] #182 Remove covers that have no asssociated Manga --- Tranga/Jobs/JobBoss.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index c8cd28b..c5324d0 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -180,12 +180,9 @@ public class JobBoss : GlobalBase AddMangaToCache(dncJob.manga); } - HashSet coverFileNames = GetAllCachedManga().Select(manga => manga.coverFileNameInCache!).ToHashSet(); - foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) //Cleanup Unused Covers - { - if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga))) + string[] coverFiles = Directory.GetFiles(settings.coverImageCache); + foreach(string fileName in coverFiles.Where(fileName => !GetAllCachedManga().Any(manga => manga.coverFileNameInCache == fileName))) File.Delete(fileName); - } } internal void UpdateJobFile(Job job, string? oldFile = null)