mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-10 12:24:20 +01:00
updated to go-ipfs 0.4
This commit is contained in:
parent
7449e93e26
commit
604a48fa53
@ -9,6 +9,7 @@ Needs to be browserified to work in the browser
|
|||||||
// EventEmitter used to communicate with clients
|
// EventEmitter used to communicate with clients
|
||||||
var EventEmitter = require('wolfy87-eventemitter')
|
var EventEmitter = require('wolfy87-eventemitter')
|
||||||
var asyncjs = require('async')
|
var asyncjs = require('async')
|
||||||
|
var semver = require('semver')
|
||||||
|
|
||||||
function asObj (str, done) {
|
function asObj (str, done) {
|
||||||
if (str.toString) str = str.toString()
|
if (str.toString) str = str.toString()
|
||||||
@ -64,6 +65,12 @@ function BoardsAPI (ipfs) {
|
|||||||
this.resolvingIPNS = {}
|
this.resolvingIPNS = {}
|
||||||
this.ee = new EventEmitter()
|
this.ee = new EventEmitter()
|
||||||
if (window && window.localStorage !== undefined) {
|
if (window && window.localStorage !== undefined) {
|
||||||
|
this.ee.on('init', e => {
|
||||||
|
if (e) {
|
||||||
|
console.log('init failed')
|
||||||
|
this.init_error = e
|
||||||
|
}
|
||||||
|
})
|
||||||
// Use localStorage to store the IPNS cache
|
// Use localStorage to store the IPNS cache
|
||||||
var stored = window.localStorage.getItem('ipfs-boards-user-cache')
|
var stored = window.localStorage.getItem('ipfs-boards-user-cache')
|
||||||
try {
|
try {
|
||||||
@ -77,6 +84,17 @@ function BoardsAPI (ipfs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BoardsAPI.prototype.createProfile = function (profile) {
|
||||||
|
console.log('creating profile')
|
||||||
|
this.ipfs.add(new Buffer(JSON.stringify(profile)), (err, res) => {
|
||||||
|
console.log('added profile to IPFS:', err, res.Hash)
|
||||||
|
var profilepath = '/ipfs/' + res.Hash
|
||||||
|
this.ipfs.files.mv([profilepath, '/ipns/local/profile.json'], (err, res) => {
|
||||||
|
console.log('mv', err, res)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
BoardsAPI.prototype.backupCache = function () {
|
BoardsAPI.prototype.backupCache = function () {
|
||||||
if (window && window.localStorage !== undefined) {
|
if (window && window.localStorage !== undefined) {
|
||||||
// Use localStorage to store the IPNS cache
|
// Use localStorage to store the IPNS cache
|
||||||
@ -528,9 +546,19 @@ BoardsAPI.prototype.init = function (done) {
|
|||||||
} else {
|
} else {
|
||||||
this.ipfs_version = res.Version
|
this.ipfs_version = res.Version
|
||||||
console.log('IPFS Version is', res.Version)
|
console.log('IPFS Version is', res.Version)
|
||||||
this.ee.emit('init', undefined)
|
if (semver.satisfies(this.ipfs_version, '~0.4.0')) {
|
||||||
this.isInit = true
|
console.log('IPFS version is supported')
|
||||||
if (done && done.apply) done(null)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"description": "decentralized discussion board",
|
"description": "decentralized discussion board",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "webpack-dev-server --progress --hot --devtool eval-source --no-info",
|
"serve": "webpack-dev-server --progress --no-info --hot --watch --devtool eval-source",
|
||||||
"build": "webpack --progress"
|
"build": "webpack --progress"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@ -24,7 +24,7 @@
|
|||||||
"babel-plugin-transform-runtime": "~6.3.13",
|
"babel-plugin-transform-runtime": "~6.3.13",
|
||||||
"babel-preset-es2015": "~6.3.13",
|
"babel-preset-es2015": "~6.3.13",
|
||||||
"babel-preset-react": "~6.3.13",
|
"babel-preset-react": "~6.3.13",
|
||||||
"babel-runtime": "^6.3.13",
|
"babel-runtime": "~5.8.23",
|
||||||
"css-loader": "~0.23.0",
|
"css-loader": "~0.23.0",
|
||||||
"eslint": "~1.10.3",
|
"eslint": "~1.10.3",
|
||||||
"eslint-config-standard": "^4.4.0",
|
"eslint-config-standard": "^4.4.0",
|
||||||
@ -37,7 +37,7 @@
|
|||||||
"html-loader": "^0.4.0",
|
"html-loader": "^0.4.0",
|
||||||
"html-webpack-plugin": "~1.7.0",
|
"html-webpack-plugin": "~1.7.0",
|
||||||
"https-browserify": "0.0.1",
|
"https-browserify": "0.0.1",
|
||||||
"ipfs-api": "2.9.13",
|
"ipfs-api": "github:ipfs/js-ipfs-api#ba85b3b",
|
||||||
"json-loader": "~0.5.4",
|
"json-loader": "~0.5.4",
|
||||||
"lodash.sortedindex": "~3.1.1",
|
"lodash.sortedindex": "~3.1.1",
|
||||||
"markdown-loader": "^0.1.7",
|
"markdown-loader": "^0.1.7",
|
||||||
@ -46,6 +46,7 @@
|
|||||||
"react-dom": "~0.14.3",
|
"react-dom": "~0.14.3",
|
||||||
"react-markdown": "~1.1.1",
|
"react-markdown": "~1.1.1",
|
||||||
"react-router": "~1.0.2",
|
"react-router": "~1.0.2",
|
||||||
|
"semver": "^5.1.0",
|
||||||
"stream-http": "~2.0.2",
|
"stream-http": "~2.0.2",
|
||||||
"style-loader": "~0.13.0",
|
"style-loader": "~0.13.0",
|
||||||
"webpack": "~1.12.9",
|
"webpack": "~1.12.9",
|
||||||
|
@ -4,23 +4,35 @@ var Icon = require('icon.jsx')
|
|||||||
|
|
||||||
module.exports = React.createClass({
|
module.exports = React.createClass({
|
||||||
getInitialState: function () {
|
getInitialState: function () {
|
||||||
return { connected: false, error: false, long: false }
|
return {}
|
||||||
|
},
|
||||||
|
componentWillReceiveProps: function (props) {
|
||||||
|
if (props.api) {
|
||||||
|
this.checkStatus(props.api)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
componentDidMount: function () {
|
componentDidMount: function () {
|
||||||
var boards = this.props.api
|
this.checkStatus(this.props.api)
|
||||||
|
},
|
||||||
|
checkStatus: function (boards) {
|
||||||
if (boards) {
|
if (boards) {
|
||||||
if (!this.isMounted()) return
|
if (!this.isMounted()) return
|
||||||
if (boards.isInit) {
|
if (boards.isInit) {
|
||||||
this.setState({ connected: true })
|
this.setState({ connected: true })
|
||||||
} else {
|
} else {
|
||||||
boards.getEventEmitter().on('init', err => {
|
if (boards.init_error) {
|
||||||
if (!this.isMounted()) return
|
this.setState({ error: boards.init_error })
|
||||||
if (err) {
|
} else {
|
||||||
this.setState({ error: true })
|
boards.getEventEmitter().on('init', error => {
|
||||||
} else {
|
if (!this.isMounted()) return
|
||||||
this.setState({ connected: true })
|
if (error) {
|
||||||
}
|
this.setState({ error })
|
||||||
})
|
} else {
|
||||||
|
this.setState({ connected: true })
|
||||||
|
clearTimeout(this.timer)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else this.startTimer()
|
} else this.startTimer()
|
||||||
},
|
},
|
||||||
@ -29,8 +41,11 @@ module.exports = React.createClass({
|
|||||||
},
|
},
|
||||||
startTimer: function () {
|
startTimer: function () {
|
||||||
this.timer = setTimeout(_ => {
|
this.timer = setTimeout(_ => {
|
||||||
console.log('Connection to go-ipfs has timed out (probably due to CORS)')
|
if (this.isMounted()) {
|
||||||
if (this.isMounted()) this.setState({ long: true })
|
console.log('Connection to go-ipfs has timed out (probably due to CORS)')
|
||||||
|
this.setState({ long: true })
|
||||||
|
this.checkStatus()
|
||||||
|
}
|
||||||
}, 5000)
|
}, 5000)
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
@ -40,6 +55,10 @@ module.exports = React.createClass({
|
|||||||
<div className="">
|
<div className="">
|
||||||
<h1><Icon name="ban"/> Connection to IPFS not available</h1>
|
<h1><Icon name="ban"/> Connection to IPFS not available</h1>
|
||||||
<h4 className="light">Sorry, but at the moment an external application is needed to try the Prototype</h4>
|
<h4 className="light">Sorry, but at the moment an external application is needed to try the Prototype</h4>
|
||||||
|
<hr/>
|
||||||
|
<h5>Error Message</h5>
|
||||||
|
<p>{this.state.error.Message || this.state.error || 'connection to go-ipfs failed'}</p>
|
||||||
|
<hr/>
|
||||||
<p>You don't have an IPFS node running at <code>{opt.addr}:{opt.port}</code> or it is not reachable.
|
<p>You don't have an IPFS node running at <code>{opt.addr}:{opt.port}</code> or it is not reachable.
|
||||||
The IPFS Boards prototype requires a full IPFS node. Please start one by following the
|
The IPFS Boards prototype requires a full IPFS node. Please start one by following the
|
||||||
<a href="https://github.com/ipfs/go-ipfs"><code>go-ipfs</code> documentation.</a></p>
|
<a href="https://github.com/ipfs/go-ipfs"><code>go-ipfs</code> documentation.</a></p>
|
||||||
|
@ -41,8 +41,8 @@ module.exports = function (boardsAPI) {
|
|||||||
if (!this.isMounted()) return true
|
if (!this.isMounted()) return true
|
||||||
if (err) {
|
if (err) {
|
||||||
this.setState({
|
this.setState({
|
||||||
name: <Icon name="ban" />,
|
name: <span><Icon name="ban" /> Error</span>,
|
||||||
description: err
|
error: err
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.setState({ name: res.name, description: res.description })
|
this.setState({ name: res.name, description: res.description })
|
||||||
@ -56,12 +56,23 @@ module.exports = function (boardsAPI) {
|
|||||||
this.setState({ init: true })
|
this.setState({ init: true })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
newProfile: function () {
|
||||||
|
var boards = this.state.api
|
||||||
|
boards.createProfile({
|
||||||
|
name: 'Default Name',
|
||||||
|
description: 'Default Profile Description'
|
||||||
|
})
|
||||||
|
},
|
||||||
linkToEditor: function () {
|
linkToEditor: function () {
|
||||||
var uid = this.props.params.userid
|
var uid = this.props.params.userid
|
||||||
if (uid === 'me' && this.state.id) uid = this.state.id
|
if (uid === 'me' && this.state.id) uid = this.state.id
|
||||||
if (uid === this.state.id) {
|
if (uid === this.state.id) {
|
||||||
return <div>
|
return <div className="your-profile">
|
||||||
<h6>This is your profile</h6>
|
<h6>This is your profile</h6>
|
||||||
|
{this.state.error ? <div>
|
||||||
|
<b>Oops</b>. Looks like your profile is not valid
|
||||||
|
<button className="new-profile button button-primary" onClick={this.newProfile}>New Profile</button>
|
||||||
|
</div> : <div></div>}
|
||||||
<hr/>
|
<hr/>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
@ -74,7 +85,7 @@ module.exports = function (boardsAPI) {
|
|||||||
return (<div className="profile">
|
return (<div className="profile">
|
||||||
{this.linkToEditor()}
|
{this.linkToEditor()}
|
||||||
<h1>{this.state.name}</h1>
|
<h1>{this.state.name}</h1>
|
||||||
<Markdown source={this.state.description} skipHtml={true} />
|
<Markdown source={this.state.erro ? this.state.error : this.state.description} skipHtml={true} />
|
||||||
<hr/>
|
<hr/>
|
||||||
<div className="light breaker">@{uid}</div>
|
<div className="light breaker">@{uid}</div>
|
||||||
{this.state.boards.map(n => {
|
{this.state.boards.map(n => {
|
||||||
|
@ -166,6 +166,15 @@ a:hover {
|
|||||||
margin-right: 1rem;
|
margin-right: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.your-profile {
|
||||||
|
text-align: center
|
||||||
|
}
|
||||||
|
|
||||||
|
.new-profile {
|
||||||
|
display: block;
|
||||||
|
margin: 3rem auto;
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 400px) {
|
@media (min-width: 400px) {
|
||||||
/* larger than mobile */
|
/* larger than mobile */
|
||||||
.settings .buttons {
|
.settings .buttons {
|
||||||
|
@ -61,7 +61,7 @@ var config = {
|
|||||||
},
|
},
|
||||||
externals: {
|
externals: {
|
||||||
net: '{}',
|
net: '{}',
|
||||||
fs: '{}',
|
fs: '{ lstat: function(){} }',
|
||||||
tls: '{}',
|
tls: '{}',
|
||||||
console: '{}',
|
console: '{}',
|
||||||
'require-dir': '{}'
|
'require-dir': '{}'
|
||||||
|
Loading…
Reference in New Issue
Block a user