Files: 281a3bcf874278b04675432a0655c81ceba5f569 / router / sync / routes.js
1379 bytesRaw
1 | const nest = require('depnest') |
2 | const { isBlob, isFeed, isMsg } = require('ssb-ref') |
3 | |
4 | exports.gives = nest('router.sync.routes') |
5 | |
6 | exports.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 | |
21 | exports.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 | // stack already loaded routes on top of these |
42 | return [...sofar, ...routes] |
43 | }) |
44 | } |
45 | |
46 | function isPresent (content) { |
47 | return typeof content === 'string' && content.length > 1 |
48 | } |
49 |
Built with git-ssb-web