Files: a096997010493803cf4bb08f12a5f112e9bd24d7 / index.js
5739 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 | client(function (err, sbot) { |
17 | pull( |
18 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'email'}}}}], limit: 1, reverse: true}), |
19 | pull.drain(function (data) { |
20 | email = data.value.content.email; |
21 | }) |
22 | ) |
23 | pull( |
24 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'location'}}}}], limit: 1, reverse: true}), |
25 | pull.drain(function (data) { |
26 | loc = data.value.content.location; |
27 | }) |
28 | ) |
29 | pull( |
30 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'website'}}}}], limit: 1, reverse: true}), |
31 | pull.drain(function (data) { |
32 | website = data.value.content.website; |
33 | }) |
34 | ) |
35 | }) |
36 | |
37 | http.createServer(function (req, res){ |
38 | if (req.url === '/') { |
39 | client(function (err, sbot) { |
40 | avatar(sbot, me, me, function (err, avatar){ |
41 | if (err) throw err |
42 | name = avatar.name; |
43 | image = avatar.image; |
44 | }) |
45 | pull( |
46 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), |
47 | pull.drain(function (data) { |
48 | post = data |
49 | }) |
50 | ) |
51 | pull( |
52 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'pin'}}}}], limit: 1, reverse: true}), |
53 | pull.drain(function (data) { |
54 | getpin = data; |
55 | pull( |
56 | sbot.query.read({query: [{$filter: { key: getpin.value.content.link}}]}), |
57 | pull.drain(function (data) { |
58 | pinned = data; |
59 | }) |
60 | ) |
61 | }) |
62 | ) |
63 | pull( |
64 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}), |
65 | pull.drain(function (data) { |
66 | vote = data; |
67 | pull( |
68 | sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}), |
69 | pull.drain(function (data) { |
70 | avatar(sbot, me, data.value.author, function (err, avatar){ |
71 | if (err) { |
72 | throw err; |
73 | } |
74 | reauthor = avatar; |
75 | gotPost() |
76 | }) |
77 | redo = data; |
78 | }) |
79 | ) |
80 | }) |
81 | ) |
82 | pull( |
83 | sbot.query.read({query: [{$filter: { value: { content: {mentions: [{link: me}]}}}}], limit: 1, reverse: true}), |
84 | pull.drain(function (data) { |
85 | avatar(sbot, me, data.value.author, function (err, avatar){ |
86 | if (err) throw err |
87 | mentionauthor = avatar |
88 | }) |
89 | mention = data |
90 | }) |
91 | ) |
92 | pull( |
93 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'git-update'}}}}], limit: 1, reverse: true}), |
94 | pull.drain(function (data) { |
95 | gits = data |
96 | }) |
97 | ) |
98 | |
99 | }) |
100 | function gotPost() { |
101 | res.end( |
102 | h('html', |
103 | h('head', |
104 | h('title', title), |
105 | h('style', fs.readFileSync('style.css', 'utf8')) |
106 | ), |
107 | h('body', |
108 | h('img.profile', {src: bloburl + image}), |
109 | h('h1', |
110 | h('a', {href: me }, '@' + name) |
111 | ), |
112 | h('p', loc + ' | ', |
113 | h('a', {href: 'mailto:' + email}, email) |
114 | ), |
115 | h('p', {innerHTML: '<a href="/node">Minimal Node</a> | <a href="/minimalist">The Art of Being Minimalist</a>'}), |
116 | h('p', {innerHTML: desc}), |
117 | h('hr'), |
118 | h('div.msg', |
119 | h('p.small.ri', 'pinned'), |
120 | h('img.avatar', {src: bloburl + image}), |
121 | h('a', {href: me }, '@' + name), |
122 | h('div', {innerHTML: md.block(pinned.value.content.text)}, |
123 | h('span.date', mo(pinned.value.timestamp).fromNow()) |
124 | ) |
125 | ), |
126 | h('div.msg', |
127 | h('p.small.ri', 'post'), |
128 | h('img.avatar', {src: bloburl + image}), |
129 | h('a', {href: me }, '@' + name), |
130 | h('div', {innerHTML: md.block(post.value.content.text)}, |
131 | h('span.date', mo(post.value.timestamp).fromNow()) |
132 | ) |
133 | ), |
134 | h('div.msg', |
135 | h('p.small.ri', 'dig'), |
136 | h('img.avatar', {src: bloburl + image}), |
137 | h('a', {href: me }, '@' + name), ' dug ', |
138 | h('div', vote.value.content.vote.link, |
139 | h('p.date', mo(vote.value.timestamp).fromNow()), |
140 | h('div.msg', |
141 | h('img.avatar', {src: bloburl + reauthor.image}), |
142 | h('a', {href: reauthor.name }, '@' + name), |
143 | h('div', {innerHTML: md.block(redo.value.content.text)}, |
144 | h('span.date', mo(redo.value.timestamp).fromNow()) |
145 | ) |
146 | ) |
147 | ) |
148 | ), |
149 | h('div.msg', |
150 | h('p.small.ri', 'last mention'), |
151 | h('img.avatar', {src: bloburl + mentionauthor.image}), |
152 | h('a', {href: me }, '@' + mentionauthor.name), |
153 | h('div', {innerHTML: md.block(mention.value.content.text)}, |
154 | h('span.date', mo(mention.value.timestamp).fromNow()) |
155 | ) |
156 | ) |
157 | |
158 | ) |
159 | ).outerHTML) |
160 | } |
161 | } |
162 | }).listen(1337) |
163 |
Built with git-ssb-web