git ssb

2+

mixmix / ticktack



Tree: a2b3f21193e91cdc60bd46279f51bf999c49647a

Files: a2b3f21193e91cdc60bd46279f51bf999c49647a / router / sync / routes.js

3154 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.userEdit': 'first',
20 'app.page.userShow': 'first',
21 'app.page.splash': 'first',
22 'app.page.statsShow': 'first',
23 'app.page.threadNew': 'first',
24 'app.page.threadShow': 'first',
25 'blob.sync.url': 'first'
26})
27
28exports.create = (api) => {
29 return nest('router.sync.routes', (sofar = []) => {
30 const pages = api.app.page
31 // route format: [ routeValidator, routeFunction ]
32
33 const routes = [
34 [ location => location.page === 'splash', pages.splash ],
35
36 // Blog pages
37 [ location => location.page === 'blogIndex', pages.blogIndex ],
38 [ location => location.page === 'blogNew', pages.blogNew ],
39 [ location => location.page === 'blogSearch', pages.blogSearch ],
40 [ location => location.page === 'blogShow', pages.blogShow ],
41 [ location => isMsg(location.key) && get(location, 'value.content.type') === 'blog', pages.blogShow ],
42 [ location => {
43 return isMsg(location.key) &&
44 get(location, 'value.content.type') === 'post' &&
45 !get(location, 'value.private') // treats public posts as 'blogs'
46 }, pages.blogShow ],
47
48 // Channel related pages
49 [ location => location.page === 'channelSubscriptions', pages.channelSubscriptions ],
50 [ location => location.page === 'channelShow', pages.channelShow ],
51 [ location => location.channel, pages.channelShow ],
52
53 // Stats / Notifications pages
54 [ location => location.page === 'statsShow', pages.statsShow ],
55 [ location => location.page === 'notifications', pages.notifications ],
56
57 // AddressBook pages
58 [ location => location.page === 'addressBook', pages.addressBook ],
59
60 // Private Thread pages
61 // [ location => location.page === 'threadNew' && location.channel, pages.threadNew ],
62 [ location => location.page === 'threadNew' && location.participants.every(isFeed), pages.threadNew ],
63 [ location => isMsg(location.key), pages.threadShow ],
64
65 // User pages
66 // [ location => location.page === 'userFind', pages.userFind ],
67 [ location => location.page === 'userEdit' && isFeed(location.feed), pages.userEdit ],
68 [ location => isFeed(location.feed), pages.userShow ],
69
70 // Settings page
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

Built with git-ssb-web