From 66f3b0739df7dfff77ae86bb2262f8884f388575 Mon Sep 17 00:00:00 2001 From: Bobby Wibowo Date: Wed, 7 Feb 2018 13:22:31 +0700 Subject: [PATCH] Updates Experimental changes to allow generating thumbnails only for EITHER images or videos. --- config.sample.js | 3 ++- controllers/utilsController.js | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config.sample.js b/config.sample.js index 8988aee..5597de4 100644 --- a/config.sample.js +++ b/config.sample.js @@ -62,7 +62,8 @@ module.exports = { to install a separate binary called graphicsmagick (http://www.graphicsmagick.org) for images and ffmpeg (https://ffmpeg.org/) for video files */ - generateThumbnails: false, + generateImageThumbnails: true, + generateVideoThumbnails: false, /* Allows users to download a .zip file of all files in an album. diff --git a/controllers/utilsController.js b/controllers/utilsController.js index 5cd2170..101932f 100644 --- a/controllers/utilsController.js +++ b/controllers/utilsController.js @@ -31,13 +31,18 @@ utilsController.authorize = async (req, res) => { } utilsController.generateThumbs = function (file, basedomain) { - if (config.uploads.generateThumbnails !== true) return const ext = path.extname(file.name).toLowerCase() + const isVideoExt = utilsController.videoExtensions.includes(ext) + const isImageExt = utilsController.imageExtensions.includes(ext) + + if (!isVideoExt && !isImageExt) return + if (isVideoExt && config.uploads.generateVideoThumbnails !== true) return + if (isImageExt && config.uploads.generateImageThumbnails !== true) return let thumbname = path.join(__dirname, '..', config.uploads.folder, 'thumbs', file.name.slice(0, -ext.length) + '.png') fs.access(thumbname, err => { if (err && err.code === 'ENOENT') { - if (utilsController.videoExtensions.includes(ext)) { + if (isVideoExt) { ffmpeg(path.join(__dirname, '..', config.uploads.folder, file.name)) .thumbnail({ timestamps: [0], @@ -46,7 +51,7 @@ utilsController.generateThumbs = function (file, basedomain) { size: '200x?' }) .on('error', error => console.log('Error - ', error.message)) - } else { + } else if (isImageExt) { let size = { width: 200, height: 200