aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/serve.js36
-rw-r--r--package.json4
2 files changed, 34 insertions, 6 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)
- }
+ })
})
}
diff --git a/package.json b/package.json
index 816c115..e39ff34 100644
--- a/package.json
+++ b/package.json
@@ -7,13 +7,15 @@
"busboy": "^0.2.14",
"emoji-named-characters": "^1.0.2",
"emoji-server": "^1.0.0",
+ "hashlru": "^2.1.0",
"human-time": "^0.0.1",
"hyperscript": "^2.0.2",
- "hashlru": "^2.1.0",
+ "jpeg-autorotate": "^3.0.0",
"looper": "^4.0.0",
"mime-types": "^2.1.12",
"multicb": "^1.2.1",
"pull-cat": "^1.1.11",
+ "pull-concat": "^1.1.1",
"pull-git-packidx-parser": "^1.0.0",
"pull-hash": "^1.0.0",
"pull-hyperscript": "^0.2.2",