aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519>2020-11-27 11:19:37 -0500
committercel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519>2020-11-27 11:19:37 -0500
commitfdb5ceeebc7b7e7ca182c7ac547723a321c7ffc5 (patch)
treeb3b460c9e28a98623ca5ca5d76c9577c9c97cf5c
parent6a6f0b821f7d42f8ea24c3bc6b6ad61ce422e8d4 (diff)
downloadpatchfoo-fdb5ceeebc7b7e7ca182c7ac547723a321c7ffc5.tar.gz
patchfoo-fdb5ceeebc7b7e7ca182c7ac547723a321c7ffc5.zip
Fix support for git-ssb repo IDs
-rw-r--r--lib/serve.js17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/serve.js b/lib/serve.js
index aad2510..147c6ee 100644
--- a/lib/serve.js
+++ b/lib/serve.js
@@ -31,8 +31,9 @@ module.exports = Serve
var hlCssDir = path.join(require.resolve('highlight.js'), '../../styles')
-var ssbURIRegex = /^(?:\/+)(ssb:(message|blob|feed)([:\/])([^:?]*?)([:/])([^?]*)(\\?.*)?)$/
+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') {
@@ -450,9 +451,17 @@ 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
+ if (!m) return this.translateFromGitSsbRepoId(url)
var uri = m[1]
var prefix = m[2]
var separator = m[3]
@@ -529,7 +538,7 @@ Serve.prototype.redirect = function (dest) {
Serve.prototype.path = function (url) {
if (url.substr(0, 5) === '/ssb:') {
- var link = this.translateFromURI(url)
+ var link = this.translateFromURI(url.substr(1))
if (link) return this.redirect(this.app.render.toUrl(link))
}
var m
@@ -765,7 +774,7 @@ Serve.prototype.search = function (ext) {
var maybeId = searchQ.substr(6)
if (u.isRef(maybeId)) searchQ = maybeId
}
- var link = this.translateFromURI('/' + searchQ)
+ var link = this.translateFromURI(searchQ)
if (link) return self.redirect(self.app.render.toUrl(link))
if (u.isRef(searchQ) || searchQ[0] === '#') {