js-ipfs-http-client with either a user provided apiAddress, the current origin, or the default /ip4/127.0.0.1/tcp/5001 address.
js-ipfsdisabled by default. Pass tryJsIpfs: true, getJsIpfs: () => Promise to enable it. See Enable js-ipfs
Usage
Add ipfs-redux-bundle to your store
bundles/index.js
import{composeBundles}from'redux-bundler'importipfsBundlefrom'ipfs-redux-bundle'// ... import other bundlesexportdefaultcomposeBundles(ipfsBundle({// These are the defaults:tryCompanion: true,// set false to bypass ipfs-companion verificationtryWindow: true,// set false to bypass window.ipfs verificationtryApi: true,// set false to bypass js-ipfs-http-client verification. Uses data from ipfsApi variable in localStoragetryJsIpfs: false,// set true to attempt js-ipfs initialisation.getJsIpfs: null// must be set to a js-ipfs instance if tryJsIpfs is true.})// ... add bundles here)
In your app, you can now connect up the doInitIpfs function. Here we init IPFS when our root component mounts:
getJsIpfs should be a function that returns a promise that resolves with a JsIpfs constructor. This works well with dynamic import(), so you can lazily load js-ipfs when it is needed.
API
Adds the following methods to the redux store.
store.selectIpfsReady()
boolean - Is the IPFS instance ready to use yet?
store.selectIpfsInitFailed()
boolean - Did the IPFS instance fail to start?
store.selectIpfsInvalidAddress()
boolean - Is the last API Address you tried to use invalid?
store.selectIpfsProvider()
string - Can be window.ipfs, js-ipfs-api or js-ipfs.
store.selectIpfsApiAddress()
string - The API address of the IPFS instance.
store.doInitIpfs()
Create a new IPFS instance. This will window.ipfs if you have IPFS Companion installed, or a js-ipfs-http-client instance otherwise.
store.doStopIpfs()
Stops the IPFS instance. It is only intended to use with js-ipfs.
请发表评论