mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-03-11 21:38:38 +01:00
added few small features and rewrote user profile resolution
This commit is contained in:
parent
29e5ca5f5b
commit
2448630e4b
@ -79,29 +79,27 @@ BoardsAPI.prototype.backupCache = function(){
|
||||
BoardsAPI.prototype.resolveIPNS = function(n,handler){
|
||||
if(handler && handler.apply) this.ee.on(n,handler)
|
||||
var cached = this.users[n]
|
||||
//console.log('Cached is',cached)
|
||||
if(cached){
|
||||
this.ee.emit(n,cached)
|
||||
}
|
||||
if(this.resolving_ipns[n] != true){
|
||||
this.resolving_ipns[n] = true
|
||||
this.ipfs.name.resolve(n,(err,r) => {
|
||||
this.resolving_ipns[n] = false
|
||||
setTimeout(_ => {
|
||||
console.log('Launched automatic check for IPNS address',n)
|
||||
this.resolveIPNS(n)
|
||||
},10*1000)
|
||||
if(!err) console.log('Resolved',n,'to',r.Path)
|
||||
if(err){
|
||||
// Communicate error
|
||||
this.ee.emit(n,undefined,err)
|
||||
} else if(cached !== r.Path){
|
||||
//console.log('oldcache',this.users)
|
||||
//console.log('Setting cache for',n,'to',r.Path)
|
||||
this.users[n] = r.Path
|
||||
this.backupCache()
|
||||
console.log('Address for',n,'was updated to',r.Path)
|
||||
this.ee.emit(n,r.Path)
|
||||
this.ee.emit('error',err)
|
||||
} else {
|
||||
var url = r.Hash
|
||||
if(this.users[n] != url) this.isUserProfile(r.Hash,isit => {
|
||||
if(isit == this.version){
|
||||
console.log(n,'is a user')
|
||||
if(this.users[n] != url){
|
||||
this.users[n] = url
|
||||
this.ee.emit(n,url)
|
||||
}
|
||||
}
|
||||
this.resolving_ipns[n] = false
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -109,6 +107,7 @@ BoardsAPI.prototype.resolveIPNS = function(n,handler){
|
||||
}
|
||||
|
||||
BoardsAPI.prototype.isUserProfile = function(addr,done){
|
||||
if(addr === undefined) return console.log('Asked to check if undefined is a profile')
|
||||
this.ipfs.cat(addr+this.baseurl+'ipfs-boards-version.txt',(err,r) => {
|
||||
if(err) return done(false)
|
||||
replyAsObj(r,false,(_,res) => {
|
||||
@ -119,26 +118,6 @@ BoardsAPI.prototype.isUserProfile = function(addr,done){
|
||||
})
|
||||
}
|
||||
|
||||
BoardsAPI.prototype.isUser = function(s,done){
|
||||
var ss = s.split('/')
|
||||
var addr = ss[ss.length-1]
|
||||
// Try to see if they run IPFS Boards
|
||||
this.resolveIPNS(addr,(url,err) => {
|
||||
if(err){
|
||||
if(done) done(false)
|
||||
return console.log('Cannot resolve',addr,':',err)
|
||||
}
|
||||
this.isUserProfile(url,isit => {
|
||||
if(isit == this.version){
|
||||
console.log(addr,'is a user')
|
||||
this.users[addr] = url
|
||||
if(done) done(true,addr,url)
|
||||
} else if(done) done(false)
|
||||
})
|
||||
return true // remove myself from listeners
|
||||
})
|
||||
}
|
||||
|
||||
BoardsAPI.prototype.searchUsers = function(){
|
||||
// Look at our peers
|
||||
this.ipfs.swarm.peers((err,r) => {
|
||||
@ -146,11 +125,7 @@ BoardsAPI.prototype.searchUsers = function(){
|
||||
replyAsObj(r,true,(e,reply) => {
|
||||
console.log('Checking',reply.Strings.length,'peers')
|
||||
reply.Strings.forEach(item => {
|
||||
this.isUser(item,(isit,addr,url) => {
|
||||
if(isit){
|
||||
this.ee.emit('found user',addr,url)
|
||||
}
|
||||
})
|
||||
this.resolveIPNS(item)
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -177,7 +152,6 @@ BoardsAPI.prototype.getProfile = function(userID,done){
|
||||
// Get other info
|
||||
this.ipfs.ls(url+this.baseurl+'boards/',(err2,res) => {
|
||||
if(!err2){
|
||||
console.log('RES',res)
|
||||
var l = res.Objects[0].Links.map(i => {
|
||||
return { name: i.Name, hash: i.Hash }
|
||||
})
|
||||
@ -329,7 +303,7 @@ BoardsAPI.prototype.init = function(done){
|
||||
} else if(res.ID){
|
||||
console.log('I am',res.ID)
|
||||
this.id = res.ID
|
||||
this.isUser(res.ID)
|
||||
this.resolveIPNS(res.ID)
|
||||
console.log('Version is',this.version)
|
||||
this.ipfs.add(new Buffer('ipfs:boards:version:'+this.version),(err2,r) => {
|
||||
if(err2){
|
||||
|
@ -3,6 +3,7 @@ var ReactDOM = require('react-dom')
|
||||
var Router = require('react-router').Router
|
||||
var Route = require('react-router').Route
|
||||
var IndexRoute = require('react-router').IndexRoute
|
||||
var Redirect = require('react-router').Redirect
|
||||
var Link = require('react-router').Link
|
||||
|
||||
var MarkdownLib = require('react-markdown')
|
||||
@ -59,8 +60,9 @@ var Navbar = React.createClass({
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="twelve columns">
|
||||
<h4><Link to="/"><Icon name="comments" class="light"/> Boards</Link></h4>
|
||||
{this.props.children || <h4><Link to="/"><Icon name="comments" class="light"/> Boards</Link></h4>}
|
||||
<div className="u-pull-right iconbar">
|
||||
<Link className="nounderline" to="/@me"><Icon name="user" class="fa-2x light"/></Link>
|
||||
<Link className="nounderline" to="/users"><Icon name="globe" class="fa-2x light"/></Link>
|
||||
<Link className="nounderline" to="/settings"><Icon name="cog" class="fa-2x light"/></Link>
|
||||
<a className="nounderline" href="https://github.com/fazo96/ipfs-boards"><Icon name="github" class="fa-2x light"/></a>
|
||||
@ -185,13 +187,11 @@ var Profile = React.createClass({
|
||||
var ee = boards.getProfile(this.props.params.userid, (err,res) => {
|
||||
if(!this.isMounted()) return true
|
||||
if(err){
|
||||
console.log(err)
|
||||
this.setState({
|
||||
name: '?',
|
||||
error: 'Invalid profile'
|
||||
})
|
||||
} else {
|
||||
console.log(res)
|
||||
this.setState({ name: res.name, description: res.description })
|
||||
}
|
||||
})
|
||||
@ -200,8 +200,18 @@ var Profile = React.createClass({
|
||||
this.setState({ boards: l })
|
||||
})
|
||||
},
|
||||
linkToEditor: function(){
|
||||
if(this.props.params.userid === boards.id){
|
||||
return <div>
|
||||
<h6>This is your profile</h6>
|
||||
<hr/>
|
||||
</div>
|
||||
}
|
||||
return ''
|
||||
},
|
||||
render: function(){
|
||||
return (<div className="profile">
|
||||
{this.linkToEditor()}
|
||||
<h1>{this.state.name}</h1>
|
||||
<p>{this.state.error}</p>
|
||||
<Markdown source={this.state.description} skipHtml={true} />
|
||||
@ -323,6 +333,7 @@ boards.init(err => {
|
||||
<Router>
|
||||
<Route path="/" component={App}>
|
||||
<IndexRoute component={Homepage} />
|
||||
<Redirect from="/@me" to={'/@'+boards.id} />
|
||||
<Route path="/@:userid">
|
||||
<IndexRoute component={Profile} />
|
||||
<Route path=":boardname" component={Board} />
|
||||
|
@ -1,3 +0,0 @@
|
||||
<div ng-repeat="post in posts">
|
||||
<div>{{post}}</div>
|
||||
</div>
|
@ -1 +0,0 @@
|
||||
Landing Page
|
Loading…
Reference in New Issue
Block a user