Files: 90b52d74d1635f1581c983ea2ca9ff0b83ba8fab / router / sync / routes.js
2202 bytesRaw
1 | const nest = require('depnest') |
2 | const { isMsg, isFeed, isBlob } = require('ssb-ref') |
3 | const openExternal = require('open-external') |
4 | |
5 | exports.gives = nest('router.sync.routes') |
6 | |
7 | exports.needs = nest({ |
8 | 'app.page.error': 'first', |
9 | 'app.page.home': 'first', |
10 | 'app.page.channel': 'first', |
11 | 'app.page.settings': 'first', |
12 | 'app.page.groupFind': 'first', |
13 | 'app.page.groupIndex': 'first', |
14 | 'app.page.groupNew': 'first', |
15 | 'app.page.groupShow': 'first', |
16 | 'app.page.userEdit': 'first', |
17 | 'app.page.userFind': 'first', |
18 | 'app.page.userShow': 'first', |
19 | 'app.page.threadNew': 'first', |
20 | 'app.page.threadShow': 'first', |
21 | 'app.page.image': 'first', |
22 | 'blob.sync.url': 'first', |
23 | }) |
24 | |
25 | exports.create = (api) => { |
26 | return nest('router.sync.routes', (sofar = []) => { |
27 | const pages = api.app.page |
28 | // route format: [ routeValidator, routeFunction ] |
29 | |
30 | const routes = [ |
31 | |
32 | // Thread pages |
33 | [ location => location.page === 'threadNew' && isFeed(location.feed), pages.threadNew ], |
34 | [ location => location.page === 'threadNew' && location.channel, pages.threadNew ], |
35 | [ location => isMsg(location.key), pages.threadShow ], |
36 | |
37 | // User pages |
38 | [ location => location.page === 'userFind', pages.userFind ], |
39 | [ location => location.page === 'userEdit' && isFeed(location.feed), pages.userEdit ], |
40 | [ location => isFeed(location.feed), pages.userShow ], |
41 | |
42 | // Group pages |
43 | [ location => location.page === 'groupFind', pages.groupFind ], |
44 | [ location => location.page === 'groupIndex', pages.groupIndex ], |
45 | [ location => location.page === 'groupNew', pages.groupNew ], |
46 | // [ location => location.type === 'groupShow' && isMsg(location.key), pages.groupShow ], |
47 | [ location => location.channel , pages.channel ], |
48 | |
49 | [ location => location.page === 'home', pages.home ], |
50 | [ location => location.page === 'settings', pages.settings ], |
51 | // [ location => isBlob(location.blob), pages.image ], |
52 | |
53 | [ location => isBlob(location.blob), (location) => { |
54 | debugger |
55 | openExternal(api.blob.sync.url(location.blob)) |
56 | }], |
57 | |
58 | // Error page |
59 | [ location => true, pages.error ] |
60 | ] |
61 | |
62 | return [...routes, ...sofar] |
63 | }) |
64 | } |
65 | |
66 |
Built with git-ssb-web