diff options
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/lib/serve.js b/lib/serve.js index 5ebfa47..c162e42 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -201,8 +201,9 @@ Serve.prototype.wantBlobs = function (cb) { if (!ids.every(u.isRef)) return cb(new Error('bad blob ids ' + ids.join(','))) var done = multicb({pluck: 1}) ids.forEach(function (id) { - self.app.sbot.blobs.want(id, done()) + self.app.wantSizeBlob(id, done()) }) + if (self.data.async_want) return cb() done(function (err) { if (err) return cb(err) // self.note = h('div', 'wanted blobs: ' + ids.join(', ') + '.') @@ -303,6 +304,7 @@ Serve.prototype.path = function (url) { case '/git': return this.git(m[2]) case '/image': return this.image(m[2]) case '/npm': return this.npm(m[2]) + case '/npm-readme': return this.npmReadme(m[2]) } return this.respond(404, 'Not found') } @@ -1911,7 +1913,8 @@ Serve.prototype.npm = function (url) { ph('td', 'version'), ph('td', 'tag'), ph('td', 'size'), - ph('td', 'tarball') + ph('td', 'tarball'), + ph('td', 'readme') ])), ph('tbody', pull( self.app.blobMentions({ @@ -1934,7 +1937,30 @@ Serve.prototype.npm = function (url) { )) ]) ]), - self.wrapPage('npm:'), + self.wrapPage(prefix), + self.respondSink(200) + ) +} + +Serve.prototype.npmReadme = function (url) { + var self = this + var id = decodeURIComponent(url.substr(1)) + return pull( + ph('section', {}, [ + ph('h3', [ + 'npm readme for ', + ph('a', {href: '/links/' + id}, id.substr(0, 8) + '…') + ]), + ph('blockquote', u.readNext(function (cb) { + self.app.getNpmReadme(id, function (err, readme, isMarkdown) { + if (err) return cb(null, ph('div', u.renderError(err).outerHTML)) + cb(null, isMarkdown + ? ph('div', self.app.render.markdown(readme)) + : ph('pre', readme)) + }) + })) + ]), + self.wrapPage('npm readme'), self.respondSink(200) ) } |