Files: 9d0f7ad52dc88437b99e163851998485d945b520 / index.js
5256 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 = 'gwen bell' |
12 | var me = '@ya/sq19NPxRza5xtoqi9BilwLZ7HgQjG3QpcTRnGgWs=.ed25519' |
13 | var desc = 'What if you owned and operated - to the degree that one owns anything - the database to which you publish? Yeah, it is now possible.' |
14 | var bloburl = 'https://gwenbell.com/ws/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 | pull( |
35 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'website'}}}}], limit: 1, reverse: true}), |
36 | pull.drain(function (data) { |
37 | website = data.value.content.website |
38 | }) |
39 | ) |
40 | }) |
41 | |
42 | http.createServer(function (req, res){ |
43 | if (req.url === '/') { |
44 | client(function (err, sbot) { |
45 | avatar(sbot, me, me, function (err, avatar){ |
46 | if (err) throw err |
47 | name = avatar.name |
48 | image = avatar.image |
49 | }) |
50 | pull( |
51 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), |
52 | pull.drain(function (data) { |
53 | post = data |
54 | }) |
55 | ) |
56 | pull( |
57 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'pin'}}}}], limit: 1, reverse: true}), |
58 | pull.drain(function (data) { |
59 | getpin = data |
60 | pull( |
61 | sbot.query.read({query: [{$filter: { key: getpin.value.content.link}}]}), |
62 | pull.drain(function (data) { |
63 | pinned = data |
64 | }) |
65 | ) |
66 | }) |
67 | ) |
68 | pull( |
69 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}), |
70 | pull.drain(function (data) { |
71 | vote = data |
72 | pull( |
73 | sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}), |
74 | pull.drain(function (data) { |
75 | avatar(sbot, me, data.value.author, function (err, avatar){ |
76 | if (err) throw err |
77 | reauthor = avatar |
78 | gotPost() |
79 | }) |
80 | redo = data |
81 | }) |
82 | ) |
83 | }) |
84 | ) |
85 | pull( |
86 | sbot.query.read({query: [{$filter: { value: { content: {mentions: [{link: me}]}}}}], limit: 1, reverse: true}), |
87 | pull.drain(function (data) { |
88 | avatar(sbot, me, data.value.author, function (err, avatar){ |
89 | if (err) throw err |
90 | mentionauthor = avatar |
91 | }) |
92 | mention = data |
93 | }) |
94 | ) |
95 | pull( |
96 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'git-update'}}}}], limit: 1, reverse: true}), |
97 | pull.drain(function (data) { |
98 | gits = data |
99 | }) |
100 | ) |
101 | |
102 | }) |
103 | function gotPost() { |
104 | res.end( |
105 | h('html', |
106 | h('head', |
107 | h('title', title), |
108 | h('style', fs.readFileSync('style.css', 'utf8')) |
109 | ), |
110 | h('body', |
111 | h('img.profile', {src: bloburl + image}), |
112 | h('h1', |
113 | h('a', {href: me }, '@' + name) |
114 | ), |
115 | h('p', loc + ' | ', |
116 | h('a', {href: 'mailto:' + email}, email) |
117 | ), |
118 | h('p', {innerHTML: desc}), |
119 | h('hr'), |
120 | h('div.msg', |
121 | h('p.small.ri', 'pinned'), |
122 | h('img.avatar', {src: bloburl + image}), |
123 | h('a', {href: me }, '@' + name), |
124 | h('div', {innerHTML: md.block(pinned.value.content.text)}, |
125 | h('span.date', mo(pinned.value.timestamp).fromNow()) |
126 | ) |
127 | ), |
128 | h('div.msg', |
129 | h('p.small.ri', 'post'), |
130 | h('img.avatar', {src: bloburl + image}), |
131 | h('a', {href: me }, '@' + name), |
132 | h('div', {innerHTML: md.block(post.value.content.text)}, |
133 | h('span.date', mo(post.value.timestamp).fromNow()) |
134 | ) |
135 | ), |
136 | h('div.msg', |
137 | h('p.small.ri', 'dig'), |
138 | h('img.avatar', {src: bloburl + image}), |
139 | h('a', {href: me }, '@' + name), ' dug ', |
140 | h('a', {href: vote.value.content.vote.link}, redo.value.content.text.substring(0, 40)), '...', |
141 | h('p.date', mo(vote.value.timestamp).fromNow()), |
142 | h('div.msg', |
143 | h('img.avatar', {src: bloburl + reauthor.image}), |
144 | h('a', {href: reauthor.name }, '@' + reauthor.name), |
145 | h('div', {innerHTML: md.block(redo.value.content.text)}, |
146 | h('span.date', mo(redo.value.timestamp).fromNow()) |
147 | ) |
148 | ) |
149 | ) |
150 | ) |
151 | ).outerHTML) |
152 | } |
153 | } |
154 | }).listen(1337) |
155 |
Built with git-ssb-web