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