Files: e67c359723b2674f987c9d40341928018278c907 / index.js
1675 bytesRaw
1 | var http = require('http') |
2 | var fs = require('fs') |
3 | var h = require('hyperscript') |
4 | var pull = require('pull-stream') |
5 | var client = require('ssb-client') |
6 | var md = require('ssb-markdown') |
7 | |
8 | var title = 'sdash' |
9 | var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519' |
10 | var viewerUrl = 'https://viewer.evbogue.com/' |
11 | |
12 | var liteURL = 'http://ssb.evbogue.com/' |
13 | var opts = {"modern":true,} |
14 | var lite; |
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'}) |
37 | ) |
38 | ) |
39 | ).outerHTML) |
40 | } |
41 | } |
42 | if (req.url === '/invite' || '/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 | }) |
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 + '">'+ liteURL + '#' + lite + '</a>'}) |
60 | ) |
61 | ) |
62 | ).outerHTML) |
63 | } |
64 | } |
65 | }).listen(1337) |
66 |
Built with git-ssb-web