Foundational Cover Image Rework (#584)
* Updating wording on card item when total pages is 0, to be just "Cannot Read" since it could be a non-archive file * Refactored cover images to be stored on disk. This first commit has the extraction to disk and the metadata service to handle updating when applicable. * Refactored code to have the actual save to cover image directory done by ImageService. * Implemented the ability to override cover images. * Some cleanup on Image service * Implemented the ability to cleanup old covers nightly * Added a migration to migrate existing covers to new cover image format (files). * Refactored all CoverImages to just be the filename, leaving the Join with Cover directory to higher level code. * Ensure when getting user progress, we pick the first. * Added cleanup cover images for deleted tags. Don't pull any cover images that are blank. * After series update, clear out cover image. No change on UI, but just keeps things clear before metadata refresh hits * Refactored image formats for covers to ImageService. * Fixed an issue where after refactoring how images were stored, the cleanup service was deleting them after each scan. * Changed how ShouldUpdateCoverImage works to check if file exists or not even if cover image is locked. * Fixed unit tests * Added caching back to cover images. * Caching on series as well * Code Cleanup items * Ensure when checking if a file exists in MetadataService, that we join for cover image directory. After we scan library, do one last filter to delete any series that have 0 pages total. * Catch exceptions so we don't run cover migration if this is first time run. * After a scan, only clear out the cache directory and not do a deep clean. * Implemented the ability to backup custom locked covers only. * Fixed unit tests * Trying to figure out why GA crashes when running MetadataServiceTests.cs * Some debugging on GA tests not running * Commented out tests that were causing issues in GA. * Fixed an issue where series cover images wouldn't migrate * Fixed the updating of links to actually do all series and not just locked
This commit is contained in:
parent
fd6925b126
commit
82b5b599e0
50 changed files with 1928 additions and 234 deletions
|
|
@ -147,12 +147,13 @@ namespace API.Services
|
|||
///
|
||||
/// This skips over any __MACOSX folder/file iteration.
|
||||
/// </summary>
|
||||
/// <remarks>This always creates a thumbnail</remarks>
|
||||
/// <param name="archivePath"></param>
|
||||
/// <param name="createThumbnail">Create a smaller variant of file extracted from archive. Archive images are usually 1MB each.</param>
|
||||
/// <param name="fileName">File name to use based on context of entity.</param>
|
||||
/// <returns></returns>
|
||||
public byte[] GetCoverImage(string archivePath, bool createThumbnail = false)
|
||||
public string GetCoverImage(string archivePath, string fileName)
|
||||
{
|
||||
if (archivePath == null || !IsValidArchive(archivePath)) return Array.Empty<byte>();
|
||||
if (archivePath == null || !IsValidArchive(archivePath)) return String.Empty;
|
||||
try
|
||||
{
|
||||
var libraryHandler = CanOpen(archivePath);
|
||||
|
|
@ -168,7 +169,7 @@ namespace API.Services
|
|||
var entry = archive.Entries.Single(e => e.FullName == entryName);
|
||||
using var stream = entry.Open();
|
||||
|
||||
return createThumbnail ? CreateThumbnail(entry.FullName, stream) : ConvertEntryToByteArray(entry);
|
||||
return CreateThumbnail(entry.FullName, stream, fileName);
|
||||
}
|
||||
case ArchiveLibrary.SharpCompress:
|
||||
{
|
||||
|
|
@ -183,14 +184,14 @@ namespace API.Services
|
|||
entry.WriteTo(ms);
|
||||
ms.Position = 0;
|
||||
|
||||
return createThumbnail ? CreateThumbnail(entry.Key, ms, Path.GetExtension(entry.Key)) : ms.ToArray();
|
||||
return CreateThumbnail(entry.Key, ms, fileName); // Path.GetExtension(entry.Key)
|
||||
}
|
||||
case ArchiveLibrary.NotSupported:
|
||||
_logger.LogWarning("[GetCoverImage] This archive cannot be read: {ArchivePath}. Defaulting to no cover image", archivePath);
|
||||
return Array.Empty<byte>();
|
||||
return String.Empty;
|
||||
default:
|
||||
_logger.LogWarning("[GetCoverImage] There was an exception when reading archive stream: {ArchivePath}. Defaulting to no cover image", archivePath);
|
||||
return Array.Empty<byte>();
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -198,15 +199,7 @@ namespace API.Services
|
|||
_logger.LogWarning(ex, "[GetCoverImage] There was an exception when reading archive stream: {ArchivePath}. Defaulting to no cover image", archivePath);
|
||||
}
|
||||
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
private static byte[] ConvertEntryToByteArray(ZipArchiveEntry entry)
|
||||
{
|
||||
using var stream = entry.Open();
|
||||
using var ms = StreamManager.GetStream();
|
||||
stream.CopyTo(ms);
|
||||
return ms.ToArray();
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -223,6 +216,7 @@ namespace API.Services
|
|||
archive.Entries.Any(e => e.FullName.Contains(Path.AltDirectorySeparatorChar) && !Parser.Parser.HasBlacklistedFolderInPath(e.FullName));
|
||||
}
|
||||
|
||||
// TODO: Refactor CreateZipForDownload to return the temp file so we can stream it from temp
|
||||
public async Task<Tuple<byte[], string>> CreateZipForDownload(IEnumerable<string> files, string tempFolder)
|
||||
{
|
||||
var dateString = DateTime.Now.ToShortDateString().Replace("/", "_");
|
||||
|
|
@ -254,23 +248,18 @@ namespace API.Services
|
|||
return Tuple.Create(fileBytes, zipPath);
|
||||
}
|
||||
|
||||
private byte[] CreateThumbnail(string entryName, Stream stream, string formatExtension = ".jpg")
|
||||
private string CreateThumbnail(string entryName, Stream stream, string fileName)
|
||||
{
|
||||
if (!formatExtension.StartsWith("."))
|
||||
{
|
||||
formatExtension = $".{formatExtension}";
|
||||
}
|
||||
try
|
||||
{
|
||||
using var thumbnail = Image.ThumbnailStream(stream, MetadataService.ThumbnailWidth);
|
||||
return thumbnail.WriteToBuffer(formatExtension);
|
||||
return ImageService.WriteCoverThumbnail(stream, fileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "[GetCoverImage] There was an error and prevented thumbnail generation on {EntryName}. Defaulting to no cover image", entryName);
|
||||
}
|
||||
|
||||
return Array.Empty<byte>();
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -332,7 +321,7 @@ namespace API.Services
|
|||
{
|
||||
case ArchiveLibrary.Default:
|
||||
{
|
||||
_logger.LogDebug("Using default compression handling");
|
||||
_logger.LogTrace("Using default compression handling");
|
||||
using var archive = ZipFile.OpenRead(archivePath);
|
||||
var entry = archive.Entries.SingleOrDefault(x => !Parser.Parser.HasBlacklistedFolderInPath(x.FullName)
|
||||
&& Path.GetFileNameWithoutExtension(x.Name)?.ToLower() == ComicInfoFilename
|
||||
|
|
@ -348,7 +337,7 @@ namespace API.Services
|
|||
}
|
||||
case ArchiveLibrary.SharpCompress:
|
||||
{
|
||||
_logger.LogDebug("Using SharpCompress compression handling");
|
||||
_logger.LogTrace("Using SharpCompress compression handling");
|
||||
using var archive = ArchiveFactory.Open(archivePath);
|
||||
info = FindComicInfoXml(archive.Entries.Where(entry => !entry.IsDirectory
|
||||
&& !Parser.Parser.HasBlacklistedFolderInPath(Path.GetDirectoryName(entry.Key) ?? string.Empty)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue