Files: 32b48f9b3bd44dcb3bb24b0d9cea7a213f409121 / index.js
2959 bytesRaw
1 | var express = require('express'); |
2 | var avatar = require('ssb-avatar'); |
3 | var client = require('ssb-client'); |
4 | var pull = require('pull-stream'); |
5 | var moment = require('moment'); |
6 | var markdown = require('marked'); |
7 | var nm = require('nodemailer'); |
8 | var bodyParser = require('body-parser'); |
9 | |
10 | var app = express(); |
11 | app.set('view engine', 'jade'); |
12 | app.set('views', './layouts'); |
13 | |
14 | app.use(bodyParser.json()); |
15 | app.use(bodyParser.urlencoded({extended: true})); |
16 | |
17 | const me = '@ya/sq19NPxRza5xtoqi9BilwLZ7HgQjG3QpcTRnGgWs=.ed25519' |
18 | const site = 'Gwen Bell'; |
19 | |
20 | app.get('/', function (req, res) { |
21 | client(function (err, sbot) { |
22 | if (err) { |
23 | throw err; |
24 | } |
25 | avatar(sbot, me, me, function (err, avatar){ |
26 | if (err) { |
27 | throw err; |
28 | } |
29 | name = avatar.name; |
30 | image = avatar.image; |
31 | }) |
32 | |
33 | pull( |
34 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'pin'}}}}], limit: 1, reverse: true}), |
35 | pull.drain(function (data) { |
36 | getpin = data; |
37 | pull( |
38 | sbot.query.read({query: [{$filter: { key: getpin.value.content.link}}]}), |
39 | pull.drain(function (data){ |
40 | pinned = data; |
41 | }) |
42 | ) |
43 | }) |
44 | ) |
45 | pull( |
46 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), |
47 | pull.drain(function (data) { |
48 | post = data; |
49 | }) |
50 | ) |
51 | pull( |
52 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}), |
53 | pull.drain(function (data) { |
54 | vote = data; |
55 | pull( |
56 | sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}), |
57 | pull.drain(function (reblog) { |
58 | avatar(sbot, me, reblog.value.author, function (err, avatar){ |
59 | if (err) { |
60 | throw err; |
61 | } |
62 | reauthor = avatar; |
63 | gotPost(); |
64 | }) |
65 | redo = reblog; |
66 | }) |
67 | ) |
68 | }) |
69 | ) |
70 | pull( |
71 | sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'git-update'}}}}], limit: 1, reverse: true}), |
72 | pull.drain(function (data) { |
73 | gits = data; |
74 | }) |
75 | ) |
76 | }); |
77 | function gotPost() { |
78 | res.render('index', { title: site, markdown, moment}); |
79 | } |
80 | }); |
81 | |
82 | app.post('/send', function (req, res) { |
83 | var name = req.body.nombre; |
84 | var email = req.body.elmail; |
85 | var website = req.body.siteurl; |
86 | var date = moment().format('MMMM D, YYYY'); |
87 | var str = name + " <" + email + "> " + website + " - " + date; |
88 | |
89 | var transporter = nm.createTransport(); |
90 | |
91 | transporter.sendMail({ |
92 | from: email, |
93 | to: 'gwen@gwenbell.com', |
94 | subject: 'New signup!', |
95 | text: str |
96 | }); |
97 | res.redirect('http://gwenbell.com/'); |
98 | }); |
99 | |
100 | app.use(express.static('./../books/build')) |
101 | app.use(express.static('/static/reserva')) |
102 | app.use(express.static('build')) |
103 | |
104 | app.listen(2525); |
105 | console.log('Listening at http://localhost:2525/'); |
106 |
Built with git-ssb-web