Frontend: Only show thumbs for which a hash exists

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-04-29 10:22:33 +02:00
parent 1f3d9ca758
commit 9c72a2168c
2 changed files with 31 additions and 6 deletions

View file

@ -102,7 +102,7 @@ class Photo extends RestModel {
refreshFileAttr() { refreshFileAttr() {
const file = this.mainFile(); const file = this.mainFile();
if (!file) { if (!file || !file.FileHash) {
return; return;
} }

View file

@ -29,7 +29,11 @@ class Thumb extends Model {
let result = []; let result = [];
photos.forEach((p) => { photos.forEach((p) => {
result.push(this.fromPhoto(p)); let thumb = this.fromPhoto(p);
if(thumb) {
result.push(thumb);
}
}); });
return result; return result;
@ -40,11 +44,15 @@ class Thumb extends Model {
return this.fromFile(photo, photo.Files.find(f => !!f.FilePrimary)); return this.fromFile(photo, photo.Files.find(f => !!f.FilePrimary));
} }
if(!photo || !photo.FileHash) {
return false;
}
const result = { const result = {
uuid: photo.PhotoUUID, uuid: photo.PhotoUUID,
title: photo.PhotoTitle, title: photo.PhotoTitle,
favorite: photo.PhotoFavorite, favorite: photo.PhotoFavorite,
download_url: "/api/v1/download/" + photo.FileHash, download_url: this.downloadUrl(photo),
original_w: photo.FileWidth, original_w: photo.FileWidth,
original_h: photo.FileHeight, original_h: photo.FileHeight,
}; };
@ -63,11 +71,15 @@ class Thumb extends Model {
} }
static fromFile(photo, file) { static fromFile(photo, file) {
if(!photo || !file || !file.FileHash) {
return false;
}
const result = { const result = {
uuid: photo.PhotoUUID, uuid: photo.PhotoUUID,
title: photo.PhotoTitle, title: photo.PhotoTitle,
favorite: photo.PhotoFavorite, favorite: photo.PhotoFavorite,
download_url: "/api/v1/download/" + file.FileHash, download_url: this.downloadUrl(file),
original_w: file.FileWidth, original_w: file.FileWidth,
original_h: file.FileHeight, original_h: file.FileHeight,
}; };
@ -92,8 +104,12 @@ class Thumb extends Model {
if (!p.Files) return; if (!p.Files) return;
p.Files.forEach((f) => { p.Files.forEach((f) => {
if (f.FileType === "jpg") { if (f && f.FileType === "jpg") {
result.push(this.fromFile(p, f)); 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; return "/api/v1/thumbnails/" + file.FileHash + "/" + type;
} }
static downloadUrl(file) {
if (!file || !file.FileHash) {
return "";
}
return "/api/v1/download/" + file.FileHash;
}
} }
export default Thumb; export default Thumb;