git ssb

2+

mixmix / ticktack



Tree: b42fccbaa67e2711ebbeb26092b463df381ba13a

Files: b42fccbaa67e2711ebbeb26092b463df381ba13a / router / sync / routes.js

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

Built with git-ssb-web