fix #30, thumbnail

This commit is contained in:
lesion
2019-03-20 00:50:43 +01:00
parent c7a0b22076
commit 299d9656d7
6 changed files with 24 additions and 7 deletions

View File

@@ -25,8 +25,14 @@ DiskStorage.prototype._handleFile = function _handleFile (req, file, cb) {
const filename = crypto.randomBytes(16).toString('hex') + '.jpg'
const finalPath = path.join(destination, filename)
const thumbPath = path.join(destination, 'thumb', filename)
const outStream = fs.createWriteStream(finalPath)
const thumbStream = fs.createWriteStream(thumbPath)
const resizer = sharp().resize(800).jpeg({ quality: 80 })
const thumbnailer = sharp().resize(400).jpeg({ quality: 60 })
file.stream.pipe(thumbnailer).pipe(thumbStream)
thumbStream.on('error', e => console.log('thumbStream error ', e))
file.stream.pipe(resizer).pipe(outStream)
outStream.on('error', cb)