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 = '@EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519'; var pin = '%6ogHrwUivc2Tn3nq87vepXfPDLMWIiEIu0rqGPl0Kkg=.sha256'; 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) { console.log(req.params); 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: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), pull.drain(function (data) { post = data; console.log(data) }) ) res.render('profile', {avatar, bloburl, key}); }) }) }); app.get('/:key([^/]+/[^/]+)', function (req, res) { console.log(req.params); 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; res.render('profile', {avatar, bloburl, key}); }) }) }); 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: { key: pin}}], limit: 1, reverse: true}), 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');