2
2
3
3
const Joi = require ( 'joi' )
4
4
const pull = require ( 'pull-stream' )
5
+ const pullatch = require ( 'pull-catch' )
5
6
const toStream = require ( 'pull-stream-to-stream' )
6
7
const ndjson = require ( 'pull-ndjson' )
7
8
const PassThrough = require ( 'readable-stream' ) . PassThrough
@@ -23,9 +24,19 @@ exports.get = {
23
24
handler : ( request , reply ) => {
24
25
const ipfs = request . server . app . ipfs
25
26
const peerId = request . query . arg
27
+
26
28
// Default count to 10
27
29
const count = request . query . n || request . query . count || 10
28
30
31
+ // Streams from pull-stream-to-stream don't seem to be compatible
32
+ // with the stream2 readable interface
33
+ // see: https://github.com/hapijs/hapi/blob/c23070a3de1b328876d5e64e679a147fafb04b38/lib/response.js#L533
34
+ // and: https://github.com/pull-stream/pull-stream-to-stream/blob/e436acee18b71af8e71d1b5d32eee642351517c7/index.js#L28
35
+
36
+ // TODO: here lies the issue
37
+ // The fact that ping can fail after it starts writting some success ndjson
38
+ // responses is not very friendly to how Hapi expects this stream to work
39
+ // This multiple stream transformation and stiching is a nightmare
29
40
const source = pull (
30
41
ipfs . pingPullStream ( peerId , { count : count } ) ,
31
42
pull . map ( ( chunk ) => ( {
@@ -36,10 +47,6 @@ exports.get = {
36
47
ndjson . serialize ( )
37
48
)
38
49
39
- // Streams from pull-stream-to-stream don't seem to be compatible
40
- // with the stream2 readable interface
41
- // see: https://github.com/hapijs/hapi/blob/c23070a3de1b328876d5e64e679a147fafb04b38/lib/response.js#L533
42
- // and: https://github.com/pull-stream/pull-stream-to-stream/blob/e436acee18b71af8e71d1b5d32eee642351517c7/index.js#L28
43
50
const responseStream = toStream . source ( source )
44
51
const stream2 = new PassThrough ( )
45
52
pump ( responseStream , stream2 )
0 commit comments