This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree 3 files changed +14
-9
lines changed 3 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -77,8 +77,13 @@ module.exports = function pubsub (self) {
77
77
return setImmediate ( ( ) => callback ( new Error ( OFFLINE_ERROR ) ) )
78
78
}
79
79
80
+ if ( typeof topic === 'function' ) {
81
+ callback = topic
82
+ topic = null
83
+ }
84
+
80
85
const peers = Array . from ( self . _pubsub . peers . values ( ) )
81
- . filter ( ( peer ) => peer . topics . has ( topic ) )
86
+ . filter ( ( peer ) => topic ? peer . topics . has ( topic ) : true )
82
87
. map ( ( peer ) => peer . info . id . toB58String ( ) )
83
88
84
89
setImmediate ( ( ) => callback ( null , peers ) )
Original file line number Diff line number Diff line change @@ -102,13 +102,13 @@ exports.peers = {
102
102
const topic = request . query . arg
103
103
const ipfs = request . server . app . ipfs
104
104
105
- if ( ! topic ) {
106
- return reply ( new Error ( 'Missing topic' ) )
107
- }
108
-
109
105
ipfs . pubsub . peers ( topic , ( err , peers ) => {
110
106
if ( err ) {
111
- return reply ( new Error ( `Failed to find peers subscribed to ${ topic } : ${ err } ` ) )
107
+ const message = topic
108
+ ? `Failed to find peers subscribed to ${ topic } : ${ err } `
109
+ : `Failed to find peers: ${ err } `
110
+
111
+ return reply ( new Error ( message ) )
112
112
}
113
113
114
114
reply ( { Strings : peers } )
Original file line number Diff line number Diff line change @@ -91,13 +91,13 @@ module.exports = (http) => {
91
91
} )
92
92
93
93
describe ( '/peers' , ( ) => {
94
- it ( 'returns 500 if no topic is provided' , ( done ) => {
94
+ it ( 'returns 200 if no topic is provided' , ( done ) => {
95
95
api . inject ( {
96
96
method : 'GET' ,
97
97
url : `/api/v0/pubsub/peers`
98
98
} , ( res ) => {
99
- expect ( res . statusCode ) . to . equal ( 500 )
100
- expect ( res . result . Code ) . to . be . eql ( 1 )
99
+ expect ( res . statusCode ) . to . equal ( 200 )
100
+ expect ( res . result . Strings ) . to . be . eql ( [ ] )
101
101
done ( )
102
102
} )
103
103
} )
You can’t perform that action at this time.
0 commit comments