git ssb

16+

Dominic / patchbay



Tree: 4c7f9d8eb4c9386b518da6c6afa114503986945c

Files: 4c7f9d8eb4c9386b518da6c6afa114503986945c / router / sync / routes.js

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

Built with git-ssb-web