diff --git a/AppScaffolding/AppScaffolding.csproj b/AppScaffolding/AppScaffolding.csproj index bcfbd257..9a3c4647 100644 --- a/AppScaffolding/AppScaffolding.csproj +++ b/AppScaffolding/AppScaffolding.csproj @@ -3,7 +3,7 @@ net6.0 - 6.6.4.1 + 6.6.5.1 diff --git a/DtoImporterService/BookImporter.cs b/DtoImporterService/BookImporter.cs index 2ee45574..c67a38fb 100644 --- a/DtoImporterService/BookImporter.cs +++ b/DtoImporterService/BookImporter.cs @@ -174,7 +174,9 @@ namespace DtoImporterService var item = importItem.DtoItem; // set/update book-specific info which may have changed - book.PictureId = item.PictureId; + if (item.PictureId is not null) + book.PictureId = item.PictureId; + book.UpdateProductRating(item.Product_OverallStars, item.Product_PerformanceStars, item.Product_StoryStars); // important to update user-specific info. this will have changed if user has rated/reviewed the book since last library import diff --git a/LibationFileManager/PictureStorage.cs b/LibationFileManager/PictureStorage.cs index 1f1b0747..70cb9d59 100644 --- a/LibationFileManager/PictureStorage.cs +++ b/LibationFileManager/PictureStorage.cs @@ -73,16 +73,10 @@ namespace LibationFileManager if (!cache.ContainsKey(def) || cache[def] == null) { var path = getPath(def); - byte[] bytes; - - if (File.Exists(path)) - bytes = File.ReadAllBytes(path); - else - { - bytes = downloadBytes(def); - saveFile(def, bytes); - } - + var bytes + = File.Exists(path) + ? File.ReadAllBytes(path) + : downloadBytes(def); cache[def] = bytes; } return cache[def]; @@ -104,7 +98,6 @@ namespace LibationFileManager continue; var bytes = downloadBytes(def); - saveFile(def, bytes); lock (cacheLocker) cache[def] = bytes; @@ -115,14 +108,24 @@ namespace LibationFileManager private static HttpClient imageDownloadClient { get; } = new HttpClient(); private static byte[] downloadBytes(PictureDefinition def) { - var sz = (int)def.Size; - return imageDownloadClient.GetByteArrayAsync("ht" + $"tps://images-na.ssl-images-amazon.com/images/I/{def.PictureId}._SL{sz}_.jpg").Result; - } + if (def.PictureId is null) + return getDefaultImage(def.Size); - private static void saveFile(PictureDefinition def, byte[] bytes) - { - var path = getPath(def); - File.WriteAllBytes(path, bytes); + 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; + + // save image file. make sure to not save default image + var path = getPath(def); + File.WriteAllBytes(path, bytes); + + return bytes; + } + catch + { + return getDefaultImage(def.Size); + } } } } \ No newline at end of file