-
Notifications
You must be signed in to change notification settings - Fork 9
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
Customize the fallback order of IPFS providers #3
Comments
hi, sorry this slipped past me back in June thoughts:
|
Idea: import { getIpfs, providers } from 'ipfs-provider'
const { httpClient, windowIpfs, jsIpfs } = providers
const { ipfs, provider } = await getIpfs({
fallbackOrder: [ httpClient, windowIpfs, jsIpfs ]
apiAddress: '/ip4/10.1.1.1/tcp/5002'
jsIpfsOpts: {}
}) |
what are the value in this example? |
I was thinking along these lines: const providers = Object.freeze({
httpClient: Symbol('httpClient')
windowIpfs: Symbol('windowIpfs')
jsIpfs: Symbol('jsIpfs')
}) cc @hugomrdias if there is a better/more intuitive way to do this |
// providers.js
export {
httpClient : (options = {}) => {
options = mergeOptions(defaults, options)
return 'everything needed'
},
windowIpfs : (options = {}) => {
options = mergeOptions(defaults, options)
return 'everything needed'
},
jsIpfs : (options = {}) => {
options = mergeOptions(defaults, options)
return 'everything needed'
},
} import { getIpfs, providers } from 'ipfs-provider'
const { httpClient, windowIpfs, jsIpfs } = providers
const { ipfs, provider } = await getIpfs([
httpClient({apiAddress: '/ip4/10.1.1.1/tcp/5002'}),
windowIpfs(),
jsIpfs({})
]) i would do it like this |
@hugomrdias that looks good, one concern is that even though the provider-specific options are better encapsulated this way, we may still have some global options, so I’d pass the array as a named parameter to the constructor another comment would be that the provider constructors here need to be lazy: don’t want to start up all the nodes before picking one to actually use |
Below should address:
// providers.js
export {
httpClient : (options = {}) => {
options = mergeOptions(defaults, options)
return () => 'everything needed'
},
windowIpfs : (options = {}) => {
options = mergeOptions(defaults, options)
return () => 'everything needed'
},
jsIpfs : (options = {}) => {
options = mergeOptions(defaults, options)
return () => 'everything needed'
},
} // sample use
import { getIpfs, providers } from 'ipfs-provider'
const { httpClient, windowIpfs, jsIpfs } = providers
const { ipfs, provider } = await getIpfs({
providers: [
httpClient({ apiAddress: '/ip4/10.1.1.1/tcp/5002' }),
windowIpfs({ commands: ['add','cat'] }),
jsIpfs({
getJsIpfs: () => import('ipfs'),
jsIpfsOpts: { /* advanced config */ }
})
],
someGlobalOption: 'some value'
}) Y/n? Anything missing? |
lgtm! |
There should be a way to customize the order in which providers are tried.
For example, if I want to ensure my app tries remote API before falling back to window.ipfs and embedded js-ipfs, I should be able to specify providers via ordered list:
Additional notes:
tryApi: false
The text was updated successfully, but these errors were encountered: