aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/serve.js')
-rw-r--r--lib/serve.js36
1 files changed, 31 insertions, 5 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 4f2ed42..9228335 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -20,6 +20,8 @@ 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')
+var concat = require('pull-concat')
module.exports = Serve
@@ -1029,22 +1031,46 @@ Serve.prototype.blob = function (id) {
if (/^invalid/.test(err.message)) return self.respond(400, err.message)
else return self.respond(500, err.message || err)
}
+
+ var done = multicb({pluck: 1, spread: true})
+ var heresTheData = done()
+ var heresTheType = done().bind(self, null)
+
pull(
blobs.get(id),
pull.map(Buffer),
- ident(gotType),
- self.respondSink()
+ ident(heresTheType),
+ concat.buffer(onFullBuffer)
)
- function gotType(type) {
+
+ function onFullBuffer (err, buffer) {
+ if (err) return heresTheData(err)
+
+ jpeg.rotate(buffer, {}, function (err, rotatedBuffer, orientation) {
+ if (!err) buffer = rotatedBuffer
+
+ heresTheData(null, buffer)
+ pull(
+ pull.once(buffer),
+ self.respondSink()
+ )
+ })
+ }
+
+ done(function (err, data, type) {
+ if (err) {
+ console.trace(err)
+ self.respond(500, err.message || err)
+ }
type = type && mime.lookup(type)
if (type) self.res.setHeader('Content-Type', type)
- if (typeof size === 'number') self.res.setHeader('Content-Length', size)
+ self.res.setHeader('Content-Length', data.length)
if (self.query.name) self.res.setHeader('Content-Disposition',
'inline; filename='+encodeDispositionFilename(self.query.name))
self.res.setHeader('Cache-Control', 'public, max-age=315360000')
self.res.setHeader('etag', id)
self.res.writeHead(200)
- }
+ })
})
}