Commit 3a4d25efb5cc4deb27280b8d8c796052914bb64d
rewrite sdash as an sbot plugin
Ev Bogue committed on 1/12/2017, 1:16:40 AMParent: 318383db2d5f15f36928ea41e5158a5de1dd0973
Files changed
index.js | changed |
bin.js | added |
index.js | ||
---|---|---|
@@ -6,60 +6,68 @@ | ||
6 | 6 … | var md = require('ssb-markdown') |
7 | 7 … | |
8 | 8 … | var title = 'sdash' |
9 | 9 … | var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519' |
10 | -var viewerUrl = 'https://viewer.evbogue.com/' | |
10 … | +var viewerUrl = 'http://evbogue.com:8807/' | |
11 | 11 … | |
12 | 12 … | var liteURL = 'http://ssb.evbogue.com/' |
13 | 13 … | var opts = {"modern":true,} |
14 | 14 … | var lite; |
15 | 15 … | |
16 | -http.createServer(function (req, res){ | |
17 | - if (req.url === '/') { | |
18 | - client(function (err, sbot) { | |
19 | - pull( | |
20 | - sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), | |
21 | - pull.drain(function (data) { | |
22 | - post = data | |
23 | - gotPost() | |
24 | - }) | |
25 | - ) | |
26 | - }) | |
27 | - function gotPost() { | |
28 | - res.end( | |
29 | - h('html', | |
30 | - h('head', | |
31 | - h('title', title), | |
32 | - h('style', fs.readFileSync('style.css', 'utf8')) | |
33 | - ), | |
34 | - h('body', | |
35 | - h('div.msg', | |
36 | - h('script', {src: viewerUrl + encodeURI(post.key) + '.js'}) | |
16 … | +exports.name = 'viewer' | |
17 … | +exports.manifest = {} | |
18 … | +exports.version = require('./package').version | |
19 … | + | |
20 … | +exports.init = function (sbot, config) { | |
21 … | + | |
22 … | + http.createServer(function (req, res){ | |
23 … | + if (req.url === '/') { | |
24 … | + client(function (err, sbot) { | |
25 … | + pull( | |
26 … | + sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), | |
27 … | + pull.drain(function (data) { | |
28 … | + post = data | |
29 … | + gotPost() | |
30 … | + }) | |
31 … | + ) | |
32 … | + }) | |
33 … | + function gotPost() { | |
34 … | + res.end( | |
35 … | + h('html', | |
36 … | + h('head', | |
37 … | + h('title', title) | |
38 … | + // h('style', fs.readFileSync('style.css', 'utf8')) | |
39 … | + ), | |
40 … | + h('body', | |
41 … | + h('div.msg', | |
42 … | + h('script', {src: viewerUrl + encodeURI(post.key) + '.js'}) | |
43 … | + ) | |
37 | 44 … | ) |
38 | - ) | |
39 | - ).outerHTML) | |
45 … | + ).outerHTML) | |
46 … | + } | |
40 | 47 … | } |
41 | - } | |
42 | - if (req.url === '/invite/') { | |
43 | -client(function (err, sbot) { | |
44 | - sbot.invite.create(opts, function (err, invite) { | |
45 | - if(err) throw err | |
46 | - lite = invite | |
47 | - gotInvite() | |
48 … | + if (req.url === '/invite/') { | |
49 … | + client(function (err, sbot) { | |
50 … | + sbot.invite.create(opts, function (err, invite) { | |
51 … | + if(err) throw err | |
52 … | + lite = invite | |
53 … | + gotInvite() | |
54 … | + }) | |
48 | 55 … | }) |
49 | - }) | |
50 | - function gotInvite() { | |
51 | - res.end( | |
52 | - h('html', | |
53 | - h('head', | |
54 | - h('title', title), | |
55 | - h('style', fs.readFileSync('style.css', 'utf8')) | |
56 | - ), | |
57 | - h('body', | |
58 | - h('div.msg', | |
59 | - h('p', {innerHTML: '<a href="' + liteURL + '#' + lite + '" rel="nofollow" target="_blank">'+ liteURL + '#' + lite + '</a>'}) | |
56 … | + function gotInvite() { | |
57 … | + res.end( | |
58 … | + h('html', | |
59 … | + h('head', | |
60 … | + h('title', title), | |
61 … | + h('style', fs.readFileSync('./style.css', 'utf8')) | |
62 … | + ), | |
63 … | + h('body', | |
64 … | + h('div.msg', | |
65 … | + h('p', {innerHTML: '<a href="' + liteURL + '#' + lite + '" rel="nofollow" target="_blank">'+ liteURL + '#' + lite + '</a>'}) | |
66 … | + ) | |
60 | 67 … | ) |
61 | - ) | |
62 | - ).outerHTML) | |
68 … | + ).outerHTML) | |
69 … | + } | |
63 | 70 … | } |
64 | - } | |
65 | -}).listen(1337) | |
71 … | + }).listen(1337) | |
72 … | + | |
73 … | +} |
Built with git-ssb-web