git ssb

16+

Dominic / patchbay



Tree: 302a1977ff1d540991f9e38ace65341334faef0a

Files: 302a1977ff1d540991f9e38ace65341334faef0a / router / sync / routes.js

1379 bytesRaw
1const nest = require('depnest')
2const { isBlob, isFeed, isMsg } = require('ssb-ref')
3
4exports.gives = nest('router.sync.routes')
5
6exports.needs = nest({
7 'app.page': {
8 'errors': 'first',
9 'public': 'first',
10 'private': 'first',
11 'notifications': 'first',
12 'profile': 'first',
13 'search': 'first',
14 'blob': 'first',
15 'thread': 'first',
16 'channel': 'first'
17 },
18 'keys.sync.id': 'first'
19})
20
21exports.create = (api) => {
22 return nest('router.sync.routes', (sofar = []) => {
23 const myId = api.keys.sync.id()
24 const pages = api.app.page
25
26 // loc = location
27 const routes = [
28 [ loc => loc.page === 'public', pages.public ],
29 [ loc => loc.page === 'private', pages.private ],
30 [ loc => loc.page === 'notifications', pages.notifications ],
31 [ loc => loc.page === 'errors', pages.errors ],
32 [ loc => loc.page === 'profile', () => pages.profile({ feed: myId }) ],
33 [ loc => loc.page === 'search' && loc.query, pages.search ],
34
35 [ loc => isBlob(loc.blob), pages.blob ],
36 [ loc => isPresent(loc.channel), pages.channel ],
37 [ loc => isFeed(loc.feed), pages.profile ],
38 [ loc => isMsg(loc.key), pages.thread ]
39 ]
40
41 // stack already loaded routes on top of these
42 return [...sofar, ...routes]
43 })
44}
45
46function isPresent (content) {
47 return typeof content === 'string' && content.length > 1
48}
49

Built with git-ssb-web