aboutsummaryrefslogtreecommitdiff
path: root/lib/serve.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/serve.js')
-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] === '#') {