git ssb

16+

cel / patchfoo



Commit b6d136ab10136f9d881b239a338a4c0eea2e65f0

fixes

Stephen Whitmore committed on 6/10/2017, 10:06:49 PM
Parent: b4070f9b60e49b2c378bd85b4d0834101eae2632

Files changed

lib/serve.jschanged
package.jsonchanged
lib/serve.jsView
@@ -20,8 +20,9 @@
2020 var htime = require('human-time')
2121 var ph = require('pull-hyperscript')
2222 var emojis = require('emoji-named-characters')
2323 var jpeg = require('jpeg-autorotate')
24 +var concat = require('pull-concat')
2425
2526 module.exports = Serve
2627
2728 var emojiDir = path.join(require.resolve('emoji-named-characters'), '../pngs')
@@ -955,29 +956,40 @@
955956 else return self.respond(500, err.message || err)
956957 }
957958 if (!has) return self.respond(404, 'Not found')
958959
959- blobs.size(id, done())
960- var rotatedSize = null
960 + var heresTheData = done()
961 + var heresTheType = done().bind(self, null)
961962
962963 pull(
963964 blobs.get(id),
964965 pull.map(Buffer),
965- pull.asyncMap(function (buf, cb) {
966- jpeg.rotate(buf, {}, function (err, buffer, orientation) {
967- if (err) return cb(null, buf)
968- rotatedSize = buffer.length
969- return cb(null, buffer)
970- })
971- }),
972- ident(done().bind(self, null)),
973- self.respondSink()
966 + ident(heresTheType),
967 + concat.buffer(onFullBuffer)
974968 )
975- done(function (err, size, type) {
976- if (err) console.trace(err)
969 +
970 + function onFullBuffer (err, buffer) {
971 + if (err) return heresTheData(err)
972 +
973 + jpeg.rotate(buffer, {}, function (err, rotatedBuffer, orientation) {
974 + if (!err) buffer = rotatedBuffer
975 +
976 + heresTheData(null, buffer)
977 + pull(
978 + pull.once(buffer),
979 + self.respondSink()
980 + )
981 + })
982 + }
983 +
984 + done(function (err, data, type) {
985 + if (err) {
986 + console.trace(err)
987 + self.respond(500, err.message || err)
988 + }
977989 type = type && mime.lookup(type)
978990 if (type) self.res.setHeader('Content-Type', type)
979- if (typeof size === 'number') self.res.setHeader('Content-Length', rotatedSize || size)
991 + self.res.setHeader('Content-Length', data.length)
980992 if (self.query.name) self.res.setHeader('Content-Disposition',
981993 'inline; filename='+encodeDispositionFilename(self.query.name))
982994 self.res.setHeader('Cache-Control', 'public, max-age=315360000')
983995 self.res.setHeader('etag', id)
package.jsonView
@@ -6,15 +6,16 @@
66 "asyncmemo": "^1.0.0",
77 "busboy": "^0.2.14",
88 "emoji-named-characters": "^1.0.2",
99 "emoji-server": "^1.0.0",
10 + "hashlru": "^2.1.0",
1011 "human-time": "^0.0.1",
1112 "hyperscript": "^2.0.2",
12- "hashlru": "^2.1.0",
1313 "jpeg-autorotate": "^3.0.0",
1414 "mime-types": "^2.1.12",
1515 "multicb": "^1.2.1",
1616 "pull-cat": "^1.1.11",
17 + "pull-concat": "^1.1.1",
1718 "pull-git-packidx-parser": "^1.0.0",
1819 "pull-hash": "^1.0.0",
1920 "pull-hyperscript": "^0.2.2",
2021 "pull-identify-filetype": "^1.1.0",

Built with git-ssb-web