var express = require('express'); var pull = require('pull-stream'); var client = require('ssb-client'); var avatar = require('ssb-avatar'); var markdown = require('marked'); var favicon = require('serve-favicon'); var moment = require('moment'); var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519'; var bloburl = 'http://localhost:8989/blobs/get/'; var app = express(); app.set('views', './layouts') app.set('view engine', 'jade'); app.use(express.static('static')); app.use(favicon(__dirname + '/static/favicon.ico')); app.get('/:key', function (req, res) { client(function (err, sbot) { if (err) { throw err; } avatar(sbot, me, req.params.key, function (err, avatar){ if (err) { throw err; } key = req.params.key; pull( sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'post'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { post = data; gotPost() }) ) function gotPost() { res.render('profile', {avatar, bloburl, key, markdown, moment}); } }) }) }); app.get('/', function (req, res) { client(function (err, sbot) { if (err) { throw err; } 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: '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: 'post'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { post = 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 (reblog) { avatar(sbot, me, reblog.value.author, function (err, avatar){ if (err) { throw err; } reauthor = avatar; gotPost(); }) redo = reblog; }) ) }) ) pull( sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'git-update'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { gits = data; }) ) }); function gotPost() { res.render('index', { title: 'Evbogue.com', markdown, moment, bloburl}); } }); app.listen('7000');