git ssb

16+

Dominic / patchbay



Tree: 7e29e0bb496e38848f9337fa4cd58555f341bb0a

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

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

Built with git-ssb-web