Files: 81b5142c9c1ffb82378b6e32ba1b24a2d3a029e5 / router / sync / routes.js
3518 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.channelSubscriptions': 'first', |
17 | 'app.page.channelShow': 'first', |
18 | // 'app.page.channel': 'first', |
19 | // 'app.page.groupFind': 'first', |
20 | // 'app.page.groupIndex': 'first', |
21 | // 'app.page.groupNew': 'first', |
22 | // 'app.page.groupShow': 'first', |
23 | 'app.page.userEdit': 'first', |
24 | // 'app.page.userFind': 'first', |
25 | 'app.page.userShow': 'first', |
26 | 'app.page.splash': 'first', |
27 | 'app.page.threadNew': 'first', |
28 | 'app.page.threadShow': 'first', |
29 | // 'app.page.image': 'first', |
30 | 'blob.sync.url': 'first' |
31 | }) |
32 | |
33 | exports.create = (api) => { |
34 | return nest('router.sync.routes', (sofar = []) => { |
35 | const pages = api.app.page |
36 | // route format: [ routeValidator, routeFunction ] |
37 | |
38 | const routes = [ |
39 | [ location => location.page === 'splash', pages.splash ], |
40 | |
41 | // Blog pages |
42 | [ location => location.page === 'blogIndex', pages.blogIndex ], |
43 | [ location => location.page === 'blogNew', pages.blogNew ], |
44 | [ location => location.page === 'blogSearch', pages.blogSearch ], |
45 | [ location => location.page === 'blogShow', pages.blogShow ], |
46 | [ location => isMsg(location.key) && get(location, 'value.content.type') === 'blog', pages.blogShow ], |
47 | [ location => { |
48 | return isMsg(location.key) && |
49 | get(location, 'value.content.type') === 'post' && |
50 | !get(location, 'value.private') // treats public posts as 'blogs' |
51 | }, pages.blogShow ], |
52 | |
53 | // Channel related pages |
54 | [ location => location.page === 'channelSubscriptions', pages.channelSubscriptions], |
55 | [ location => location.page === 'channelShow', pages.channelShow ], |
56 | [ location => location.channel, pages.channelShow ], |
57 | |
58 | // AddressBook pages |
59 | [ location => location.page === 'addressBook', pages.addressBook ], |
60 | |
61 | // Private Thread pages |
62 | // [ location => location.page === 'threadNew' && location.channel, pages.threadNew ], |
63 | [ location => location.page === 'threadNew' && location.participants.every(isFeed), pages.threadNew ], |
64 | [ location => isMsg(location.key), pages.threadShow ], |
65 | |
66 | // User pages |
67 | // [ location => location.page === 'userFind', pages.userFind ], |
68 | [ location => location.page === 'userEdit' && isFeed(location.feed), pages.userEdit ], |
69 | [ location => isFeed(location.feed), pages.userShow ], |
70 | |
71 | // Group pages |
72 | // [ location => location.page === 'groupFind', pages.groupFind ], |
73 | // [ location => location.page === 'groupIndex', pages.groupIndex ], |
74 | // [ location => location.page === 'groupNew', pages.groupNew ], |
75 | // // [ location => location.type === 'groupShow' && isMsg(location.key), pages.groupShow ], |
76 | // [ location => location.channel , pages.channel ], |
77 | |
78 | [ location => location.page === 'settings', pages.settings ], |
79 | |
80 | // [ location => isBlob(location.blob), pages.image ], |
81 | [ location => isBlob(location.blob), (location) => { |
82 | openExternal(api.blob.sync.url(location.blob)) |
83 | }], |
84 | |
85 | // Error page |
86 | [ location => true, pages.error ] |
87 | ] |
88 | |
89 | return [...routes, ...sofar] |
90 | }) |
91 | } |
92 |
Built with git-ssb-web