aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPitu <[email protected]>2020-07-18 05:50:47 +0900
committerPitu <[email protected]>2020-07-18 05:50:47 +0900
commitd644b21d431c03263aa7191fe54a984aac96f979 (patch)
tree79b39247873234e33491680356031bd992be79aa
parentUpdate displaying thumbnails of unsupported file types (diff)
downloadhost.fuwn.me-d644b21d431c03263aa7191fe54a984aac96f979.tar.xz
host.fuwn.me-d644b21d431c03263aa7191fe54a984aac96f979.zip
Make thumbnails webp (bye bye safari)
-rw-r--r--src/api/utils/Util.js11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/api/utils/Util.js b/src/api/utils/Util.js
index 885228f..a4af81e 100644
--- a/src/api/utils/Util.js
+++ b/src/api/utils/Util.js
@@ -36,7 +36,7 @@ class Util {
static generateThumbnails(filename) {
const ext = path.extname(filename).toLowerCase();
- const output = `${filename.slice(0, -ext.length)}.png`;
+ const output = `${filename.slice(0, -ext.length)}.webp`;
if (imageExtensions.includes(ext)) return this.generateThumbnailForImage(filename, output);
if (videoExtensions.includes(ext)) return this.generateThumbnailForVideo(filename);
return null;
@@ -46,11 +46,11 @@ class Util {
const file = await jetpack.readAsync(path.join(__dirname, '..', '..', '..', process.env.UPLOAD_FOLDER, filename), 'buffer');
await sharp(file)
.resize(64, 64)
- .toFormat('png')
+ .toFormat('webp')
.toFile(path.join(__dirname, '..', '..', '..', process.env.UPLOAD_FOLDER, 'thumbs', 'square', output));
await sharp(file)
.resize(225, null)
- .toFormat('png')
+ .toFormat('webp')
.toFile(path.join(__dirname, '..', '..', '..', process.env.UPLOAD_FOLDER, 'thumbs', output));
}
@@ -76,8 +76,9 @@ class Util {
static getFileThumbnail(filename) {
if (!filename) return null;
const ext = path.extname(filename).toLowerCase();
- if (!imageExtensions.includes(ext) && !videoExtensions.includes(ext)) return null;
- return `${filename.slice(0, -ext.length)}.png`;
+ const extension = imageExtensions.includes(ext) ? 'webp' : videoExtensions.includes(ext) ? 'png' : null;
+ if (!extension) return null;
+ return `${filename.slice(0, -ext.length)}.${extension}`;
}
static constructFilePublicLink(file) {