Files: 2812e21b2be7dcab1cc07911be4a52548041bd9a / index.js
5614 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: desc}), |
116 | h('hr'), |
117 | h('div.msg', |
118 | h('p.small.ri', 'pinned'), |
119 | h('img.avatar', {src: bloburl + image}), |
120 | h('a', {href: me }, '@' + name), |
121 | h('div', {innerHTML: md.block(pinned.value.content.text)}, |
122 | h('span.date', mo(pinned.value.timestamp).fromNow()) |
123 | ) |
124 | ), |
125 | h('div.msg', |
126 | h('p.small.ri', 'post'), |
127 | h('img.avatar', {src: bloburl + image}), |
128 | h('a', {href: me }, '@' + name), |
129 | h('div', {innerHTML: md.block(post.value.content.text)}, |
130 | h('span.date', mo(post.value.timestamp).fromNow()) |
131 | ) |
132 | ), |
133 | h('div.msg', |
134 | h('p.small.ri', 'dig'), |
135 | h('img.avatar', {src: bloburl + image}), |
136 | h('a', {href: me }, '@' + name), ' dug ', |
137 | h('div', vote.value.content.vote.link, |
138 | h('p.date', mo(vote.value.timestamp).fromNow()), |
139 | h('div.msg', |
140 | h('img.avatar', {src: bloburl + reauthor.image}), |
141 | h('a', {href: reauthor.name }, '@' + name), |
142 | h('div', {innerHTML: md.block(redo.value.content.text)}, |
143 | h('span.date', mo(redo.value.timestamp).fromNow()) |
144 | ) |
145 | ) |
146 | ) |
147 | ), |
148 | h('div.msg', |
149 | h('p.small.ri', 'last mention'), |
150 | h('img.avatar', {src: bloburl + mentionauthor.image}), |
151 | h('a', {href: me }, '@' + mentionauthor.name), |
152 | h('div', {innerHTML: md.block(mention.value.content.text)}, |
153 | h('span.date', mo(mention.value.timestamp).fromNow()) |
154 | ) |
155 | ) |
156 | |
157 | ) |
158 | ).outerHTML) |
159 | } |
160 | } |
161 | }).listen(1337) |
162 |
Built with git-ssb-web