git ssb

16+

Dominic / patchbay



Tree: 9aa1b3e58b249adff685afd5c3f4d49e488029d2

Files: 9aa1b3e58b249adff685afd5c3f4d49e488029d2 / router / sync / routes.js

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

Built with git-ssb-web