git ssb

2+

mixmix / ticktack



Tree: 1c2359030ac279f1fdfef805d7938f3003372c24

Files: 1c2359030ac279f1fdfef805d7938f3003372c24 / router / sync / routes.js

3644 bytesRaw
1const nest = require('depnest')
2const { isMsg, isFeed, isBlob } = require('ssb-ref')
3const openExternal = require('open-external')
4const get = require('lodash/get')
5
6exports.gives = nest('router.sync.routes')
7
8exports.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.statsShow': 'first',
28 'app.page.threadNew': 'first',
29 'app.page.threadShow': 'first',
30 // 'app.page.image': 'first',
31 'blob.sync.url': 'first'
32})
33
34exports.create = (api) => {
35 return nest('router.sync.routes', (sofar = []) => {
36 const pages = api.app.page
37 // route format: [ routeValidator, routeFunction ]
38
39 const routes = [
40 [ location => location.page === 'splash', pages.splash ],
41
42 // Blog pages
43 [ location => location.page === 'blogIndex', pages.blogIndex ],
44 [ location => location.page === 'blogNew', pages.blogNew ],
45 [ location => location.page === 'blogSearch', pages.blogSearch ],
46 [ location => location.page === 'blogShow', pages.blogShow ],
47 [ location => isMsg(location.key) && get(location, 'value.content.type') === 'blog', pages.blogShow ],
48 [ location => {
49 return isMsg(location.key) &&
50 get(location, 'value.content.type') === 'post' &&
51 !get(location, 'value.private') // treats public posts as 'blogs'
52 }, pages.blogShow ],
53
54 // Channel related pages
55 [ location => location.page === 'channelSubscriptions', pages.channelSubscriptions ],
56 [ location => location.page === 'channelShow', pages.channelShow ],
57 [ location => location.channel, pages.channelShow ],
58
59 // Stats pages
60 [ location => location.page === 'statsShow', pages.statsShow ],
61
62 // AddressBook pages
63 [ location => location.page === 'addressBook', pages.addressBook ],
64
65 // Private Thread pages
66 // [ location => location.page === 'threadNew' && location.channel, pages.threadNew ],
67 [ location => location.page === 'threadNew' && location.participants.every(isFeed), pages.threadNew ],
68 [ location => isMsg(location.key), pages.threadShow ],
69
70 // User pages
71 // [ location => location.page === 'userFind', pages.userFind ],
72 [ location => location.page === 'userEdit' && isFeed(location.feed), pages.userEdit ],
73 [ location => isFeed(location.feed), pages.userShow ],
74
75 // Group pages
76 // [ location => location.page === 'groupFind', pages.groupFind ],
77 // [ location => location.page === 'groupIndex', pages.groupIndex ],
78 // [ location => location.page === 'groupNew', pages.groupNew ],
79 // // [ location => location.type === 'groupShow' && isMsg(location.key), pages.groupShow ],
80 // [ location => location.channel , pages.channel ],
81
82 [ location => location.page === 'settings', pages.settings ],
83
84 // [ location => isBlob(location.blob), pages.image ],
85 [ location => isBlob(location.blob), (location) => {
86 openExternal(api.blob.sync.url(location.blob))
87 }],
88
89 // Error page
90 [ location => true, pages.error ]
91 ]
92
93 return [...routes, ...sofar]
94 })
95}
96

Built with git-ssb-web