git ssb

3+

ev / sdash



Tree: ebd41b26e5d433b1e3663e427faed20e23e6615d

Files: ebd41b26e5d433b1e3663e427faed20e23e6615d / index.js

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

Built with git-ssb-web