Skip to content

Commit 0539ac3

Browse files
committed
fix: swap ky for ipfs-utils http
1 parent 5fcc4fc commit 0539ac3

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

Diff for: src/factory.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22
const merge = require('merge-options').bind({ ignoreUndefined: true })
3-
const kyOriginal = require('ky-universal').default
43
const { tmpDir } = require('./utils')
54
const { isNode } = require('ipfs-utils/src/env')
5+
const http = require('ipfs-utils/src/http')
66
const ControllerDaemon = require('./ipfsd-daemon')
77
const ControllerRemote = require('./ipfsd-client')
88
const ControllerProc = require('./ipfsd-in-proc')
@@ -12,7 +12,6 @@ const testsConfig = require('./config')
1212
/** @typedef {import("./index").ControllerOptionsOverrides} ControllerOptionsOverrides */
1313
/** @typedef {import("./index").IpfsOptions} IpfsOptions */
1414

15-
const ky = kyOriginal.extend({ timeout: false })
1615
const defaults = {
1716
remote: !isNode,
1817
endpoint: 'http://localhost:43134',
@@ -62,12 +61,13 @@ class Factory {
6261
async tmpDir (options) {
6362
options = merge(this.opts, options)
6463
if (options.remote) {
65-
const res = await ky.get(
64+
const res = await http.get(
6665
`${options.endpoint}/util/tmp-dir`,
6766
{ searchParams: { type: options.type } }
68-
).json()
67+
)
68+
const out = await res.json()
6969

70-
return res.tmpDir
70+
return out.tmpDir
7171
}
7272

7373
return Promise.resolve(tmpDir(options.type))
@@ -78,17 +78,20 @@ class Factory {
7878
json: {
7979
...options,
8080
// avoid recursive spawning
81-
remote: false
81+
remote: false,
82+
ipfsBin: undefined,
83+
ipfsModule: undefined,
84+
ipfsHttpModule: undefined
8285
}
8386
}
8487

85-
const res = await ky.post(
88+
const res = await http.post(
8689
`${options.endpoint}/spawn`,
8790
opts
88-
).json()
91+
)
8992
return new ControllerRemote(
9093
options.endpoint,
91-
res,
94+
await res.json(),
9295
options
9396
)
9497
}

Diff for: src/ipfsd-client.js

+20-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use strict'
22

33
const multiaddr = require('multiaddr')
4+
const http = require('ipfs-utils/src/http')
45
const merge = require('merge-options').bind({ ignoreUndefined: true })
56
const debug = require('debug')
6-
const kyOriginal = require('ky-universal').default
77

8-
const ky = kyOriginal.extend({ timeout: false })
98
const daemonLog = {
109
info: debug('ipfsd-ctl:client:stdout'),
1110
err: debug('ipfsd-ctl:client:stderr')
@@ -86,11 +85,15 @@ class Client {
8685
typeof initOptions === 'boolean' ? {} : initOptions
8786
)
8887

89-
const res = await ky.post(
88+
const req = await http.post(
9089
`${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
9497
this.clean = false
9598
return this
9699
}
@@ -107,7 +110,7 @@ class Client {
107110
return this
108111
}
109112

110-
await ky.post(
113+
await http.post(
111114
`${this.baseUrl}/cleanup`,
112115
{ searchParams: { id: this.id } }
113116
)
@@ -122,10 +125,11 @@ class Client {
122125
*/
123126
async start () {
124127
if (!this.started) {
125-
const res = await ky.post(
128+
const req = await http.post(
126129
`${this.baseUrl}/start`,
127130
{ searchParams: { id: this.id } }
128-
).json()
131+
)
132+
const res = await req.json()
129133

130134
this._setApi(res.apiAddr)
131135
this._setGateway(res.gatewayAddr)
@@ -150,7 +154,7 @@ class Client {
150154
return this
151155
}
152156

153-
await ky.post(
157+
await http.post(
154158
`${this.baseUrl}/stop`,
155159
{ searchParams: { id: this.id } }
156160
)
@@ -169,10 +173,11 @@ class Client {
169173
* @returns {Promise<number>}
170174
*/
171175
async pid () {
172-
const res = await ky.get(
176+
const req = await http.get(
173177
`${this.baseUrl}/pid`,
174178
{ searchParams: { id: this.id } }
175-
).json()
179+
)
180+
const res = await req.json()
176181

177182
return res.pid
178183
}
@@ -183,10 +188,11 @@ class Client {
183188
* @returns {Promise<String>}
184189
*/
185190
async version () {
186-
const res = await ky.get(
191+
const req = await http.get(
187192
`${this.baseUrl}/version`,
188193
{ searchParams: { id: this.id } }
189-
).json()
194+
)
195+
const res = await req.json()
190196
return res.version
191197
}
192198
}

0 commit comments

Comments
 (0)