From 9c72a2168c92599abc43b327b3c913fa097bb378 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 29 Apr 2020 10:22:33 +0200 Subject: [PATCH] Frontend: Only show thumbs for which a hash exists Signed-off-by: Michael Mayer --- frontend/src/model/photo.js | 2 +- frontend/src/model/thumb.js | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/frontend/src/model/photo.js b/frontend/src/model/photo.js index 1ea52ff69..e0b891798 100644 --- a/frontend/src/model/photo.js +++ b/frontend/src/model/photo.js @@ -102,7 +102,7 @@ class Photo extends RestModel { refreshFileAttr() { const file = this.mainFile(); - if (!file) { + if (!file || !file.FileHash) { return; } diff --git a/frontend/src/model/thumb.js b/frontend/src/model/thumb.js index cc34cf87f..2cd7e93c3 100644 --- a/frontend/src/model/thumb.js +++ b/frontend/src/model/thumb.js @@ -29,7 +29,11 @@ class Thumb extends Model { let result = []; photos.forEach((p) => { - result.push(this.fromPhoto(p)); + let thumb = this.fromPhoto(p); + + if(thumb) { + result.push(thumb); + } }); return result; @@ -40,11 +44,15 @@ class Thumb extends Model { return this.fromFile(photo, photo.Files.find(f => !!f.FilePrimary)); } + if(!photo || !photo.FileHash) { + return false; + } + const result = { uuid: photo.PhotoUUID, title: photo.PhotoTitle, favorite: photo.PhotoFavorite, - download_url: "/api/v1/download/" + photo.FileHash, + download_url: this.downloadUrl(photo), original_w: photo.FileWidth, original_h: photo.FileHeight, }; @@ -63,11 +71,15 @@ class Thumb extends Model { } static fromFile(photo, file) { + if(!photo || !file || !file.FileHash) { + return false; + } + const result = { uuid: photo.PhotoUUID, title: photo.PhotoTitle, favorite: photo.PhotoFavorite, - download_url: "/api/v1/download/" + file.FileHash, + download_url: this.downloadUrl(file), original_w: file.FileWidth, original_h: file.FileHeight, }; @@ -92,8 +104,12 @@ class Thumb extends Model { if (!p.Files) return; p.Files.forEach((f) => { - if (f.FileType === "jpg") { - result.push(this.fromFile(p, f)); + if (f && f.FileType === "jpg") { + let thumb = this.fromFile(p, f); + + if(thumb) { + result.push(thumb); + } } } ); @@ -132,6 +148,15 @@ class Thumb extends Model { return "/api/v1/thumbnails/" + file.FileHash + "/" + type; } + + static downloadUrl(file) { + if (!file || !file.FileHash) { + return ""; + + } + + return "/api/v1/download/" + file.FileHash; + } } export default Thumb;