git ssb

3+

ev / sdash



Tree: 01053b673e3260508b20dae5df0bd3c7e1e23c3b

Files: 01053b673e3260508b20dae5df0bd3c7e1e23c3b / index.js

5419 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('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: '<a href="/node">Minimal Node</a> | <a href="/minimalist">The Art of Being Minimalist</a>'}),
119 h('p', {innerHTML: desc}),
120 h('hr'),
121 h('div.msg',
122 h('p.small.ri', 'pinned'),
123 h('img.avatar', {src: bloburl + image}),
124 h('a', {href: me }, '@' + name),
125 h('div', {innerHTML: md.block(pinned.value.content.text)},
126 h('span.date', mo(pinned.value.timestamp).fromNow())
127 )
128 ),
129 h('div.msg',
130 h('p.small.ri', 'post'),
131 h('img.avatar', {src: bloburl + image}),
132 h('a', {href: me }, '@' + name),
133 h('div', {innerHTML: md.block(post.value.content.text)},
134 h('span.date', mo(post.value.timestamp).fromNow())
135 )
136 ),
137 h('div.msg',
138 h('p.small.ri', 'dig'),
139 h('img.avatar', {src: bloburl + image}),
140 h('a', {href: me }, '@' + name), ' dug ',
141 h('div', vote.value.content.vote.link,
142 h('p.date', mo(vote.value.timestamp).fromNow()),
143 h('div.msg',
144 h('img.avatar', {src: bloburl + reauthor.image}),
145 h('a', {href: reauthor.name }, '@' + reauthor.name),
146 h('div', {innerHTML: md.block(redo.value.content.text)},
147 h('span.date', mo(redo.value.timestamp).fromNow())
148 )
149 )
150 )
151 )
152 )
153 ).outerHTML)
154 }
155 }
156}).listen(1337)
157

Built with git-ssb-web