Files: 5e5bef4d7a2202ff89f9fd54978ed73376abe898 / router / sync / routes.js
1326 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({ id: 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 | |
45 | function isPresent (content) { |
46 | return typeof content === 'string' && content.length > 1 |
47 | } |
48 |
Built with git-ssb-web