git ssb

16+

Dominic / patchbay



Tree: 7c6b563bcb3bbba64f3cebbf33a2e46ca364af95

Files: 7c6b563bcb3bbba64f3cebbf33a2e46ca364af95 / router / sync / routes.js

1629 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 'posts': 'first',
10 'public': 'first',
11 'private': 'first',
12 'notifications': 'first',
13 'profile': 'first',
14 'search': 'first',
15 'imageSearch': 'first',
16 'blob': 'first',
17 'thread': 'first',
18 'channel': 'first',
19 'settings': 'first'
20
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 === 'posts', pages.posts ],
33 [ loc => loc.page === 'public', pages.public ],
34 [ loc => loc.page === 'private', pages.private ],
35 [ loc => loc.page === 'notifications', pages.notifications ],
36 [ loc => loc.page === 'errors', pages.errors ],
37 [ loc => loc.page === 'profile', () => pages.profile({ feed: myId }) ],
38 [ loc => loc.page === 'search' && loc.query, pages.search ],
39 [ loc => loc.page === 'imageSearch', pages.imageSearch ],
40 [ loc => loc.page === 'settings', pages.settings ],
41
42 [ loc => isBlob(loc.blob), pages.blob ],
43 [ loc => isPresent(loc.channel), pages.channel ],
44 [ loc => isFeed(loc.feed), pages.profile ],
45 [ loc => isMsg(loc.key), pages.thread ]
46 ]
47
48 // stack already loaded routes on top of these
49 return [...sofar, ...routes]
50 })
51}
52
53function isPresent (content) {
54 return typeof content === 'string' && content.length > 1
55}
56

Built with git-ssb-web