mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-19 01:31:34 +00:00
Merge pull request #11 from PascalTemel/master
support thumbnails for .webm and .mp4 files
This commit is contained in:
commit
f6869ff7c5
@ -48,6 +48,7 @@ module.exports = {
|
|||||||
|
|
||||||
// NOTE: Thumbnails are only for the admin panel and they require you
|
// NOTE: Thumbnails are only for the admin panel and they require you
|
||||||
// to install a separate binary called graphicsmagick (http://www.graphicsmagick.org)
|
// to install a separate binary called graphicsmagick (http://www.graphicsmagick.org)
|
||||||
|
// for images and FFmpeg (https://ffmpeg.org/) for video files
|
||||||
generateThumbnails: false
|
generateThumbnails: false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ const db = require('knex')(config.database)
|
|||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const gm = require('gm')
|
const gm = require('gm')
|
||||||
|
const ffmpeg = require('fluent-ffmpeg')
|
||||||
|
|
||||||
let uploadsController = {}
|
let uploadsController = {}
|
||||||
|
|
||||||
@ -253,30 +254,44 @@ uploadsController.list = function(req, res){
|
|||||||
|
|
||||||
if(config.uploads.generateThumbnails === true){
|
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){
|
for(let ext of extensions){
|
||||||
if(path.extname(file.name) === ext){
|
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) {
|
fs.access(thumbname, function(err) {
|
||||||
if (err && err.code === 'ENOENT') {
|
if (err && err.code === 'ENOENT') {
|
||||||
// File doesnt exist
|
// File doesnt exist
|
||||||
|
|
||||||
let size = {
|
if (ext === '.webm' || ext === '.mp4') {
|
||||||
width: 200,
|
ffmpeg('./' + config.uploads.folder + '/' + file.name)
|
||||||
height: 200
|
.thumbnail({
|
||||||
|
timestamps: [0],
|
||||||
|
filename: '%b.png',
|
||||||
|
folder: './' + config.uploads.folder + '/thumbs',
|
||||||
|
size: '200x?'
|
||||||
|
})
|
||||||
|
.on('error', function(error) {
|
||||||
|
console.log('Error - ', error.message)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
let size = {
|
||||||
|
width: 200,
|
||||||
|
height: 200
|
||||||
|
}
|
||||||
|
|
||||||
gm('./' + config.uploads.folder + '/' + file.name)
|
gm('./' + config.uploads.folder + '/' + file.name)
|
||||||
.resize(size.width, size.height + '>')
|
.resize(size.width, size.height + '>')
|
||||||
.gravity('Center')
|
.gravity('Center')
|
||||||
.extent(size.width, size.height)
|
.extent(size.width, size.height)
|
||||||
.background('transparent')
|
.background('transparent')
|
||||||
.write(thumbname, function (error) {
|
.write(thumbname, function (error) {
|
||||||
if (error) console.log('Error - ', error)
|
if (error) console.log('Error - ', error)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -295,4 +310,4 @@ uploadsController.list = function(req, res){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = uploadsController
|
module.exports = uploadsController
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
"body-parser": "^1.16.0",
|
"body-parser": "^1.16.0",
|
||||||
"express": "^4.14.0",
|
"express": "^4.14.0",
|
||||||
"express-rate-limit": "^2.6.0",
|
"express-rate-limit": "^2.6.0",
|
||||||
|
"fluent-ffmpeg": "^2.1.0",
|
||||||
"gm": "^1.23.0",
|
"gm": "^1.23.0",
|
||||||
"knex": "^0.12.6",
|
"knex": "^0.12.6",
|
||||||
"multer": "^1.2.1",
|
"multer": "^1.2.1",
|
||||||
|
Loading…
Reference in New Issue
Block a user