Skip to content

Commit

Permalink
feat: add js-kubo-rpc-client
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Aug 19, 2022
1 parent 8bf29d3 commit 20ea2f9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .aegir.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createServer } from './src/index.js'
import * as ipfsModule from 'ipfs'
import * as ipfsHttpModule from 'ipfs-http-client'
import * as kuboRpcModule from 'js-kubo-rpc-client'
import * as goIpfsModule from 'go-ipfs'

/** @type {import('aegir').Options["build"]["config"]} */
Expand All @@ -22,7 +23,8 @@ export default {
before: async () => {
const server = createServer(undefined, {
ipfsModule,
ipfsHttpModule
ipfsHttpModule: process.env.USE_KUBO_JS ? undefined : ipfsHttpModule,
kuboRpcModule: process.env.USE_KUBO_JS ? kuboRpcModule : undefined
}, {
go: {
ipfsBin: goIpfsModule.path()
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@
"scripts": {
"lint": "aegir lint",
"build": "aegir build",
"test": "aegir test",
"test:node": "aegir test -t node",
"test:chrome": "aegir test -t browser",
"test:firefox": "aegir test -t browser -- --browser firefox",
"test": "aegir test && USE_KUBO_JS=1 aegir test",
"test:node": "aegir test -t node && USE_KUBO_JS=1 aegir test -t node",
"test:chrome": "aegir test -t browser && USE_KUBO_JS=1 aegir test -t browser",
"test:firefox": "aegir test -t browser -- --browser firefox && USE_KUBO_JS=1 aegir test -t browser -- --browser firefox",
"release": "aegir release"
},
"dependencies": {
Expand All @@ -155,6 +155,7 @@
"execa": "^6.1.0",
"ipfs-utils": "^9.0.1",
"joi": "^17.2.1",
"js-kubo-rpc-client": "^1.0.0",
"merge-options": "^3.0.1",
"nanoid": "^4.0.0",
"p-wait-for": "^4.1.0",
Expand Down
3 changes: 2 additions & 1 deletion src/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class Factory {
remote: false,
ipfsBin: undefined,
ipfsModule: undefined,
ipfsHttpModule: undefined
ipfsHttpModule: undefined,
kuboRpcModule: undefined
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/ipfsd-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ class Client {
http: this.apiAddr
})
} else if (this.apiAddr) {
this.api = this.opts.ipfsHttpModule.create(this.apiAddr)
if (this.opts.kuboRpcModule != null) {
this.api = this.opts.kuboRpcModule.create(this.apiAddr)
} else if (this.opts.ipfsHttpModule != null) {
this.api = this.opts.ipfsHttpModule.create(this.apiAddr)
} else {
throw new Error('You must pass either a kuboRpcModule or ipfsHttpModule')
}
}

if (this.api) {
Expand Down
8 changes: 7 additions & 1 deletion src/ipfsd-daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ class Daemon {
http: this.apiAddr
})
} else if (this.apiAddr) {
this.api = this.opts.ipfsHttpModule.create(this.apiAddr)
if (this.opts.kuboRpcModule != null) {
this.api = this.opts.kuboRpcModule.create(this.apiAddr)
} else if (this.opts.ipfsHttpModule != null) {
this.api = this.opts.ipfsHttpModule.create(this.apiAddr)
} else {
throw new Error('You must pass either a kuboRpcModule or ipfsHttpModule')
}
}

if (!this.api) {
Expand Down
9 changes: 8 additions & 1 deletion src/ipfsd-in-proc.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ class InProc {
*/
_setApi (addr) {
this.apiAddr = new Multiaddr(addr)
this.api = this.opts.ipfsHttpModule.create(addr)

if (this.opts.kuboRpcModule != null) {
this.api = this.opts.kuboRpcModule.create(addr)
} else if (this.opts.ipfsHttpModule != null) {
this.api = this.opts.ipfsHttpModule.create(addr)
} else {
throw new Error('You must pass either a kuboRpcModule or ipfsHttpModule')
}
this.api.apiHost = this.apiAddr.nodeAddress().address
this.api.apiPort = this.apiAddr.nodeAddress().port
}
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ export interface ControllerOptions {
* Reference to an ipfs-http-client module
*/
ipfsHttpModule?: any
/**
* Reference to a js-kubo-rpc-client module
*/
kuboRpcModule?: any
/**
* Reference to an ipfs or ipfs-core module
*/
Expand Down

0 comments on commit 20ea2f9

Please sign in to comment.