aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.sample.js1
-rw-r--r--controllers/uploadController.js46
-rw-r--r--package.json1
3 files changed, 33 insertions, 15 deletions
diff --git a/config.sample.js b/config.sample.js
index 7c881d9..04b87ea 100644
--- a/config.sample.js
+++ b/config.sample.js
@@ -45,6 +45,7 @@ module.exports = {
// NOTE: Thumbnails are only for the admin panel and they require you
// to install a separate binary called graphicsmagick (http://www.graphicsmagick.org)
+ // for images and FFmpeg (https://ffmpeg.org/) for video files
generateThumbnails: false
},
diff --git a/controllers/uploadController.js b/controllers/uploadController.js
index f9abf50..1e1efe5 100644
--- a/controllers/uploadController.js
+++ b/controllers/uploadController.js
@@ -6,6 +6,7 @@ const db = require('knex')(config.database)
const crypto = require('crypto')
const fs = require('fs')
const gm = require('gm')
+const ffmpeg = require('fluent-ffmpeg')
let uploadsController = {}
@@ -246,30 +247,45 @@ uploadsController.list = function(req, res){
if(config.uploads.generateThumbnails === true){
- let extensions = ['.jpg', '.jpeg', '.bmp', '.gif', '.png']
+ let extensions = ['.jpg', '.jpeg', '.bmp', '.gif', '.png', '.webm', '.mp4']
for(let ext of extensions){
if(path.extname(file.name) === ext){
- file.thumb = basedomain + '/thumbs/' + file.name.slice(0, -4) + '.png'
+ file.thumb = basedomain + '/thumbs/' + file.name.slice(0, -ext.length) + '.png'
- let thumbname = path.join(__dirname, '..', 'uploads', 'thumbs') + '/' + file.name.slice(0, -4) + '.png'
+ let thumbname = path.join(__dirname, '..', config.uploads.folder, 'thumbs') + '/' + file.name.slice(0, -ext.length) + '.png'
fs.access(thumbname, function(err) {
if (err && err.code === 'ENOENT') {
// File doesnt exist
- let size = {
- width: 200,
- height: 200
+ if (ext === '.webm' || ext === '.mp4') {
+ ffmpeg('./' + config.uploads.folder + '/' + file.name)
+ .thumbnail({
+ timestamps: [0],
+ filename: '%b.png',
+ folder: './' + config.uploads.folder + '/thumbs',
+ size: '200x?',
+ autopad: true
+ })
+ .on('error', function(error) {
+ console.log('Error - ', error.message)
+ })
+ }
+ else {
+ let size = {
+ width: 200,
+ height: 200
+ }
+
+ gm('./' + config.uploads.folder + '/' + file.name)
+ .resize(size.width, size.height + '>')
+ .gravity('Center')
+ .extent(size.width, size.height)
+ .background('transparent')
+ .write(thumbname, function (error) {
+ if (error) console.log('Error - ', error)
+ })
}
-
- gm('./' + config.uploads.folder + '/' + file.name)
- .resize(size.width, size.height + '>')
- .gravity('Center')
- .extent(size.width, size.height)
- .background('transparent')
- .write(thumbname, function (error) {
- if (error) console.log('Error - ', error)
- })
}
})
}
diff --git a/package.json b/package.json
index c891365..330af64 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
"body-parser": "^1.16.0",
"express": "^4.14.0",
"express-rate-limit": "^2.6.0",
+ "fluent-ffmpeg": "^2.1.0",
"gm": "^1.23.0",
"knex": "^0.12.6",
"multer": "^1.2.1",