Skip to content

chore: use .create function for http client and ipfs client #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ipfsd-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ class Client {
*/
_createApi () {
if (this.opts.ipfsClientModule && this.grpcAddr && this.apiAddr) {
this.api = this.opts.ipfsClientModule({
this.api = this.opts.ipfsClientModule.create({
grpc: this.grpcAddr,
http: this.apiAddr
})
} else if (this.apiAddr) {
this.api = this.opts.ipfsHttpModule(this.apiAddr)
this.api = this.opts.ipfsHttpModule.create(this.apiAddr)
}

if (this.api) {
Expand Down
4 changes: 2 additions & 2 deletions src/ipfsd-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ class Daemon {

_createApi () {
if (this.opts.ipfsClientModule && this.grpcAddr) {
this.api = this.opts.ipfsClientModule({
this.api = this.opts.ipfsClientModule.create({
grpc: this.grpcAddr,
http: this.apiAddr
})
} else if (this.apiAddr) {
this.api = this.opts.ipfsHttpModule(this.apiAddr)
this.api = this.opts.ipfsHttpModule.create(this.apiAddr)
}

if (!this.api) {
Expand Down
2 changes: 1 addition & 1 deletion src/ipfsd-in-proc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class InProc {
*/
_setApi (addr) {
this.apiAddr = multiaddr(addr)
this.api = this.opts.ipfsHttpModule(addr)
this.api = this.opts.ipfsHttpModule.create(addr)
this.api.apiHost = this.apiAddr.nodeAddress().address
this.api.apiPort = this.apiAddr.nodeAddress().port
}
Expand Down
32 changes: 20 additions & 12 deletions test/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ describe('`createController` should return the correct class', () => {
type: 'js',
disposable: false,
ipfsModule: require('ipfs'),
ipfsClientModule: (opts) => {
clientCreated = true
ipfsClientModule: {
create: (opts) => {
clientCreated = true

return require('ipfs-client')(opts)
return require('ipfs-client')(opts)
}
},
ipfsHttpModule: (opts) => {
httpCreated = true
ipfsHttpModule: {
create: (opts) => {
httpCreated = true

return require('ipfs-http-client')(opts)
return require('ipfs-http-client')(opts)
}
},
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
})
Expand All @@ -90,15 +94,19 @@ describe('`createController` should return the correct class', () => {
remote: true,
disposable: false,
ipfsModule: require('ipfs'),
ipfsClientModule: (opts) => {
clientCreated = true
ipfsClientModule: {
create: (opts) => {
clientCreated = true

return require('ipfs-client')(opts)
return require('ipfs-client')(opts)
}
},
ipfsHttpModule: (opts) => {
httpCreated = true
ipfsHttpModule: {
create: (opts) => {
httpCreated = true

return require('ipfs-http-client')(opts)
return require('ipfs-http-client')(opts)
}
},
ipfsBin: pathJoin(__dirname, '../node_modules/ipfs/src/cli/bin.js')
})
Expand Down