Experimental changes to allow generating thumbnails only for EITHER images or videos.
This commit is contained in:
Bobby Wibowo 2018-02-07 13:22:31 +07:00
parent 421d53d396
commit 66f3b0739d
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
2 changed files with 10 additions and 4 deletions

View File

@ -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.

View File

@ -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