Files: 087d12afcf79295f91dca741ce00c7c3ec26f6a5 / index.js
4956 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 | var avatar = require('ssb-avatar') |
8 | var mo = require('moment') |
9 | var ref = require('ssb-ref') |
10 | |
11 | var title = 'sdash' |
12 | var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519' |
13 | var desc = 'This is <a href="https://gitmx.com/%25qrU04j9vfUJKfq1rGZrQ5ihtSfA4ilfY3wLy7xFv0xk%3D.sha256">sdash</a>, a work-in-progress personal gateway to the <a href="http://ssbc.github.io">scuttlebot</a> distributed social network.' |
14 | var bloburl = 'http://localhost:8989/blobs/get/' |
15 | |
16 | var loc = 'The World' |
17 | var email = 'No email' |
18 | |
19 | var pin = 'No pinned message, yet' |
20 | |
21 | client(function (err, sbot) { |
22 | pull( |
23 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'email'}}}}], limit: 1, reverse: true}), |
24 | pull.drain(function (data) { |
25 | email = data.value.content.email |
26 | }) |
27 | ) |
28 | pull( |
29 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'location'}}}}], limit: 1, reverse: true}), |
30 | pull.drain(function (data) { |
31 | loc = data.value.content.location |
32 | }) |
33 | ) |
34 | }) |
35 | |
36 | http.createServer(function (req, res){ |
37 | if (req.url === '/') { |
38 | client(function (err, sbot) { |
39 | avatar(sbot, me, me, function (err, avatar){ |
40 | if (err) throw err |
41 | name = avatar.name |
42 | image = avatar.image |
43 | }) |
44 | pull( |
45 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), |
46 | pull.drain(function (data) { |
47 | post = data |
48 | }) |
49 | ) |
50 | pull( |
51 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'pin'}}}}], limit: 1, reverse: true}), |
52 | pull.drain(function (data) { |
53 | getpin = data |
54 | pull( |
55 | sbot.query.read({query: [{$filter: { key: getpin.value.content.link}}]}), |
56 | pull.drain(function (data) { |
57 | pinned = data |
58 | }) |
59 | ) |
60 | }) |
61 | ) |
62 | pull( |
63 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}), |
64 | pull.drain(function (data) { |
65 | vote = data |
66 | pull( |
67 | sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}), |
68 | pull.drain(function (data) { |
69 | avatar(sbot, me, data.value.author, function (err, avatar){ |
70 | if (err) throw err |
71 | reauthor = avatar |
72 | gotPost() |
73 | }) |
74 | redo = data |
75 | }) |
76 | ) |
77 | }) |
78 | ) |
79 | }) |
80 | function gotPost() { |
81 | res.end( |
82 | h('html', |
83 | h('head', |
84 | h('title', name + '\'s ' + title), |
85 | h('style', fs.readFileSync('style.css', 'utf8')) |
86 | ), |
87 | h('body', |
88 | h('div.ad', |
89 | h('p', {innerHTML: '<a href="https://evbogue.com/liteclient.png"><img src="https://evbogue.com/liteclient.png" style="margin-bottom: 1em; width: 100%;"></a>Get a lite client invite.<br />Email <a href="mailto:ev@evbogue.com">ev@evbogue.com</a>'}) |
90 | ), |
91 | h('img.profile', {src: bloburl + image}), |
92 | h('h1', |
93 | h('a', {href: me }, '@' + name) |
94 | ), |
95 | h('p', loc + ' | ', |
96 | h('a', {href: 'mailto:' + email}, email) |
97 | ), |
98 | h('p', {innerHTML: '<a href="/node">Minimal Node</a> | <a href="/minimalist">The Art of Being Minimalist</a>'}), |
99 | h('p', {innerHTML: desc}), |
100 | h('hr'), |
101 | h('div.msg', |
102 | h('p.small.ri', 'pinned'), |
103 | h('img.avatar', {src: bloburl + image}), |
104 | h('a', {href: me }, '@' + name), |
105 | h('div', {innerHTML: md.block(pinned.value.content.text)}, |
106 | h('span.date', mo(pinned.value.timestamp).fromNow()) |
107 | ) |
108 | ), |
109 | h('div.msg', |
110 | h('p.small.ri', 'post'), |
111 | h('img.avatar', {src: bloburl + image}), |
112 | h('a', {href: me }, '@' + name), |
113 | h('div', {innerHTML: md.block(post.value.content.text)}, |
114 | h('span.date', mo(post.value.timestamp).fromNow()) |
115 | ) |
116 | ), |
117 | h('div.msg', |
118 | h('p.small.ri', 'dig'), |
119 | h('img.avatar', {src: bloburl + image}), |
120 | h('a', {href: me }, '@' + name), ' dug ', |
121 | h('a', {href: vote.value.content.vote.link}, redo.value.content.text.substring(0, 40)), '...', |
122 | h('p.date', mo(vote.value.timestamp).fromNow()), |
123 | h('div.msg', |
124 | h('img.avatar', {src: bloburl + reauthor.image}), |
125 | h('a', {href: reauthor.name }, '@' + reauthor.name), |
126 | h('div', {innerHTML: md.block(redo.value.content.text)}, |
127 | h('span.date', mo(redo.value.timestamp).fromNow()) |
128 | ) |
129 | ) |
130 | ) |
131 | ) |
132 | ).outerHTML) |
133 | } |
134 | } |
135 | }).listen(1337) |
136 |
Built with git-ssb-web