Files: 324fed137cb04497adc9c508cdb230546136ec9f / v01.js
835 bytesRaw
1 | const Connection = require('ssb-client') |
2 | const pull = require('pull-stream') |
3 | |
4 | console.log('Connecting') |
5 | |
6 | Connection((err, server) => { |
7 | if (err) throw err |
8 | console.log('Connection established') |
9 | |
10 | const opts = { |
11 | limit: 100, |
12 | reverse: true |
13 | } |
14 | |
15 | pull( |
16 | server.query.read(opts), |
17 | pull.filter(msg => msg.value.content.type === 'post'), |
18 | pull.collect(onDone) |
19 | ) |
20 | |
21 | function onDone (err, msgs) { |
22 | if (err) { |
23 | console.error(err) |
24 | server.close() |
25 | return |
26 | } |
27 | |
28 | msgs.forEach(msg => { |
29 | prettyPrint(msg) |
30 | console.log('------') |
31 | }) |
32 | |
33 | console.log(`${msgs.length} messages`) |
34 | server.close() |
35 | } |
36 | }) |
37 | |
38 | function prettyPrint (msg) { |
39 | console.log(JSON.stringify(msg, null, 2)) |
40 | // this just print the full object out as a string that's been nicely indented |
41 | // with each level of nesting |
42 | } |
43 |
Built with git-ssb-web