git ssb

16+

Dominic / patchbay



Tree: f0535dd0a919de44e6900039da1cfe29882caa5a

Files: f0535dd0a919de44e6900039da1cfe29882caa5a / router / sync / routes.js

1555 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 'imageSearch': 'first',
15 'blob': 'first',
16 'thread': 'first',
17 'channel': 'first',
18 'settings': 'first'
19
20 },
21 'keys.sync.id': 'first'
22})
23
24exports.create = (api) => {
25 return nest('router.sync.routes', (sofar = []) => {
26 const myId = api.keys.sync.id()
27 const pages = api.app.page
28
29 // loc = location
30 const routes = [
31 [ loc => loc.page === 'public', pages.public ],
32 [ loc => loc.page === 'private', pages.private ],
33 [ loc => loc.page === 'notifications', pages.notifications ],
34 [ loc => loc.page === 'errors', pages.errors ],
35 [ loc => loc.page === 'profile', () => pages.profile({ feed: myId }) ],
36 [ loc => loc.page === 'search' && loc.query, pages.search ],
37 [ loc => loc.page === 'imageSearch', pages.imageSearch ],
38 [ loc => loc.page === 'settings', pages.settings ],
39
40 [ loc => isBlob(loc.blob), pages.blob ],
41 [ loc => isPresent(loc.channel), pages.channel ],
42 [ loc => isFeed(loc.feed), pages.profile ],
43 [ loc => isMsg(loc.key), pages.thread ]
44 ]
45
46 // stack already loaded routes on top of these
47 return [...sofar, ...routes]
48 })
49}
50
51function isPresent (content) {
52 return typeof content === 'string' && content.length > 1
53}
54

Built with git-ssb-web