From b0d1f692a33733cfa41cdf7e3ef9e05f9a23bc25 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Tue, 10 May 2022 12:01:23 -0600 Subject: [PATCH] Use new PictureIDLarge and PictureSize.Native --- Source/DtoImporterService/BookImporter.cs | 5 ++--- Source/FileLiberator/Processable.cs | 6 +++--- Source/LibationFileManager/PictureStorage.cs | 13 +++++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Source/DtoImporterService/BookImporter.cs b/Source/DtoImporterService/BookImporter.cs index 4c3cd74d..bc69f382 100644 --- a/Source/DtoImporterService/BookImporter.cs +++ b/Source/DtoImporterService/BookImporter.cs @@ -165,9 +165,8 @@ namespace DtoImporterService if (item.PictureId is not null) book.PictureId = item.PictureId; - // set/update book-specific info which may have changed - if (item.PictureId_1215 is not null) - book.PictureId_1215 = item.PictureId_1215; + if (item.PictureLarge is not null) + book.PictureLarge = item.PictureLarge; book.UpdateProductRating(item.Product_OverallStars, item.Product_PerformanceStars, item.Product_StoryStars); diff --git a/Source/FileLiberator/Processable.cs b/Source/FileLiberator/Processable.cs index 66e36d1c..56ca47a5 100644 --- a/Source/FileLiberator/Processable.cs +++ b/Source/FileLiberator/Processable.cs @@ -63,9 +63,9 @@ namespace FileLiberator try { - (string picId, PictureSize size) = libraryBook.Book.PictureId_1215 is null ? - (libraryBook.Book.PictureId, PictureSize._500x500) : - (libraryBook.Book.PictureId_1215, PictureSize._1215x1215); + (string picId, PictureSize size) = libraryBook.Book.PictureLarge is null ? + (libraryBook.Book.PictureId, PictureSize.Native) : + (libraryBook.Book.PictureLarge, PictureSize.Native); var picBytes = PictureStorage.GetPictureSynchronously(new PictureDefinition(picId, size)); diff --git a/Source/LibationFileManager/PictureStorage.cs b/Source/LibationFileManager/PictureStorage.cs index 4b6556ab..ba5cea1a 100644 --- a/Source/LibationFileManager/PictureStorage.cs +++ b/Source/LibationFileManager/PictureStorage.cs @@ -8,13 +8,13 @@ using System.Threading.Tasks; namespace LibationFileManager { - public enum PictureSize { _80x80 = 80, _300x300 = 300, _500x500 = 500 , _1215x1215 = 1215 } + public enum PictureSize { Native, _80x80 = 80, _300x300 = 300, _500x500 = 500 } public class PictureCachedEventArgs : EventArgs { public PictureDefinition Definition { get; internal set; } public byte[] Picture { get; internal set; } } - public struct PictureDefinition + public struct PictureDefinition : IEquatable { public string PictureId { get; } public PictureSize Size { get; } @@ -24,6 +24,11 @@ namespace LibationFileManager PictureId = pictureId; Size = pictureSize; } + + public bool Equals(PictureDefinition other) + { + return PictureId == other.PictureId && Size == other.Size; + } } public static class PictureStorage { @@ -113,8 +118,8 @@ namespace LibationFileManager try { - var sz = (int)def.Size; - var bytes = imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result; + var sizeStr = def.Size == PictureSize.Native ? "" : $"._SL{(int)def.Size}_"; + var bytes = imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}{sizeStr}.jpg").Result; // save image file. make sure to not save default image var path = getPath(def);