git ssb

16+

Dominic / patchbay



Tree: 6488759bc2fd16ee805d043447b749462714bfdb

Files: 6488759bc2fd16ee805d043447b749462714bfdb / router / sync / routes.js

1328 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 return [...sofar, ...routes]
42 })
43}
44
45function isPresent (content) {
46 return typeof content === 'string' && content.length > 1
47}
48

Built with git-ssb-web