git ssb

3+

cel / ssb-npm-registry



Commit fa946a64685781d58a9266937da0e1d9c30a20d6

Generate _npmUser in response

Put the feed id and name for the "npm view" command to show.
cel committed on 8/31/2018, 2:32:11 AM
Parent: 87875a4f00604b64bb80b480a5764b44885eef80

Files changed

index.jschanged
index.jsView
@@ -338,8 +338,9 @@
338338 this.host = this.npmConfig.host || 'localhost'
339339 this.fetchAll = this.npmConfig.fetchAll
340340 this.needShasum = this.npmConfig.needShasum
341341 this.getMsg = memo({cache: lru(100)}, this.getMsg)
342 + this.getFeedName = memo({cache: lru(100)}, this.getFeedName)
342343 }
343344
344345 SsbNpmRegistryServer.prototype = Object.create(http.Server.prototype)
345346 SsbNpmRegistryServer.prototype.constructor = SsbNpmRegistryServer
@@ -412,8 +413,47 @@
412413 cb(null, {key: id, value: value})
413414 })
414415 }
415416
417 +SsbNpmRegistryServer.prototype.getFeedName = function (id, cb) {
418 + var self = this
419 + if (self.sbot.names && self.sbot.names.getSignifier) {
420 + self.sbot.names.getSignifier(id, function (err, name) {
421 + if (err || !name) tryLinks()
422 + else cb(null, name)
423 + })
424 + } else {
425 + tryLinks()
426 + }
427 + function tryLinks() {
428 + if (!self.sbot.links) return nope()
429 + pull(
430 + self.sbot.links({
431 + source: id,
432 + dest: id,
433 + rel: 'about',
434 + values: true,
435 + limit: 1,
436 + reverse: true,
437 + keys: false,
438 + meta: false
439 + }),
440 + pull.map(function (value) {
441 + return value && value.content && value.content.name
442 + }),
443 + pull.filter(Boolean),
444 + pull.take(1),
445 + pull.collect(function (err, names) {
446 + if (err || !names.length) return nope()
447 + cb(null, names[0])
448 + })
449 + )
450 + }
451 + function nope() {
452 + cb(null, '')
453 + }
454 +}
455 +
416456 SsbNpmRegistryServer.prototype.streamTree = function (heads, prop) {
417457 var self = this
418458 var stack = heads.slice()
419459 var seen = {}
@@ -1025,9 +1065,9 @@
10251065 // correct.
10261066 obj.dependencies = deps
10271067 obj.bundledDependencies = bundledDeps
10281068 if (shasum) obj.dist.shasum = obj._shasum = shasum
1029- cb(null, obj)
1069 + next(obj)
10301070 } else {
10311071 // get dependencies from the tarball
10321072 getPackageJsonFromTarballBlob(self.server.sbot, blobId, function (err, pkg) {
10331073 if (err) return cb(err)
@@ -1036,13 +1076,24 @@
10361076 pkg.author = pkg.author || obj.author
10371077 pkg.version = pkg.version || obj.version
10381078 pkg.name = pkg.name || obj.name
10391079 pkg.license = pkg.license || obj.license
1040- cb(null, pkg)
1080 + next(pkg)
10411081 })
10421082 }
10431083 })
10441084 )
1085 + function next(pkg) {
1086 + var feedId = obj.author.url
1087 + self.server.getFeedName(feedId, function (err, name) {
1088 + if (err) console.error('[npm-registry]', err.stack || err), name = ''
1089 + pkg._npmUser = {
1090 + email: feedId,
1091 + name: name
1092 + }
1093 + cb(null, pkg)
1094 + })
1095 + }
10451096 }
10461097
10471098 function getPackageJsonFromTarballBlob(sbot, id, cb) {
10481099 var self = this

Built with git-ssb-web