aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/app.js18
-rw-r--r--lib/render-msg.js15
-rw-r--r--lib/render.js49
-rw-r--r--lib/serve.js37
4 files changed, 117 insertions, 2 deletions
diff --git a/lib/app.js b/lib/app.js
index afa914f..3255851 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -545,3 +545,21 @@ App.prototype.streamPrivate = function (opts) {
pull.take(opts.limit)
)
}
+
+App.prototype.blobMentions = function (opts) {
+ if (!this.sbot.links2) return pull.error(new Error(
+ 'missing ssb-links plugin'))
+ return this.sbot.links2.read({
+ query: [
+ {$filter: {rel: ['mentions', opts.name]}},
+ {$filter: {dest: {$prefix: '&'}}},
+ {$map: {
+ name: ['rel', 1],
+ size: ['rel', 2],
+ link: 'dest',
+ author: 'source',
+ time: 'ts'
+ }}
+ ]
+ })
+}
diff --git a/lib/render-msg.js b/lib/render-msg.js
index e9fc413..2e58610 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -254,6 +254,7 @@ RenderMsg.prototype.message = function (cb) {
case 'mutual/credit': return this.mutualCredit(cb)
case 'mutual/account': return this.mutualAccount(cb)
case 'npm-publish': return this.npmPublish(cb)
+ case 'npm-packages': return this.npmPackages(cb)
default: return this.object(cb)
}
}
@@ -569,13 +570,16 @@ RenderMsg.prototype.gitUpdate = function (cb) {
h('code', String(tag.sha1).substr(0, 8))), ' ',
'tagged ', String(tag.type), ' ',
h('code', String(tag.object).substr(0, 8)), ' ',
- String(tag.tag)
+ String(tag.tag),
+ tag.title ? [': ', self.linkify(String(tag.title).trim()), ' '] : '',
+ tag.body ? self.render.gitCommitBody(tag.body) : ''
)
})) : '',
self.c.commits_more ? h('div',
'+ ' + self.c.commits_more + ' more commits') : '',
self.c.tags_more ? h('div',
- '+ ' + self.c.tags_more + ' more tags') : ''
+ '+ ' + self.c.tags_more + ' more tags') : '',
+ self.render.npmPackageMentions(self.c.mentions)
), cb)
})
}
@@ -943,6 +947,13 @@ RenderMsg.prototype.npmPublish = function (cb) {
})
}
+RenderMsg.prototype.npmPackages = function (cb) {
+ var self = this
+ self.wrap([
+ self.render.npmPackageMentions(self.c.mentions)
+ ], cb)
+}
+
RenderMsg.prototype.npmPublishTitle = function (cb) {
var pkg = this.c.meta || {}
var name = pkg.name || pkg._id || '?'
diff --git a/lib/render.js b/lib/render.js
index 63eecd4..9bba5bd 100644
--- a/lib/render.js
+++ b/lib/render.js
@@ -389,3 +389,52 @@ Render.prototype.highlight = function (code, lang) {
return u.escapeHTML(code)
}
}
+
+Render.prototype.npmPackageMentions = function (links) {
+ var self = this
+ var pkgLinks = u.toArray(links).filter(function (link) {
+ return /^npm:/.test(link.name)
+ })
+ return pkgLinks.length > 0 ? h('div',
+ h('table',
+ h('thead', h('tr',
+ h('td', 'package'),
+ h('td', 'version'),
+ h('td', 'tag'),
+ h('td', 'size'),
+ h('td', 'tarball')
+ )),
+ h('tbody', pkgLinks.map(function (link) {
+ return self.npmPackageMention(link)
+ }))
+ )
+ ) : ''
+}
+
+Render.prototype.npmPackageMention = function (link) {
+ var parts = String(link.name).replace(/\.tgz$/, '').split(':')
+ var name = parts[1]
+ var version = parts[2]
+ var distTag = parts[3]
+ return h('tr', [
+ h('td', h('a', {
+ href: this.toUrl('/npm/' + name),
+ title: 'package name'
+ }, name), ' '),
+ h('td', version ? [h('a', {
+ href: this.toUrl('/npm/' + name + '/' + version + '/'),
+ title: 'package version'
+ }, version), ' '] : ''),
+ h('td', distTag ? [h('a', {
+ href: this.toUrl('/npm/' + name + '//' + distTag + '/'),
+ title: 'dist-tag'
+ }, distTag), ' '] : ''),
+ h('td', {align: 'right'}, link.size != null ? [h('span', {
+ title: 'tarball size'
+ }, this.formatSize(link.size)), ' '] : ''),
+ h('td', typeof link.link === 'string' ? [h('a', {
+ href: this.toUrl('/links/' + link.link),
+ title: 'package tarball'
+ }, link.link.substr(0, 8) + '…')] : '')
+ ])
+}
diff --git a/lib/serve.js b/lib/serve.js
index c4c740c..9686927 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -302,6 +302,7 @@ Serve.prototype.path = function (url) {
case '/about': return this.about(m[2])
case '/git': return this.git(m[2])
case '/image': return this.image(m[2])
+ case '/npm': return this.npm(m[2])
}
return this.respond(404, 'Not found')
}
@@ -1872,6 +1873,42 @@ Serve.prototype.gitObjectLinks = function (headMsgId, type) {
}, 8)
}
+Serve.prototype.npm = function (url) {
+ var self = this
+ var parts = url.split('/')
+ var name = parts[1]
+ var version = parts[2]
+ var distTag = parts[3]
+ var prefix = 'npm:' +
+ (name ? name + ':' +
+ (version ? version + ':' +
+ (distTag ? distTag + ':' : '') : '') : '')
+
+ return pull(
+ ph('section', {}, [
+ ph('h3', ['npm: ',
+ name ? [ph('code', name), ' '] : '',
+ version ? [ph('code', version), ' '] : '',
+ distTag ? [ph('code', distTag), ' '] : ''
+ ]),
+ pull(
+ self.app.blobMentions({
+ name: {$prefix: prefix}
+ }),
+ distTag && !version && pull.filter(function (link) {
+ return link.name.split(':')[3] === distTag
+ }),
+ pull.map(function (link) {
+ return self.app.render.npmPackageMention(link)
+ }),
+ pull.map(u.toHTML)
+ )
+ ]),
+ self.wrapPage('npm:'),
+ self.respondSink(200)
+ )
+}
+
// wrap a binary source and render it or turn into an embed
Serve.prototype.wrapBinary = function (opts) {
var self = this