mirror of https://gitgud.io/fatchan/jschan.git
parent
b868bb52ce
commit
e90847b0a4
13 changed files with 133 additions and 24 deletions
@ -1,5 +1,14 @@ |
||||
'use strict'; |
||||
|
||||
const allowedMimeTypes = new Set(['image/jpeg', 'image/pjpeg', 'image/png', 'image/gif']); |
||||
const allowedMimeTypes = new Set([ |
||||
'image/jpeg', |
||||
'image/pjpeg', |
||||
'image/png', |
||||
'image/gif', |
||||
'image/webp', |
||||
'image/bmp', |
||||
'video/mp4', |
||||
'video/webm', |
||||
]); |
||||
|
||||
module.exports = (mimetype) => allowedMimeTypes.has(mimetype); |
||||
|
@ -0,0 +1,11 @@ |
||||
'use strict'; |
||||
const sizes = ['B', 'KB', 'MB']; |
||||
const k = 1024; |
||||
|
||||
module.exports = (bytes) => { |
||||
if (bytes === 0) { |
||||
return '0B'; |
||||
} |
||||
const i = Math.floor(Math.log(bytes) / Math.log(k)); |
||||
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))}${sizes[i]}`; |
||||
}; |
@ -0,0 +1,16 @@ |
||||
const ffmpeg = require('fluent-ffmpeg') |
||||
, configs = require(__dirname+'/../../configs/main.json') |
||||
, uploadDirectory = require(__dirname+'/../uploadDirectory.js'); |
||||
|
||||
module.exports = (filename) => { |
||||
|
||||
return new Promise((resolve, reject) => { |
||||
ffmpeg.ffprobe(uploadDirectory + filename, (err, metadata) => { |
||||
if (err) { |
||||
return reject(err) |
||||
} |
||||
return resolve(metadata); |
||||
}); |
||||
}); |
||||
|
||||
}; |
@ -0,0 +1,21 @@ |
||||
const ffmpeg = require('fluent-ffmpeg') |
||||
, configs = require(__dirname+'/../../configs/main.json') |
||||
, uploadDirectory = require(__dirname+'/../uploadDirectory.js'); |
||||
|
||||
module.exports = (filename) => { |
||||
|
||||
return new Promise((resolve, reject) => { |
||||
ffmpeg(uploadDirectory + filename) |
||||
.on('end', () => { |
||||
return resolve(); |
||||
}) |
||||
.screenshots({ |
||||
timestamps: [0], |
||||
count: 1, |
||||
filename: `thumb-${filename.split('.')[0]}.png`, |
||||
folder: uploadDirectory, |
||||
size: '128x128' |
||||
}); |
||||
}); |
||||
|
||||
}; |
Loading…
Reference in new issue