From c639b8ca042f8ee2adf6e389b85b16e0ec638220 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Wed, 24 Mar 2021 07:41:52 -0500 Subject: [PATCH] Implemented the LastWrite check for Summaries and Series Cover Images. Removed a TODO after validation. --- API/Services/ArchiveService.cs | 4 ++-- API/Services/MetadataService.cs | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/API/Services/ArchiveService.cs b/API/Services/ArchiveService.cs index 3cda2b4a1..03635188a 100644 --- a/API/Services/ArchiveService.cs +++ b/API/Services/ArchiveService.cs @@ -203,7 +203,7 @@ namespace API.Services { formatExtension = "." + formatExtension; } - // TODO: Validate if jpeg is same as jpg + try { using var thumbnail = Image.ThumbnailBuffer(entry, ThumbnailWidth); @@ -227,7 +227,7 @@ namespace API.Services { using var stream = entry.Open(); using var thumbnail = Image.ThumbnailStream(stream, ThumbnailWidth); - return thumbnail.WriteToBuffer(formatExtension); // TODO: Validate this code works with .png files + return thumbnail.WriteToBuffer(formatExtension); } catch (Exception ex) { diff --git a/API/Services/MetadataService.cs b/API/Services/MetadataService.cs index 4c1dbc118..9c8ee95bb 100644 --- a/API/Services/MetadataService.cs +++ b/API/Services/MetadataService.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Linq; using System.Threading.Tasks; using API.Entities; +using API.Extensions; using API.Interfaces; using API.Interfaces.Services; using Microsoft.Extensions.Logging; @@ -51,7 +53,10 @@ namespace API.Services // Skip calculating Cover Image (I/O) if the chapter already has it set if (firstChapter == null || ShouldFindCoverImage(firstChapter.CoverImage)) { - if (firstFile != null) volume.CoverImage = _archiveService.GetCoverImage(firstFile.FilePath, true); + if (firstFile != null && !new FileInfo(firstFile.FilePath).DoesLastWriteMatch(firstFile.LastModified)) + { + volume.CoverImage = _archiveService.GetCoverImage(firstFile.FilePath, true); + } } else { @@ -80,9 +85,11 @@ namespace API.Services var firstVolume = series.Volumes.FirstOrDefault(v => v.Chapters.Any() && v.Number == 1); var firstChapter = firstVolume?.Chapters.FirstOrDefault(c => c.Files.Any()); - if (firstChapter != null) + + var firstFile = firstChapter?.Files.FirstOrDefault(); + if (firstFile != null && !new FileInfo(firstFile.FilePath).DoesLastWriteMatch(firstFile.LastModified)) { - series.Summary = _archiveService.GetSummaryInfo(firstChapter.Files.FirstOrDefault()?.FilePath); + series.Summary = _archiveService.GetSummaryInfo(firstFile.FilePath); } }