From 567a75309f69d495ff55a1dc6b43a4774c69fe31 Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 27 Nov 2020 12:18:06 -0500 Subject: Add mentions for ssb URIs --- lib/serve.js | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) (limited to 'lib/serve.js') diff --git a/lib/serve.js b/lib/serve.js index 67b57c7..50bfff2 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -25,15 +25,12 @@ var split = require('pull-split') var utf8 = require('pull-utf8-decoder') var webresolve = require('ssb-web-resolver') var Url = require('url') -var Base64URL = require('base64-url') module.exports = Serve var hlCssDir = path.join(require.resolve('highlight.js'), '../../styles') -var ssbURIRegex = /^(ssb:(message|blob|feed)([:\/])([^:?]*?)([:/])([^?]*)(\\?.*)?)$/ var urlIdRegex = /^(?:\/+(([%&@]|%25|%26)(?:[A-Za-z0-9\/+]|%2[Ff]|%2[Bb]){43}(?:=|%3D)\.(?:sha256|ed25519))([^?]*)?|(\/.*?))(?:\?(.*))?$/ -var gitSsbRepoIdRegex = /^ssb:\/\/(%[A-Za-z0-9\/+]{43}=\.sha256)(\?.*)?$/ function ctype(name) { switch (name && /[^.\/]*$/.exec(name)[0] || 'html') { @@ -451,41 +448,6 @@ Serve.prototype.publishMayRedirect = function (content, cb) { } } -Serve.prototype.translateFromGitSsbRepoId = function (url) { - var m = gitSsbRepoIdRegex.exec(url) - if (!m) return - var id = m[1] - var qs = m[2] || '' - return id + qs -} - -Serve.prototype.translateFromURI = function (url) { - var m = ssbURIRegex.exec(url) - if (!m) return this.translateFromGitSsbRepoId(url) - var uri = m[1] - var prefix = m[2] - var separator = m[3] - var format = m[4] - var separator2 = m[5] - var hash = m[6] - var qs = m[7] || '' - if (separator !== separator2) return - hash = Base64URL.unescape(hash) - if (separator === '/') { - // ssb-custom-uri - try { hash = decodeURIComponent(hash) } - catch(e) {} - } - var sigil - switch (prefix) { - case 'message': sigil = '%'; break - case 'blob': sigil = '&'; break - case 'feed': sigil = '@'; break - default: return - } - return sigil + hash + '.' + format + qs -} - Serve.prototype.handle = function () { var m = urlIdRegex.exec(this.req.url) this.query = m[5] ? qs.parse(m[5]) : {} @@ -538,7 +500,7 @@ Serve.prototype.redirect = function (dest) { Serve.prototype.path = function (url) { if (url.substr(0, 5) === '/ssb:') { - var link = this.translateFromURI(url.substr(1)) + var link = u.translateFromURI(url.substr(1)) if (link) return this.redirect(this.app.render.toUrl(link)) } var m @@ -774,7 +736,7 @@ Serve.prototype.search = function (ext) { var maybeId = searchQ.substr(6) if (u.isRef(maybeId)) searchQ = maybeId } - var link = this.translateFromURI(searchQ) + var link = u.translateFromURI(searchQ) if (link) return self.redirect(self.app.render.toUrl(link)) if (u.isRef(searchQ) || searchQ[0] === '#') { -- cgit v1.2.3