aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Whitmore <sww@eight45.net>2017-06-10 15:04:24 -0700
committerStephen Whitmore <sww@eight45.net>2017-06-10 15:06:49 -0700
commitb6d136ab10136f9d881b239a338a4c0eea2e65f0 (patch)
treed6fa231c2033c5605bec662297e48e1b5949ffe5
parentb4070f9b60e49b2c378bd85b4d0834101eae2632 (diff)
downloadpatchfoo-b6d136ab10136f9d881b239a338a4c0eea2e65f0.tar.gz
patchfoo-b6d136ab10136f9d881b239a338a4c0eea2e65f0.zip
fixes
-rw-r--r--lib/serve.js40
-rw-r--r--package.json3
2 files changed, 28 insertions, 15 deletions
diff --git a/lib/serve.js b/lib/serve.js
index 81ab0b7..25969c9 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -21,6 +21,7 @@ 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
@@ -956,27 +957,38 @@ Serve.prototype.blob = function (id) {
}
if (!has) return self.respond(404, 'Not found')
- blobs.size(id, done())
- var rotatedSize = null
+ var heresTheData = done()
+ var heresTheType = done().bind(self, 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()
+ ident(heresTheType),
+ concat.buffer(onFullBuffer)
)
- done(function (err, size, type) {
- if (err) console.trace(err)
+
+ 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', rotatedSize || 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')
diff --git a/package.json b/package.json
index f398f61..e70fa96 100644
--- a/package.json
+++ b/package.json
@@ -7,13 +7,14 @@
"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",
"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",