Files: 9b70108d00646124112662ec83dd9733d7afca7d / router / sync / routes.js
2941 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.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.threadNew': 'first', |
24 | 'app.page.threadShow': 'first', |
25 | // 'app.page.image': 'first', |
26 | 'blob.sync.url': 'first', |
27 | }) |
28 | |
29 | exports.create = (api) => { |
30 | return nest('router.sync.routes', (sofar = []) => { |
31 | const pages = api.app.page |
32 | // route format: [ routeValidator, routeFunction ] |
33 | |
34 | const routes = [ |
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 | // 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