git ssb

3+

cel / ssb-npm-registry



Commit a3a138c8aab9a07782fdb33a880803a50d51b994

Allow multiple messages IDs for scope

cel committed on 6/30/2018, 8:57:26 PM
Parent: 8fe62bb65f2acf84e07a7284752d9d79e13e0903

Files changed

README.mdchanged
index.jschanged
README.mdView
@@ -112,9 +112,9 @@
112112 [`prebuild-install`]: https://github.com/prebuild/prebuild-install
113113
114114 ### Message scope
115115
116-Requests to the registry server can be scoped to a message by prefixing the request pathname with a directory part with a url-encoded message id. You can make such requests by including that prefix in the registry URL. i.e. `npm --registry=http://localhost:8043/<MsgIdEnc>/ ...`
116 +Requests to the registry server can be scoped to one or more messages by prefixing the request pathname with a directory part with url-encoded message ids. You can make such requests by including that prefix in the registry URL. i.e. `npm --registry=http://localhost:8043/<MsgIdEnc>[,<MsgIdEnc>...]/ ...`
117117
118118 If a request is scoped to a message, the registry server will answer the request using information contained in that message or messages that it links to (recursively), instead of by using `sbot`'s ssb-links indexes. Fetching messages for a message-scoped request will be done using [`ssb-ooo`][] if that sbot plugin is available.
119119
120120 A message-scoped request allows you to install a package without having to replicate the feeds of the authors of the package or its dependencies, since the information needed to install the package is referenced by message id.
index.jsView
@@ -458,11 +458,11 @@
458458 console.log(this.req.method, this.req.url, this.req.socket.remoteAddress.replace(/^::ffff:/, ''))
459459 this.res.setTimeout(0)
460460 var pathname = this.req.url.replace(/\?.*/, '')
461461 var m
462- if ((m = /^\/(\^|%5[Ee])?(%25.*sha256)(\/.*)$/.exec(pathname))) {
462 + if ((m = /^\/(\^|%5[Ee])?(%25.*sha256)+(\/.*)$/.exec(pathname))) {
463463 try {
464- this.headMsgId = decodeURIComponent(m[2])
464 + this.headMsgIds = decodeURIComponent(m[2]).split(',')
465465 this.headMsgPlus = !!m[1]
466466 // ^ means also include packages published after the head message id
467467 } catch(e) {
468468 return this.respondError(400, e.stack || e)
@@ -519,9 +519,9 @@
519519 }
520520
521521 Req.prototype.getMsgMentions = function (name) {
522522 return pull(
523- this.server.streamTree([this.headMsgId], 'dependencyBranch'),
523 + this.server.streamTree(this.headMsgIds, 'dependencyBranch'),
524524 // decryption could be done here
525525 pull.map(function (msg) {
526526 var c = msg.value && msg.value.content
527527 if (!c.mentions || !Array.isArray(c.mentions)) return []
@@ -546,10 +546,10 @@
546546 )
547547 }
548548
549549 Req.prototype.getMentions = function (name) {
550- var useMsgMentions = this.headMsgId
551- var useServerMentions = !this.headMsgId || this.headMsgPlus
550 + var useMsgMentions = this.headMsgIds
551 + var useServerMentions = !this.headMsgIds || this.headMsgPlus
552552 if (useServerMentions && !this.server.sbot.links2) {
553553 return this.headMsgPlus
554554 ? pull.error(new Error('ssb-links scuttlebot plugin is needed for ^msgid queries'))
555555 : pull.error(new Error('ssb-links scuttlebot plugin is needed for non-msgid queries'))
@@ -561,10 +561,10 @@
561561 }
562562
563563 Req.prototype.getMentionLinks = function (blobId) {
564564 return pull(
565- this.headMsgId
566- ? this.server.streamTree([this.headMsgId], 'dependencyBranch')
565 + this.headMsgIds
566 + ? this.server.streamTree(this.headMsgIds, 'dependencyBranch')
567567 : this.server.sbot.links({
568568 dest: blobId,
569569 rel: 'mentions',
570570 values: true,

Built with git-ssb-web