diff options
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/serve.js b/lib/serve.js index 9d5eb82..81ab0b7 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -20,6 +20,7 @@ var ident = require('pull-identify-filetype') var htime = require('human-time') var ph = require('pull-hyperscript') var emojis = require('emoji-named-characters') +var jpeg = require('jpeg-autorotate') module.exports = Serve @@ -954,10 +955,20 @@ Serve.prototype.blob = function (id) { else return self.respond(500, err.message || err) } if (!has) return self.respond(404, 'Not found') + blobs.size(id, done()) + var rotatedSize = null + pull( blobs.get(id), pull.map(Buffer), + pull.asyncMap(function (buf, cb) { + jpeg.rotate(buf, {}, function (err, buffer, orientation) { + if (err) return cb(null, buf) + rotatedSize = buffer.length + return cb(null, buffer) + }) + }), ident(done().bind(self, null)), self.respondSink() ) @@ -965,7 +976,7 @@ Serve.prototype.blob = function (id) { if (err) console.trace(err) type = type && mime.lookup(type) if (type) self.res.setHeader('Content-Type', type) - if (typeof size === 'number') self.res.setHeader('Content-Length', size) + if (typeof size === 'number') self.res.setHeader('Content-Length', rotatedSize || size) if (self.query.name) self.res.setHeader('Content-Disposition', 'inline; filename='+encodeDispositionFilename(self.query.name)) self.res.setHeader('Cache-Control', 'public, max-age=315360000') |