git ssb

3+

ev / sdash



Tree: 673f1c3e0d3f41220ad06d849135a029dd6aa8cc

Files: 673f1c3e0d3f41220ad06d849135a029dd6aa8cc / index.js

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

Built with git-ssb-web