Files: d3a0c5e302f7edc7a52b5002d4c9ad4f2a2d4df3 / router / sync / routes.js
1273 bytesRaw
1 | const nest = require('depnest') |
2 | |
3 | exports.gives = nest('router.sync.routes') |
4 | |
5 | exports.needs = nest({ |
6 | 'app.page': { |
7 | 'errors': 'first', |
8 | 'public': 'first', |
9 | 'private': 'first', |
10 | 'notifications': 'first', |
11 | 'profile': 'first', |
12 | 'blob': 'first', |
13 | 'thread': 'first', |
14 | 'channel': 'first' |
15 | }, |
16 | 'keys.sync.id': 'first', |
17 | }) |
18 | |
19 | exports.create = (api) => { |
20 | return nest('router.sync.routes', (sofar = []) => { |
21 | const myId = api.keys.sync.id() |
22 | const { |
23 | errors, public, private, notifications, channel, |
24 | profile, blob, thread |
25 | } = api.app.page |
26 | |
27 | const routes = [ |
28 | [ ({ page }) => page === 'public', public ], |
29 | [ ({ page }) => page === 'private', private ], |
30 | [ ({ page }) => page === 'notifications', notifications ], |
31 | [ ({ page }) => page === 'errors', errors ], |
32 | [ ({ page }) => page === 'profile', () => profile({ id: myId }) ], |
33 | // TODO - use is-my-json-valid ? |
34 | [ ({ blob }) => isPresent(blob), blob ], |
35 | [ ({ channel }) => isPresent(channel), channel ], |
36 | [ ({ feed }) => isPresent(feed), profile ], |
37 | [ ({ msg }) => isPresent(msg), thread ] |
38 | ] |
39 | |
40 | return [...sofar, ...routes] |
41 | }) |
42 | } |
43 | |
44 | function isPresent (content) { |
45 | return typeof content === 'string' && content.length > 1 |
46 | } |
47 | |
48 | |
49 | |
50 |
Built with git-ssb-web