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