diff options
author | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-11-27 12:18:06 -0500 |
---|---|---|
committer | cel <cel@lOUVT+Phkvai9a/cCS/RKo+S9hnPAQdVixms/7ldpPA=.ed25519> | 2020-11-27 12:18:06 -0500 |
commit | 567a75309f69d495ff55a1dc6b43a4774c69fe31 (patch) | |
tree | 44e8b9d7c8a4bd3350e541da60e6149d2a034d9c /lib/util.js | |
parent | e6bb8bd53b7045b8bfcbeaa8936ab7a3ff1760e1 (diff) | |
download | patchfoo-567a75309f69d495ff55a1dc6b43a4774c69fe31.tar.gz patchfoo-567a75309f69d495ff55a1dc6b43a4774c69fe31.zip |
Add mentions for ssb URIs
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/util.js b/lib/util.js index 2fa5c63..e62bde9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -8,6 +8,8 @@ u.ssbRefRegex = /((?:@|%|&|ssb:\/\/%)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g u.ssbRefRegexOnly = /^(?:@|%|&|ssb:\/\/%)[A-Za-z0-9\/+]{43}=\.[\w\d]+$/ u.ssbRefEncRegex = /((?:ssb:\/\/)?(?:[@%&]|%26|%40|%25)(?:[A-Za-z0-9\/+]|%2[fF]|%2[bB]){43}(?:=|%3[dD])\.[\w\d]+)/g u.channelRegex = /^#[^\s#]+$/ +u.ssbURIRegex = /^(ssb:(message|blob|feed)([:\/])([^:?]*?)([:/])([^?]*)(\\?.*)?)$/ +u.gitSsbRepoIdRegex = /^ssb:\/\/(%[A-Za-z0-9\/+]{43}=\.sha256)(\?.*)?$/ u.isRef = function (str) { if (!str) return false @@ -292,3 +294,38 @@ u.extractHostPort = function (id, addr) { } return addr } + +u.translateFromGitSsbRepoId = function (url) { + var m = u.gitSsbRepoIdRegex.exec(url) + if (!m) return + var id = m[1] + var qs = m[2] || '' + return id + qs +} + +u.translateFromURI = function (url) { + var m = u.ssbURIRegex.exec(url) + if (!m) return u.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 = b64url.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 +} |