mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-10 12:24:20 +01:00
bugfixing and better limited mode
This commit is contained in:
parent
6f71134301
commit
6ab84ba064
@ -748,59 +748,58 @@ BoardsAPI.prototype.isNode = function () {
|
||||
// Initialize API
|
||||
BoardsAPI.prototype.init = function (done) {
|
||||
if (this.isInit) return
|
||||
this.ipfs.id((err, res) => {
|
||||
this.ipfs.version((err, res) => {
|
||||
if (err) {
|
||||
console.log('Error while getting OWN ID:', err)
|
||||
if (this.isRunningFromGateway()) {
|
||||
console.log('Running in limited mode')
|
||||
this.limited = true
|
||||
} else console.log('Limited mode not available')
|
||||
this.limited = this.isRunningFromGateway() ? 2 : false
|
||||
this.ee.emit('error', err)
|
||||
this.ee.emit('init', err, this.limited)
|
||||
if (done && done.apply) {
|
||||
done(err, this.limited)
|
||||
}
|
||||
} else if (res.ID) {
|
||||
console.log('I am', res.ID)
|
||||
this.id = res.ID
|
||||
this.resolveIPNS(res.ID)
|
||||
console.log('Version is', this.version)
|
||||
this.ipfs.add(new Buffer(this.version), (err2, r) => {
|
||||
if (err2) {
|
||||
this.ee.emit('error', err2)
|
||||
console.log('Error while calculating version hash:', err2)
|
||||
this.ee.emit('init', err2)
|
||||
if (done && done.apply) done(err2)
|
||||
} else {
|
||||
if (r && r.Hash) this.version_hash = r.Hash
|
||||
if (r && r[0] && r[0].Hash) this.version_hash = r[0].Hash
|
||||
console.log('Version hash is', this.version_hash)
|
||||
this.ipfs.version((err, res) => {
|
||||
if (err) {
|
||||
this.ee.emit('error', err)
|
||||
this.ee.emit('init', err)
|
||||
console.log('Error while getting ipfs version:', err)
|
||||
if (done && done.apply) done(err)
|
||||
} else {
|
||||
this.ipfs_version = res.Version.split('-')[0]
|
||||
console.log('IPFS Version is', res.Version)
|
||||
if (semver.satisfies(this.ipfs_version, '~0.4.0')) {
|
||||
console.log('IPFS version is supported')
|
||||
console.log('Error while getting ipfs version:', err)
|
||||
if (done && done.apply) done(err, this.limited)
|
||||
} else {
|
||||
this.ipfs_version = res.Version.split('-')[0]
|
||||
console.log('IPFS Version is', res.Version)
|
||||
if (semver.satisfies(this.ipfs_version, '~0.4.0')) {
|
||||
console.log('IPFS version is supported')
|
||||
this.ipfs.id((err, res) => {
|
||||
if (err) {
|
||||
console.log('Error while getting OWN ID:', err)
|
||||
this.limited = this.isRunningFromGateway() ? 1 : false
|
||||
this.ee.emit('error', err)
|
||||
this.ee.emit('init', err, this.limited)
|
||||
if (done && done.apply) {
|
||||
done(err, this.limited)
|
||||
}
|
||||
} else if (res.ID) {
|
||||
console.log('I am', res.ID)
|
||||
this.id = res.ID
|
||||
this.resolveIPNS(res.ID)
|
||||
console.log('Version is', this.version)
|
||||
this.ipfs.add(new Buffer(this.version), (err2, r) => {
|
||||
if (err2) {
|
||||
this.ee.emit('error', err2)
|
||||
console.log('Error while calculating version hash:', err2)
|
||||
this.ee.emit('init', err2, this.limited)
|
||||
if (done && done.apply) done(err2)
|
||||
} else {
|
||||
if (r && r.Hash) this.version_hash = r.Hash
|
||||
if (r && r[0] && r[0].Hash) this.version_hash = r[0].Hash
|
||||
console.log('Version hash is', this.version_hash)
|
||||
// DONE!
|
||||
this.ee.emit('init', undefined)
|
||||
this.isInit = true
|
||||
delete this.init_error
|
||||
if (done && done.apply) done(null)
|
||||
} else {
|
||||
var e = { Message: 'IPFS Version not supported. This app supports go-ipfs 0.4.x' }
|
||||
if (done && done.apply) done(e)
|
||||
console.log('Error:', e.Message)
|
||||
this.ee.emit('error', e)
|
||||
this.ee.emit('init', e)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
var e = { Message: 'IPFS Version not supported. This app supports go-ipfs 0.4.x' }
|
||||
if (done && done.apply) done(e)
|
||||
console.log('Error:', e.Message)
|
||||
this.ee.emit('error', e)
|
||||
this.ee.emit('init', e)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -40,21 +40,20 @@ module.exports = React.createClass({
|
||||
console.log('Connection to go-ipfs has timed out (probably due to CORS)')
|
||||
if (this.isMounted() && !this.state.connected && !this.state.limited) {
|
||||
this.setState({ long: true })
|
||||
this.init(this.props)
|
||||
}
|
||||
}, 5000)
|
||||
},
|
||||
getContent () {
|
||||
if (this.state.limited) {
|
||||
return <div>
|
||||
<h1><Icon name="ban"/> You're running in limited mode</h1>
|
||||
<h1><Icon name="exclamation-triangle" className="light" /> You're running in limited mode</h1>
|
||||
<h4 className="light">Sorry, but at the moment an external application is needed to fully take advantage of the app</h4>
|
||||
<p>Only a few features are available in limited mode.</p>
|
||||
<h5>Why am I running in limited mode?</h5>
|
||||
</div>
|
||||
} else {
|
||||
return <div>
|
||||
<h1><Icon name="ban"/> Connection to IPFS not available</h1>
|
||||
<h1><Icon name="ban" className="light" /> Connection to IPFS not available</h1>
|
||||
<h4 className="light">Sorry, but at the moment an external application is needed to try the Prototype</h4>
|
||||
<p><b>Tip:</b> you can also run in limited mode by loading the app from an IPFS Gateway.</p>
|
||||
</div>
|
||||
|
@ -7,14 +7,6 @@ module.exports = function (boardsAPI) {
|
||||
return { addr: 'localhost', port: 5001, api: false }
|
||||
},
|
||||
getInitialState: function () {
|
||||
boardsAPI.use(boards => {
|
||||
if (boards.isInit && this.isMounted()) this.setState({ api: true })
|
||||
boards.getEventEmitter().on('init', (err, limited) => {
|
||||
if ((!err || limited) && this.isMounted()) {
|
||||
this.setState({ api: true, limited })
|
||||
}
|
||||
})
|
||||
})
|
||||
var s = window.localStorage.getItem('ipfs-boards-settings')
|
||||
var obj = this.getDefaults()
|
||||
try {
|
||||
@ -24,6 +16,20 @@ module.exports = function (boardsAPI) {
|
||||
}
|
||||
return obj || this.getDefaults()
|
||||
},
|
||||
componentDidMount () {
|
||||
boardsAPI.use(boards => {
|
||||
if (boards.isInit || boards.limited) {
|
||||
this.setState({ api: true, limited: boards.limited })
|
||||
} else {
|
||||
this.setState({ error: boards.init_error || 'neither limited mode nor the API is available.' })
|
||||
}
|
||||
boards.getEventEmitter().on('init', (err, limited) => {
|
||||
if (this.isMounted()) {
|
||||
this.setState({ error: err, api: (!err || limited), limited })
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
save: function () {
|
||||
if (isNaN(this.state.port) || parseInt(this.state.port, 10) > 65535 || parseInt(this.state.port, 10) < 1) {
|
||||
window.alert('Port number invalid')
|
||||
@ -46,7 +52,13 @@ module.exports = function (boardsAPI) {
|
||||
}
|
||||
},
|
||||
isOK: function () {
|
||||
if (this.state.limited) {
|
||||
if (this.state.error) {
|
||||
console.log('Error', this.state.error)
|
||||
return <div className="itsok light">
|
||||
<h5><Icon name="ban" /> Error</h5>
|
||||
<p>{this.state.error}</p>
|
||||
</div>
|
||||
} else if (this.state.limited) {
|
||||
return <div className="itsok light">
|
||||
<h5><Icon name="exclamation-triangle" /> Limited Mode</h5>
|
||||
<p>Some features may not be available.</p>
|
||||
|
Loading…
Reference in New Issue
Block a user