From 48fb2df5755db23bcdef3185a6944561efae3055 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 10 Oct 2022 12:12:25 -0700 Subject: [PATCH] Use preview for unsupported images (fix #1408) Signed-off-by: Varun Patil --- src/components/Images.vue | 9 ++++----- src/mixins/PreviewUrl.js | 8 +------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/components/Images.vue b/src/components/Images.vue index 758b554cb..14d4fd15d 100644 --- a/src/components/Images.vue +++ b/src/components/Images.vue @@ -104,13 +104,12 @@ export default { return this.getBase64FromImage() } - if (this.source) { - return this.source - } - - if (this.mime === 'image/gif') { + // Use original file if directly supported by the browser + const nativeMimes = ['image/apng', 'image/avif', 'image/jpeg', 'image/png', 'image/webp', 'image/gif'] + if (this.src && nativeMimes.indexOf(this.mime) !== -1) { return this.src } + return this.previewPath }, }, diff --git a/src/mixins/PreviewUrl.js b/src/mixins/PreviewUrl.js index 7edcb4e91..afed1b718 100644 --- a/src/mixins/PreviewUrl.js +++ b/src/mixins/PreviewUrl.js @@ -34,7 +34,6 @@ export default { previewPath() { return this.getPreviewIfAny({ fileid: this.fileid, - source: this.source, filename: this.filename, hasPreview: this.hasPreview, davPath: this.davPath, @@ -60,17 +59,12 @@ export default { * * @param {object} data destructuring object * @param {string} data.fileid the file id - * @param {?string} data.source the download source * @param {boolean} data.hasPreview have the file an existing preview ? * @param {string} data.davPath the absolute dav path * @param {string} data.filename the file name * @return {string} the absolute url */ - getPreviewIfAny({ fileid, source, filename, hasPreview, davPath }) { - if (source) { - return source - } - + getPreviewIfAny({ fileid, filename, hasPreview, davPath }) { const searchParams = `fileId=${fileid}` + `&x=${Math.floor(screen.width * devicePixelRatio)}` + `&y=${Math.floor(screen.height * devicePixelRatio)}`