Skip to content

Commit

Permalink
fix: set Explore defaults on app load (#2268)
Browse files Browse the repository at this point in the history
* fix: set Explore defaults on app load

* chore: fix types

* fix: do not allow insecure remote gateways for explore page

* chore: use [email protected]
  • Loading branch information
SgtPooki authored Sep 24, 2024
1 parent eb3076b commit fd8819e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 25 deletions.
48 changes: 24 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"ipfs-css": "^1.4.0",
"ipfs-geoip": "^9.1.0",
"ipfs-provider": "^2.1.0",
"ipld-explorer-components": "^7.0.2",
"ipld-explorer-components": "^7.0.3",
"is-ipfs": "^8.0.1",
"istextorbinary": "^6.0.0",
"it-all": "^1.0.5",
Expand Down
7 changes: 7 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import FilesExploreForm from './files/explore-form/FilesExploreForm.js'

export class App extends Component {
static propTypes = {
doSetupLocalStorage: PropTypes.func.isRequired,
doTryInitIpfs: PropTypes.func.isRequired,
doInitHelia: PropTypes.func.isRequired,
doUpdateUrl: PropTypes.func.isRequired,
Expand All @@ -32,6 +33,11 @@ export class App extends Component {
isOver: PropTypes.bool.isRequired
}

constructor (props) {
super(props)
props.doSetupLocalStorage()
}

componentDidMount () {
this.props.doTryInitIpfs()
this.props.doInitHelia()
Expand Down Expand Up @@ -131,6 +137,7 @@ export default connect(
'doExploreUserProvidedPath',
'doUpdateUrl',
'doUpdateHash',
'doSetupLocalStorage',
'doTryInitIpfs',
'doInitHelia',
'doFilesWrite',
Expand Down
19 changes: 19 additions & 0 deletions src/bundles/ipfs-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,25 @@ const selectors = {
*/

const actions = {

doSetupLocalStorage: () => async () => {
/** For the Explore page (i.e. ipld-explorer-components) */
const useRemoteGatewaysToExplore = localStorage.getItem('explore.ipld.gatewayEnabled')
if (useRemoteGatewaysToExplore === null) {
// by default, disable remote gateways for the Explore page (i.e. ipld-explorer-components)
await writeSetting('explore.ipld.gatewayEnabled', false)
}

const kuboGateway = readSetting('kuboGateway')
if (kuboGateway === null || typeof kuboGateway === 'string' || typeof kuboGateway === 'boolean' || typeof kuboGateway === 'number') {
// empty or invalid, set defaults
await writeSetting('kuboGateway', { trustlessBlockBrokerConfig: { init: { allowLocal: true, allowInsecure: false } } })
} else if (/** @type {Record<string, any>} */(kuboGateway).trustlessBlockBrokerConfig == null) {
// missing trustlessBlockBrokerConfig, set defaults
await writeSetting('kuboGateway', { ...kuboGateway, trustlessBlockBrokerConfig: { init: { allowLocal: true, allowInsecure: false } } })
}
},

/**
* @returns {function(Context):Promise<boolean>}
*/
Expand Down

0 comments on commit fd8819e

Please sign in to comment.