Files: dfa8dcc1b8dc80fea753df44f2c9faa9c5eb88ef / router / sync / routes.js
2970 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.blogIndex': 'first', |
11 | 'app.page.blogNew': 'first', |
12 | 'app.page.blogShow': 'first', |
13 | 'app.page.settings': 'first', |
14 | // 'app.page.channel': 'first', |
15 | // 'app.page.groupFind': 'first', |
16 | // 'app.page.groupIndex': 'first', |
17 | // 'app.page.groupNew': 'first', |
18 | // 'app.page.groupShow': 'first', |
19 | 'app.page.userEdit': 'first', |
20 | // 'app.page.userFind': 'first', |
21 | 'app.page.userShow': 'first', |
22 | 'app.page.threadNew': 'first', |
23 | 'app.page.threadShow': 'first', |
24 | // 'app.page.image': 'first', |
25 | 'blob.sync.url': 'first', |
26 | }) |
27 | |
28 | exports.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 | |
35 | // Blog pages |
36 | [ location => location.page === 'home', pages.blogIndex ], |
37 | [ location => location.page === 'discovery', pages.blogIndex ], |
38 | [ location => location.page === 'blogIndex', pages.blogIndex ], |
39 | [ location => location.page === 'blogNew', pages.blogNew ], |
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 | // Private Thread pages |
49 | // [ location => location.page === 'threadNew' && location.channel, pages.threadNew ], |
50 | [ location => location.page === 'threadNew' && isFeed(location.feed), pages.threadNew ], |
51 | [ location => isMsg(location.key), pages.threadShow ], |
52 | |
53 | // User pages |
54 | // [ location => location.page === 'userFind', pages.userFind ], |
55 | [ location => location.page === 'userEdit' && isFeed(location.feed), pages.userEdit ], |
56 | [ location => isFeed(location.feed), pages.userShow ], |
57 | |
58 | // Group pages |
59 | // [ location => location.page === 'groupFind', pages.groupFind ], |
60 | // [ location => location.page === 'groupIndex', pages.groupIndex ], |
61 | // [ location => location.page === 'groupNew', pages.groupNew ], |
62 | // // [ location => location.type === 'groupShow' && isMsg(location.key), pages.groupShow ], |
63 | // [ location => location.channel , pages.channel ], |
64 | |
65 | [ location => location.page === 'settings', pages.settings ], |
66 | |
67 | // [ location => isBlob(location.blob), pages.image ], |
68 | [ location => isBlob(location.blob), (location) => { |
69 | openExternal(api.blob.sync.url(location.blob)) |
70 | }], |
71 | |
72 | // Error page |
73 | [ location => true, pages.error ] |
74 | ] |
75 | |
76 | return [...routes, ...sofar] |
77 | }) |
78 | } |
79 | |
80 |
Built with git-ssb-web