git ssb

3+

ev / sdash



Tree: f764460e75e9d5babcd1180c26c9ac5ba849ac2d

Files: f764460e75e9d5babcd1180c26c9ac5ba849ac2d / index.js

3332 bytesRaw
1var express = require('express');
2var pull = require('pull-stream');
3var client = require('ssb-client');
4var avatar = require('ssb-avatar');
5var markdown = require('marked');
6var favicon = require('serve-favicon');
7var moment = require('moment');
8
9var me = '@EMovhfIrFk4NihAKnRNhrfRaqIhBv1Wj8pTxJNgvCCY=.ed25519';
10
11var pin = '%6ogHrwUivc2Tn3nq87vepXfPDLMWIiEIu0rqGPl0Kkg=.sha256';
12
13var bloburl = 'http://localhost:8989/blobs/get/';
14
15var app = express();
16
17app.set('views', './layouts')
18app.set('view engine', 'jade');
19
20app.use(express.static('static'));
21app.use(favicon(__dirname + '/static/favicon.ico'));
22
23app.get('/:key', function (req, res) {
24 client(function (err, sbot) {
25 if (err) {
26 throw err;
27 }
28 avatar(sbot, me, req.params.key, function (err, avatar){
29 if (err) {
30 throw err;
31 }
32 key = req.params.key;
33 pull(
34 sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'post'}}}}], limit: 1, reverse: true}),
35 pull.drain(function (data) {
36 post = data;
37 })
38 )
39 res.render('profile', {avatar, bloburl, key, markdown, moment});
40 })
41 })
42});
43
44
45app.get('/:key([^/]+/[^/]+)', function (req, res) {
46 client(function (err, sbot) {
47 if (err) {
48 throw err;
49 }
50 avatar(sbot, me, req.params.key, function (err, avatar){
51 if (err) {
52 throw err;
53 }
54 key = req.params.key;
55 pull(
56 sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'post'}}}}], limit: 1, reverse: true}),
57 pull.drain(function (data) {
58 post = data;
59 })
60 )
61 res.render('profile', {avatar, bloburl, key, markdown, moment});
62 })
63 })
64});
65
66app.get('/', function (req, res) {
67 client(function (err, sbot) {
68 if (err) {
69 throw err;
70 }
71 avatar(sbot, me, me, function (err, avatar){
72 if (err) {
73 throw err;
74 }
75 name = avatar.name;
76 image = avatar.image;
77 })
78 pull(
79 sbot.query.read({query: [{$filter: { key: pin}}], limit: 1, reverse: true}),
80 pull.drain(function (data) {
81 pinned = data;
82 })
83 )
84 pull(
85 sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}),
86 pull.drain(function (data) {
87 post = data;
88 })
89 )
90 pull(
91 sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}),
92 pull.drain(function (data) {
93 vote = data;
94 pull(
95 sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}),
96 pull.drain(function (reblog) {
97 avatar(sbot, me, reblog.value.author, function (err, avatar){
98 if (err) {
99 throw err;
100 }
101 reauthor = avatar;
102 gotPost();
103 })
104 redo = reblog;
105 })
106 )
107 })
108 )
109 pull(
110 sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'git-update'}}}}], limit: 1, reverse: true}),
111 pull.drain(function (data) {
112 gits = data;
113 })
114 )
115 });
116 function gotPost() {
117 res.render('index', { title: 'Evbogue.com', markdown, moment, bloburl});
118 }
119});
120
121
122app.listen('7000');
123
124
125

Built with git-ssb-web