jschan - Anonymous imageboard software. Classic look, modern features and feel. Works without JavaScript and supports Tor, I2P, Lokinet, etc.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
'use strict';
|
|
|
|
const isValidFile = require(__dirname+'/filefilter.js')
|
|
|
|
, path = require('path')
|
|
|
|
, uploadDest = path.join(__dirname, '/../static/img/')
|
|
|
|
, uuidv4 = require('uuid/v4')
|
|
|
|
, gm = require('@tohru/gm');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
uploadDest,
|
|
|
|
|
|
|
|
uploadAndThumb: (req, res) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const file = req.files.file;
|
|
|
|
//check type
|
|
|
|
if (!isValidFile(file)) {
|
|
|
|
return reject(new Error('Unsupported file type'))
|
|
|
|
}
|
|
|
|
//save it
|
|
|
|
const filename = uuidv4() + path.extname(file.name);
|
|
|
|
file.mv(uploadDest + filename, function (err) {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
//thumbnail it
|
|
|
|
gm(uploadDest + filename)
|
|
|
|
.resize(128, 128)
|
|
|
|
.noProfile()
|
|
|
|
.write(uploadDest + 'thumb-' + filename, function (err) {
|
|
|
|
if (err) {
|
|
|
|
return reject(err);
|
|
|
|
}
|
|
|
|
return resolve(filename);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
};
|