1
1
'use strict'
2
2
3
3
const multiaddr = require ( 'multiaddr' )
4
+ const http = require ( 'ipfs-utils/src/http' )
4
5
const merge = require ( 'merge-options' ) . bind ( { ignoreUndefined : true } )
5
6
const debug = require ( 'debug' )
6
- const kyOriginal = require ( 'ky-universal' ) . default
7
7
8
- const ky = kyOriginal . extend ( { timeout : false } )
9
8
const daemonLog = {
10
9
info : debug ( 'ipfsd-ctl:client:stdout' ) ,
11
10
err : debug ( 'ipfsd-ctl:client:stderr' )
@@ -86,11 +85,15 @@ class Client {
86
85
typeof initOptions === 'boolean' ? { } : initOptions
87
86
)
88
87
89
- const res = await ky . post (
88
+ const req = await http . post (
90
89
`${ this . baseUrl } /init` ,
91
- { searchParams : { id : this . id } , json : opts }
92
- ) . json ( )
93
- this . initialized = res . initialized
90
+ {
91
+ searchParams : { id : this . id } ,
92
+ json : opts
93
+ }
94
+ )
95
+ const rsp = await req . json ( )
96
+ this . initialized = rsp . initialized
94
97
this . clean = false
95
98
return this
96
99
}
@@ -107,7 +110,7 @@ class Client {
107
110
return this
108
111
}
109
112
110
- await ky . post (
113
+ await http . post (
111
114
`${ this . baseUrl } /cleanup` ,
112
115
{ searchParams : { id : this . id } }
113
116
)
@@ -122,10 +125,11 @@ class Client {
122
125
*/
123
126
async start ( ) {
124
127
if ( ! this . started ) {
125
- const res = await ky . post (
128
+ const req = await http . post (
126
129
`${ this . baseUrl } /start` ,
127
130
{ searchParams : { id : this . id } }
128
- ) . json ( )
131
+ )
132
+ const res = await req . json ( )
129
133
130
134
this . _setApi ( res . apiAddr )
131
135
this . _setGateway ( res . gatewayAddr )
@@ -150,7 +154,7 @@ class Client {
150
154
return this
151
155
}
152
156
153
- await ky . post (
157
+ await http . post (
154
158
`${ this . baseUrl } /stop` ,
155
159
{ searchParams : { id : this . id } }
156
160
)
@@ -169,10 +173,11 @@ class Client {
169
173
* @returns {Promise<number> }
170
174
*/
171
175
async pid ( ) {
172
- const res = await ky . get (
176
+ const req = await http . get (
173
177
`${ this . baseUrl } /pid` ,
174
178
{ searchParams : { id : this . id } }
175
- ) . json ( )
179
+ )
180
+ const res = await req . json ( )
176
181
177
182
return res . pid
178
183
}
@@ -183,10 +188,11 @@ class Client {
183
188
* @returns {Promise<String> }
184
189
*/
185
190
async version ( ) {
186
- const res = await ky . get (
191
+ const req = await http . get (
187
192
`${ this . baseUrl } /version` ,
188
193
{ searchParams : { id : this . id } }
189
- ) . json ( )
194
+ )
195
+ const res = await req . json ( )
190
196
return res . version
191
197
}
192
198
}
0 commit comments