Files: 8c00d2692c05faece6e79ee8158e2cbf6612e078 / router / sync / routes.js
3172 bytesRaw
1 | const nest = require('depnest') |
2 | const { isMsg, isFeed, isBlob } = require('ssb-ref') |
3 | const openExternal = require('open-external') |
4 | const get = require('lodash/get') |
5 | |
6 | exports.gives = nest('router.sync.routes') |
7 | |
8 | exports.needs = nest({ |
9 | 'app.page.error': 'first', |
10 | 'app.page.addressBook': 'first', |
11 | 'app.page.blogIndex': 'first', |
12 | 'app.page.blogNew': 'first', |
13 | 'app.page.blogSearch': 'first', |
14 | 'app.page.blogShow': 'first', |
15 | 'app.page.settings': 'first', |
16 | // 'app.page.channel': 'first', |
17 | // 'app.page.groupFind': 'first', |
18 | // 'app.page.groupIndex': 'first', |
19 | // 'app.page.groupNew': 'first', |
20 | // 'app.page.groupShow': 'first', |
21 | 'app.page.userEdit': 'first', |
22 | // 'app.page.userFind': 'first', |
23 | 'app.page.userShow': 'first', |
24 | 'app.page.splash': 'first', |
25 | 'app.page.threadNew': 'first', |
26 | 'app.page.threadShow': 'first', |
27 | // 'app.page.image': 'first', |
28 | 'blob.sync.url': 'first', |
29 | }) |
30 | |
31 | exports.create = (api) => { |
32 | return nest('router.sync.routes', (sofar = []) => { |
33 | const pages = api.app.page |
34 | // route format: [ routeValidator, routeFunction ] |
35 | |
36 | const routes = [ |
37 | [ location => location.page === 'splash', pages.splash ], |
38 | |
39 | // Blog pages |
40 | [ location => location.page === 'blogIndex', pages.blogIndex ], |
41 | [ location => location.page === 'blogNew', pages.blogNew ], |
42 | [ location => location.page === 'blogSearch', pages.blogSearch ], |
43 | [ location => location.page === 'blogShow', pages.blogShow ], |
44 | [ location => isMsg(location.key) && get(location, 'value.content.type') === 'blog', pages.blogShow ], |
45 | [ location => { |
46 | return isMsg(location.key) |
47 | && get(location, 'value.content.type') === 'post' |
48 | && !get(location, 'value.private') // treats public posts as 'blogs' |
49 | }, pages.blogShow ], |
50 | |
51 | // AddressBook pages |
52 | [ location => location.page === 'addressBook', pages.addressBook ], |
53 | |
54 | // Private Thread pages |
55 | // [ location => location.page === 'threadNew' && location.channel, pages.threadNew ], |
56 | [ location => location.page === 'threadNew' && isFeed(location.feed), pages.threadNew ], |
57 | [ location => isMsg(location.key), pages.threadShow ], |
58 | |
59 | // User pages |
60 | // [ location => location.page === 'userFind', pages.userFind ], |
61 | [ location => location.page === 'userEdit' && isFeed(location.feed), pages.userEdit ], |
62 | [ location => isFeed(location.feed), pages.userShow ], |
63 | |
64 | // Group pages |
65 | // [ location => location.page === 'groupFind', pages.groupFind ], |
66 | // [ location => location.page === 'groupIndex', pages.groupIndex ], |
67 | // [ location => location.page === 'groupNew', pages.groupNew ], |
68 | // // [ location => location.type === 'groupShow' && isMsg(location.key), pages.groupShow ], |
69 | // [ location => location.channel , pages.channel ], |
70 | |
71 | [ location => location.page === 'settings', pages.settings ], |
72 | |
73 | // [ location => isBlob(location.blob), pages.image ], |
74 | [ location => isBlob(location.blob), (location) => { |
75 | openExternal(api.blob.sync.url(location.blob)) |
76 | }], |
77 | |
78 | // Error page |
79 | [ location => true, pages.error ] |
80 | ] |
81 | |
82 | return [...routes, ...sofar] |
83 | }) |
84 | } |
85 | |
86 |
Built with git-ssb-web