@@ -93,19 +93,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
93
93
94
94
// https://specs.ipfs.tech/routing/http-routing-v1/
95
95
const url = new URL ( `${ this . clientUrl } routing/v1/providers/${ cid . toString ( ) } ` )
96
- // IPIP-484 filtering. options takes precedence over global filter
97
- if ( options . filterAddrs != null || this . filterAddrs != null ) {
98
- const filterAddrs = options . filterAddrs ?. join ( ',' ) ?? this . filterAddrs ?. join ( ',' ) ?? ''
99
- if ( filterAddrs !== '' ) {
100
- url . searchParams . set ( 'filter-addrs' , filterAddrs )
101
- }
102
- }
103
- if ( options . filterProtocols != null || this . filterProtocols != null ) {
104
- const filterProtocols = options . filterProtocols ?. join ( ',' ) ?? this . filterProtocols ?. join ( ',' ) ?? ''
105
- if ( filterProtocols !== '' ) {
106
- url . searchParams . set ( 'filter-protocols' , filterProtocols )
107
- }
108
- }
96
+ this . #addFilterParams( url , options . filterAddrs , options . filterProtocols )
109
97
const getOptions = { headers : { Accept : 'application/x-ndjson' } , signal }
110
98
const res = await fetch ( url , getOptions )
111
99
@@ -171,20 +159,8 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
171
159
172
160
// https://specs.ipfs.tech/routing/http-routing-v1/
173
161
const url = new URL ( `${ this . clientUrl } routing/v1/peers/${ peerId . toCID ( ) . toString ( ) } ` )
162
+ this . #addFilterParams( url , options . filterAddrs , options . filterProtocols )
174
163
175
- // IPIP-484 filtering. local options filter precedence over global filter
176
- if ( options . filterAddrs != null || this . filterAddrs != null ) {
177
- const filterAddrs = options . filterAddrs ?. join ( ',' ) ?? this . filterAddrs ?. join ( ',' ) ?? ''
178
- if ( filterAddrs !== '' ) {
179
- url . searchParams . set ( 'filter-addrs' , filterAddrs )
180
- }
181
- }
182
- if ( options . filterProtocols != null || this . filterProtocols != null ) {
183
- const filterProtocols = options . filterProtocols ?. join ( ',' ) ?? this . filterProtocols ?. join ( ',' ) ?? ''
184
- if ( filterProtocols !== '' ) {
185
- url . searchParams . set ( 'filter-protocols' , filterProtocols )
186
- }
187
- }
188
164
const getOptions = { headers : { Accept : 'application/x-ndjson' } , signal }
189
165
const res = await fetch ( url , getOptions )
190
166
@@ -357,4 +333,20 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
357
333
log . error ( 'could not conform record to peer schema' , err )
358
334
}
359
335
}
336
+
337
+ #addFilterParams ( url : URL , filterAddrs ?: string [ ] , filterProtocols ?: string [ ] ) : void {
338
+ // IPIP-484 filtering. local options filter precedence over global filter
339
+ if ( filterAddrs != null || this . filterAddrs != null ) {
340
+ const adressFilter = filterAddrs ?. join ( ',' ) ?? this . filterAddrs ?. join ( ',' ) ?? ''
341
+ if ( adressFilter !== '' ) {
342
+ url . searchParams . set ( 'filter-addrs' , adressFilter )
343
+ }
344
+ }
345
+ if ( filterProtocols != null || this . filterProtocols != null ) {
346
+ const protocolFilter = filterProtocols ?. join ( ',' ) ?? this . filterProtocols ?. join ( ',' ) ?? ''
347
+ if ( protocolFilter !== '' ) {
348
+ url . searchParams . set ( 'filter-protocols' , protocolFilter )
349
+ }
350
+ }
351
+ }
360
352
}
0 commit comments