Commit a90a1c43ce789756570fb5b3b4601ddd6614b091
Merge pull request #306 from ssbc/support-ssb-uri
Add SSB URI supportmix irving authored on 1/30/2019, 12:48:46 AM
GitHub committed on 1/30/2019, 12:48:46 AM
Parent: d006827557e63f5aabd07e480b910ca50ddb9646
Parent: 9685f2bac5b5ddf1f41373900ab3405b765c7076
Files changed
app/async/catch-link-click.js | changed |
app/html/search-bar.js | changed |
package-lock.json | changed |
package.json | changed |
router/async/normalise.js | changed |
app/async/catch-link-click.js | |||
---|---|---|---|
@@ -1,6 +1,5 @@ | |||
1 | 1 … | const nest = require('depnest') | |
2 | -const Url = require('url') | ||
3 | 2 … | ||
4 | 3 … | exports.gives = nest('app.async.catchLinkClick') | |
5 | 4 … | ||
6 | 5 … | exports.needs = nest({ | |
@@ -31,9 +30,17 @@ | |||
31 | 30 … | ||
32 | 31 … | var href = anchor.getAttribute('href') | |
33 | 32 … | if (!href || href === '#') return | |
34 | 33 … | ||
35 | - var url = Url.parse(href) | ||
34 … | + var url | ||
35 … | + | ||
36 … | + try { | ||
37 … | + var url = new URL(href) | ||
38 … | + } catch (e) { | ||
39 … | + // In case we pass an invalid URL | ||
40 … | + url = {} | ||
41 … | + } | ||
42 … | + | ||
36 | 43 … | var opts = { | |
37 | 44 … | altKey: ev.altKey, | |
38 | 45 … | ctrlKey: ev.ctrlKey, | |
39 | 46 … | metaKey: ev.metaKey, |
app/html/search-bar.js | ||
---|---|---|
@@ -17,11 +17,13 @@ | ||
17 | 17 … | return nest('app.html.searchBar', function searchBar () { |
18 | 18 … | if (_search) return _search |
19 | 19 … | |
20 | 20 … | function goToLocation (location, ev) { |
21 … | + const prefixes = ['@', '#', '%', '&', '/', 'ssb:'] | |
22 … | + | |
21 | 23 … | if (location[0] === '?') { |
22 | 24 … | location = { page: 'search', query: location.substring(1) } |
23 | - } else if (!['@', '#', '%', '&', '/'].includes(location[0])) { | |
25 … | + } else if (prefixes.every(p => !location.startsWith(p))) { | |
24 | 26 … | location = { page: 'search', query: location } |
25 | 27 … | } |
26 | 28 … | |
27 | 29 … | api.app.sync.goTo(location) |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 587807 bytes New file size: 589463 bytes |
package.json | ||
---|---|---|
@@ -111,8 +111,9 @@ | ||
111 | 111 … | "ssb-server": "^14.0.3", |
112 | 112 … | "ssb-sort": "^1.1.0", |
113 | 113 … | "ssb-suggest": "^1.0.3", |
114 | 114 … | "ssb-unread": "^1.0.2", |
115 … | + "ssb-uri": "^1.0.1", | |
115 | 116 … | "ssb-ws": "^4.0.1", |
116 | 117 … | "suggest-box": "^2.2.3", |
117 | 118 … | "text-node-searcher": "^1.1.1", |
118 | 119 … | "xtend": "^4.0.1" |
router/async/normalise.js | ||
---|---|---|
@@ -1,6 +1,7 @@ | ||
1 | 1 … | const nest = require('depnest') |
2 | 2 … | const { isBlobLink, isFeed, isMsg } = require('ssb-ref') |
3 … | +const ssbUri = require('ssb-uri') | |
3 | 4 … | |
4 | 5 … | exports.gives = nest('router.async.normalise') |
5 | 6 … | |
6 | 7 … | exports.needs = nest({ |
@@ -21,8 +22,16 @@ | ||
21 | 22 … | if (location.match(/^%25.*%3D.sha256$/)) { |
22 | 23 … | location = decodeURIComponent(location) |
23 | 24 … | } |
24 | 25 … | |
26 … | + if (location.startsWith('ssb:')) { | |
27 … | + try { | |
28 … | + location = ssbUri.toSigilLink(location) | |
29 … | + } catch (err) { | |
30 … | + cb(err) | |
31 … | + } | |
32 … | + } | |
33 … | + | |
25 | 34 … | if (isMsg(location)) { |
26 | 35 … | api.sbot.async.get(location, (err, value) => { |
27 | 36 … | if (err) cb(err) |
28 | 37 … | else { |
Built with git-ssb-web