git ssb

2+

mixmix / ticktack



Tree: f53d4720c0fe90f6e4f8f94d0f986812e6ca896b

Files: f53d4720c0fe90f6e4f8f94d0f986812e6ca896b / router / sync / routes.js

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

Built with git-ssb-web