var http = require('http') var fs = require('fs') var h = require('hyperscript') var pull = require('pull-stream') var client = require('ssb-client') var md = require('ssb-markdown') var avatar = require('ssb-avatar') var mo = require('moment') var ref = require('ssb-ref') var title = 'sdash' var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519' var desc = 'This is sdash, a work-in-progress personal gateway to the scuttlebot distributed social network.' var bloburl = 'http://localhost:8989/blobs/get/' var loc = 'The World' var email = 'No email' var pin = 'No pinned message, yet' client(function (err, sbot) { pull( sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'email'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { email = data.value.content.email }) ) pull( sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'location'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { loc = data.value.content.location }) ) }) http.createServer(function (req, res){ if (req.url === '/') { client(function (err, sbot) { avatar(sbot, me, me, function (err, avatar){ if (err) throw err name = avatar.name image = avatar.image }) pull( sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { post = data }) ) pull( sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'pin'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { getpin = data pull( sbot.query.read({query: [{$filter: { key: getpin.value.content.link}}]}), pull.drain(function (data) { pinned = data }) ) }) ) pull( sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { vote = data pull( sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}), pull.drain(function (data) { avatar(sbot, me, data.value.author, function (err, avatar){ if (err) throw err reauthor = avatar gotPost() }) redo = data }) ) }) ) }) function gotPost() { res.end( h('html', h('head', h('title', name + '\'s ' + title), h('style', fs.readFileSync('style.css', 'utf8')) ), h('body', h('div.ad', h('p', {innerHTML: 'Get a lite client invite.
Email ev@evbogue.com'}) ), h('img.profile', {src: bloburl + image}), h('h1', h('a', {href: me }, '@' + name) ), h('p', loc + ' | ', h('a', {href: 'mailto:' + email}, email) ), h('p', {innerHTML: 'Minimal Node | The Art of Being Minimalist'}), h('p', {innerHTML: desc}), h('hr'), h('div.msg', h('p.small.ri', 'pinned'), h('img.avatar', {src: bloburl + image}), h('a', {href: me }, '@' + name), h('div', {innerHTML: md.block(pinned.value.content.text)}, h('span.date', mo(pinned.value.timestamp).fromNow()) ) ), h('div.msg', h('p.small.ri', 'post'), h('img.avatar', {src: bloburl + image}), h('a', {href: me }, '@' + name), h('div', {innerHTML: md.block(post.value.content.text)}, h('span.date', mo(post.value.timestamp).fromNow()) ) ), h('div.msg', h('p.small.ri', 'dig'), h('img.avatar', {src: bloburl + image}), h('a', {href: me }, '@' + name), ' dug ', h('a', {href: vote.value.content.vote.link}, redo.value.content.text.substring(0, 40)), '...', h('p.date', mo(vote.value.timestamp).fromNow()), h('div.msg', h('img.avatar', {src: bloburl + reauthor.image}), h('a', {href: reauthor.name }, '@' + reauthor.name), h('div', {innerHTML: md.block(redo.value.content.text)}, h('span.date', mo(redo.value.timestamp).fromNow()) ) ) ) ) ).outerHTML) } } }).listen(1337)