git ssb

16+

Dominic / patchbay



Tree: 5f97507b06176a1234e3614305355b78666ee6f9

Files: 5f97507b06176a1234e3614305355b78666ee6f9 / router / sync / routes.js

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

Built with git-ssb-web