mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-01-10 12:24:20 +01:00
removed cache layer for IPNS
This commit is contained in:
parent
947ec377f4
commit
7c6360389b
@ -60,8 +60,8 @@ function BoardsAPI(ipfs){
|
||||
this.ipfs = ipfs
|
||||
this.version = 'ipfs:boards:version:dev'
|
||||
this.baseurl = '/ipfs-boards-profile/'
|
||||
this.users = {} // userID : profileHash
|
||||
this.resolving_ipns = {} // to check if a resolve is already in progress
|
||||
this.users = [] // list of IPNS names
|
||||
this.resolvingIPNS = {}
|
||||
this.ee = new EventEmitter()
|
||||
if(localStorage !== undefined){
|
||||
// Use localStorage to store the IPNS cache
|
||||
@ -69,10 +69,10 @@ function BoardsAPI(ipfs){
|
||||
try {
|
||||
this.users = JSON.parse(stored)
|
||||
if(this.users === null || this.users === undefined){
|
||||
this.users = {}
|
||||
this.users = []
|
||||
}
|
||||
} catch(e){
|
||||
this.users = {}
|
||||
this.users = []
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -87,16 +87,10 @@ BoardsAPI.prototype.backupCache = function(){
|
||||
// Rewrote this to use event emitters. Should also add periodic rechecking
|
||||
BoardsAPI.prototype.resolveIPNS = function(n,handler){
|
||||
if(handler && handler.apply) this.ee.on(n,handler)
|
||||
var cached = this.users[n]
|
||||
if(cached){
|
||||
this.ee.emit(n,cached)
|
||||
//console.log(n,'was cached',cached)
|
||||
} else {
|
||||
console.log(n,'not cached')
|
||||
}
|
||||
if(this.resolving_ipns[n] != true){
|
||||
this.resolving_ipns[n] = true
|
||||
if(!this.resolvingIPNS[n]){
|
||||
this.resolvingIPNS[n] = true
|
||||
this.ipfs.name.resolve(n,(err,r) => {
|
||||
delete this.resolvingIPNS[n]
|
||||
if(err){
|
||||
// Communicate error
|
||||
this.ee.emit('error',err)
|
||||
@ -105,20 +99,25 @@ BoardsAPI.prototype.resolveIPNS = function(n,handler){
|
||||
if(url === undefined){
|
||||
console.log('Could not resolve',n)
|
||||
this.ee.emit('error',r.Message)
|
||||
} else if(this.users[n] != url) this.isUserProfile(url,(isit,err) => {
|
||||
if(isit){
|
||||
console.log(n,'is a user')
|
||||
if(this.users[n] === undefined) this.ee.emit('user',n,url)
|
||||
this.users[n] = url
|
||||
this.ee.emit(n,url)
|
||||
this.backupCache()
|
||||
} else {
|
||||
console.log(n,'not a valid profile:',err)
|
||||
this.ee.emit(n,undefined,'not a valid profile: '+err)
|
||||
}
|
||||
this.resolving_ipns[n] = false
|
||||
return true // Remove from listeners
|
||||
})
|
||||
} else if(this.users.indexOf(n) < 0){ // new find
|
||||
this.isUserProfile(url,(isit,err) => {
|
||||
if(isit){
|
||||
console.log(n,'is a user')
|
||||
this.ee.emit(n,url)
|
||||
if(this.users.indexOf(n) < 0){
|
||||
this.ee.emit('user',n,url)
|
||||
this.users.push(n)
|
||||
this.backupCache()
|
||||
}
|
||||
} else {
|
||||
console.log(n,'not a valid profile:',err)
|
||||
this.ee.emit(n,undefined,'not a valid profile: '+err)
|
||||
}
|
||||
return true // Remove from listeners
|
||||
})
|
||||
} else { // Already known
|
||||
this.ee.emit(n,url)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -497,7 +496,7 @@ BoardsAPI.prototype.getEventEmitter = function(){
|
||||
}
|
||||
|
||||
BoardsAPI.prototype.getUsers = function(){
|
||||
return Object.keys(this.users)
|
||||
return this.users
|
||||
}
|
||||
|
||||
BoardsAPI.prototype.getMyID = function(){
|
||||
|
@ -59,7 +59,7 @@ module.exports = function(boardsAPI){
|
||||
<Markdown source={this.state.description} skipHtml={true} />
|
||||
{this.props.params.userid?<h5><UserID id={this.props.params.userid} api={this.state.boards} /></h5>:<p></p>}
|
||||
<div className="whitelist">
|
||||
{this.state.whitelist.map(i => <UserID id={i} api={this.state.boards} />)}
|
||||
{this.state.whitelist.map(i => <UserID id={i} key={i} api={this.state.boards} />)}
|
||||
</div>
|
||||
<hr />
|
||||
<PostList board={this.props.params.boardname} admin={this.props.params.userid} api={this.state.boards} />
|
||||
|
Loading…
Reference in New Issue
Block a user