git ssb

3+

ev / sdash



Tree: 93111b0067bd271cf647b5e5e459f1f75ee6fc54

Files: 93111b0067bd271cf647b5e5e459f1f75ee6fc54 / index.js

5757 bytesRaw
1var http = require('http')
2var fs = require('fs')
3var h = require('hyperscript')
4var pull = require('pull-stream')
5var client = require('ssb-client')
6var md = require('ssb-markdown')
7var avatar = require('ssb-avatar')
8var mo = require('moment')
9var ref = require('ssb-ref')
10
11var title = 'sdash'
12var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519'
13var 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.'
14var bloburl = 'http://localhost:8989/blobs/get/'
15
16var loc = 'The World'
17var email = 'No email'
18
19var pin = 'No pinned message, yet'
20
21client(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
42http.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('div.ad',
112 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>'})
113 ),
114 h('img.profile', {src: bloburl + image}),
115 h('h1',
116 h('a', {href: me }, '@' + name)
117 ),
118 h('p', loc + ' | ',
119 h('a', {href: 'mailto:' + email}, email)
120 ),
121 h('p', {innerHTML: '<a href="/node">Minimal Node</a> | <a href="/minimalist">The Art of Being Minimalist</a>'}),
122 h('p', {innerHTML: desc}),
123 h('hr'),
124 h('div.msg',
125 h('p.small.ri', 'pinned'),
126 h('img.avatar', {src: bloburl + image}),
127 h('a', {href: me }, '@' + name),
128 h('div', {innerHTML: md.block(pinned.value.content.text)},
129 h('span.date', mo(pinned.value.timestamp).fromNow())
130 )
131 ),
132 h('div.msg',
133 h('p.small.ri', 'post'),
134 h('img.avatar', {src: bloburl + image}),
135 h('a', {href: me }, '@' + name),
136 h('div', {innerHTML: md.block(post.value.content.text)},
137 h('span.date', mo(post.value.timestamp).fromNow())
138 )
139 ),
140 h('div.msg',
141 h('p.small.ri', 'dig'),
142 h('img.avatar', {src: bloburl + image}),
143 h('a', {href: me }, '@' + name), ' dug ',
144 h('a', {href: vote.value.content.vote.link}, redo.value.content.text.substring(0, 40)), '...',
145 h('p.date', mo(vote.value.timestamp).fromNow()),
146 h('div.msg',
147 h('img.avatar', {src: bloburl + reauthor.image}),
148 h('a', {href: reauthor.name }, '@' + reauthor.name),
149 h('div', {innerHTML: md.block(redo.value.content.text)},
150 h('span.date', mo(redo.value.timestamp).fromNow())
151 )
152 )
153 )
154 )
155 ).outerHTML)
156 }
157 }
158}).listen(1337)
159

Built with git-ssb-web