mirror of https://gitgud.io/fatchan/jschan.git
parent
90a8093bd2
commit
8002569954
7 changed files with 121 additions and 51 deletions
@ -0,0 +1,17 @@ |
|||||||
|
const gm = require('@tohru/gm') |
||||||
|
, configs = require(__dirname+'/../configs/main.json') |
||||||
|
, uploadDirectory = require(__dirname+'/uploadDirectory.js'); |
||||||
|
|
||||||
|
module.exports = (filename) => { |
||||||
|
|
||||||
|
return new Promise((resolve, reject) => { |
||||||
|
gm(uploadDirectory + filename) |
||||||
|
.identify(function (err, data) { |
||||||
|
if (err) { |
||||||
|
return reject(err); |
||||||
|
} |
||||||
|
return resolve(data) |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
}; |
@ -0,0 +1,19 @@ |
|||||||
|
const gm = require('@tohru/gm') |
||||||
|
, configs = require(__dirname+'/../configs/main.json') |
||||||
|
, uploadDirectory = require(__dirname+'/uploadDirectory.js'); |
||||||
|
|
||||||
|
module.exports = (filename) => { |
||||||
|
|
||||||
|
return new Promise((resolve, reject) => { |
||||||
|
gm(uploadDirectory + filename) |
||||||
|
.resize(128, 128) |
||||||
|
.noProfile() |
||||||
|
.write(uploadDirectory + 'thumb-' + filename, function (err) { |
||||||
|
if (err) { |
||||||
|
return reject(err); |
||||||
|
} |
||||||
|
}); |
||||||
|
return resolve(); |
||||||
|
}); |
||||||
|
|
||||||
|
}; |
@ -0,0 +1,18 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
const configs = require(__dirname+'/../configs/main.json') |
||||||
|
, uploadDirectory = require(__dirname+'/uploadDirectory.js'); |
||||||
|
|
||||||
|
module.exports = (req, res, filename) => { |
||||||
|
|
||||||
|
return new Promise((resolve, reject) => { |
||||||
|
const file = req.files.file; |
||||||
|
file.mv(uploadDirectory + filename, function (err) { |
||||||
|
if (err) { |
||||||
|
return reject(err); |
||||||
|
} |
||||||
|
return resolve() |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
}; |
@ -1,39 +0,0 @@ |
|||||||
'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); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}); |
|
||||||
}, |
|
||||||
|
|
||||||
}; |
|
@ -0,0 +1,6 @@ |
|||||||
|
'use strict'; |
||||||
|
|
||||||
|
const path = require('path'); |
||||||
|
const directory = path.join(__dirname+'/../static/img/') |
||||||
|
|
||||||
|
module.exports = directory; |
Loading…
Reference in new issue