index.jsView |
---|
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'); |
| 1 … | +var http = require('http') |
| 2 … | +var fs = require('fs') |
| 3 … | +var h = require('hyperscript') |
| 4 … | +var pull = require('pull-stream') |
| 5 … | +var client = require('ssb-client') |
| 6 … | +var md = require('ssb-markdown') |
| 7 … | +var avatar = require('ssb-avatar') |
| 8 … | +var mo = require('moment') |
8 | 9 … | |
9 | | -var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519'; |
| 10 … | +var title = 'sdash' |
| 11 … | +var me = '@8Qee0I/DwI5DHSCi3p5fsl6FyLGArrnDz3ox9qZr5Qc=.ed25519' |
| 12 … | +var desc = 'This is <a href="https://gitmx.com/%25qrU04j9vfUJKfq1rGZrQ5ihtSfA4ilfY3wLy7xFv0xk%3D.sha256">sdash</a>, a work-in-progress personal gateway to the <a href="http://ssbc.github.io">scuttlebot</a> distributed social network' |
| 13 … | +var bloburl = 'http://localhost:8989/blobs/get/' |
10 | 14 … | |
11 | | -var bloburl = 'http://localhost:8989/blobs/get/'; |
12 | 15 … | |
13 | | -var app = express(); |
14 | | - |
15 | | -app.set('views', './layouts') |
16 | | -app.set('view engine', 'jade'); |
17 | | - |
18 | | -app.use(express.static('static')); |
19 | | -app.use(favicon(__dirname + '/static/favicon.ico')); |
20 | | - |
21 | | -app.get('/:key', function (req, res) { |
22 | | - client(function (err, sbot) { |
23 | | - if (err) { |
24 | | - throw err; |
25 | | - } |
26 | | - avatar(sbot, me, req.params.key, function (err, avatar){ |
27 | | - if (err) { |
28 | | - throw err; |
29 | | - } |
30 | | - key = req.params.key; |
31 | | - pull( |
32 | | - sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'post'}}}}], limit: 1, reverse: true}), |
33 | | - pull.drain(function (data) { |
34 | | - post = data; |
35 | | - }) |
36 | | - ) |
37 | | - pull( |
38 | | - sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'tagline'}}}}], limit: 1, reverse: true}), |
39 | | - pull.drain(function (data) { |
40 | | - tagline = data; |
41 | | - console.log(tagline) |
42 | | - }) |
43 | | - ) |
44 | | - pull( |
45 | | - sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'location'}}}}], limit: 1, reverse: true}), |
46 | | - pull.drain(function (data) { |
47 | | - loc = data; |
48 | | - console.log(loc) |
49 | | - }) |
50 | | - ) |
51 | | - pull( |
52 | | - sbot.query.read({query: [{$filter: { value: { author: key, content: {type: 'website'}}}}], limit: 1, reverse: true}), |
53 | | - pull.drain(function (data) { |
54 | | - website = data; |
55 | | - console.log(website) |
56 | | - }) |
57 | | - ) |
58 | | - res.render('profile', {avatar, bloburl, key, markdown, moment}); |
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; |
| 16 … | +http.createServer(function (req, res){ |
| 17 … | + if (req.url === '/') { |
| 18 … | + client(function (err, sbot) { |
| 19 … | + avatar(sbot, me, me, function (err, avatar){ |
| 20 … | + if (err) { |
| 21 … | + throw err; |
| 22 … | + } |
| 23 … | + name = avatar.name; |
| 24 … | + image = avatar.image; |
| 25 … | + }) |
| 26 … | + pull( |
| 27 … | + sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), |
| 28 … | + pull.drain(function (data) { |
| 29 … | + post = data |
| 30 … | + }) |
| 31 … | + ) |
| 32 … | + pull( |
| 33 … | + sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'pin'}}}}], limit: 1, reverse: true}), |
| 34 … | + pull.drain(function (data) { |
| 35 … | + getpin = data; |
| 36 … | + pull( |
| 37 … | + sbot.query.read({query: [{$filter: { key: getpin.value.content.link}}]}), |
| 38 … | + pull.drain(function (data) { |
| 39 … | + pinned = data; |
| 40 … | + gotPost() |
| 41 … | + }) |
| 42 … | + ) |
| 43 … | + }) |
| 44 … | + ) |
| 45 … | + pull( |
| 46 … | + sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}), |
| 47 … | + pull.drain(function (data) { |
| 48 … | + vote = data; |
| 49 … | + pull( |
| 50 … | + sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}), |
| 51 … | + pull.drain(function (reblog) { |
| 52 … | + avatar(sbot, me, reblog.value.author, function (err, avatar){ |
| 53 … | + if (err) { |
| 54 … | + throw err; |
| 55 … | + } |
| 56 … | + reauthor = avatar; |
| 57 … | + }) |
| 58 … | + redo = reblog; |
| 59 … | + }) |
| 60 … | + ) |
| 61 … | + }) |
| 62 … | + ) |
| 63 … | + pull( |
| 64 … | + sbot.query.read({query: [{$filter: { value: { content: {mentions: [{link: me}]}}}}], limit: 1, reverse: true}), |
| 65 … | + pull.drain(function (data) { |
| 66 … | + mention = data |
| 67 … | + }) |
| 68 … | + ) |
| 69 … | + pull( |
| 70 … | + sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'git-update'}}}}], limit: 1, reverse: true}), |
| 71 … | + pull.drain(function (data) { |
| 72 … | + gits = data |
| 73 … | + }) |
| 74 … | + ) |
| 75 … | + |
74 | 76 … | }) |
75 | | - pull( |
76 | | - sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'pin'}}}}], limit: 1, reverse: true}), |
77 | | - pull.drain(function (data) { |
78 | | - getpin = data; |
79 | | - pull( |
80 | | - sbot.query.read({query: [{$filter: { key: getpin.value.content.link}}]}), |
81 | | - pull.drain(function (data) { |
82 | | - pinned = data; |
83 | | - }) |
| 77 … | + function gotPost() { |
| 78 … | + res.end( |
| 79 … | + h('html', |
| 80 … | + h('head', |
| 81 … | + h('title', title), |
| 82 … | + h('style', fs.readFileSync('style.css', 'utf8')) |
| 83 … | + ), |
| 84 … | + h('body', |
| 85 … | + h('img.profile', {src: bloburl + image}), |
| 86 … | + h('h1', |
| 87 … | + h('a', {href: me }, '@' + name) |
| 88 … | + ), |
| 89 … | + h('p', {innerHTML: desc}), |
| 90 … | + h('hr'), |
| 91 … | + h('div.msg', |
| 92 … | + h('p.small.ri', 'pinned'), |
| 93 … | + h('img.avatar', {src: bloburl + image}), |
| 94 … | + h('div', {innerHTML: md.block(pinned.value.content.text)}, |
| 95 … | + h('span.date', mo(pinned.value.timestamp).fromNow()) |
| 96 … | + ) |
| 97 … | + ), |
| 98 … | + h('div.msg', |
| 99 … | + h('p.small.ri', 'post'), |
| 100 … | + h('img.avatar', {src: bloburl + image}), |
| 101 … | + h('div', {innerHTML: md.block(post.value.content.text)}, |
| 102 … | + h('span.date', mo(post.value.timestamp).fromNow()) |
| 103 … | + ) |
| 104 … | + ), |
| 105 … | + h('div.msg', |
| 106 … | + h('p.small.ri', 'dig'), |
| 107 … | + h('img.avatar', {src: bloburl + image}), |
| 108 … | + h('div', vote.value.content.vote.link, |
| 109 … | + h('span.date', mo(vote.value.timestamp).fromNow()) |
| 110 … | + ) |
| 111 … | + ) |
84 | 112 … | ) |
85 | | - }) |
86 | | - ) |
87 | | - pull( |
88 | | - sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'post'}}}}], limit: 1, reverse: true}), |
89 | | - pull.drain(function (data) { |
90 | | - post = data; |
91 | | - }) |
92 | | - ) |
93 | | - pull( |
94 | | - sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'vote'}}}}], limit: 1, reverse: true}), |
95 | | - pull.drain(function (data) { |
96 | | - vote = data; |
97 | | - pull( |
98 | | - sbot.query.read({query: [{$filter: { key: data.value.content.vote.link}}]}), |
99 | | - pull.drain(function (reblog) { |
100 | | - avatar(sbot, me, reblog.value.author, function (err, avatar){ |
101 | | - if (err) { |
102 | | - throw err; |
103 | | - } |
104 | | - reauthor = avatar; |
105 | | - }) |
106 | | - redo = reblog; |
107 | | - }) |
108 | | - ) |
109 | | - }) |
110 | | - ) |
111 | | - pull( |
112 | | - sbot.query.read({query: [{$filter: { value: { author: me, content: {type: 'git-update'}}}}], limit: 1, reverse: true}), |
113 | | - pull.drain(function (data) { |
114 | | - gits = data; |
115 | | - }) |
116 | | - ) |
117 | | - }); |
118 | | - res.render('index', { title: 'Sdash', markdown, moment, bloburl}); |
119 | | -}); |
120 | | - |
121 | | -app.listen('7000'); |
| 113 … | + ).outerHTML) |
| 114 … | + } |
| 115 … | + } |
| 116 … | +}).listen(1337) |