mirror of
https://github.com/fazo96/ipfs-boards
synced 2025-03-12 21:48:39 +01:00
updated IPNS resolving system
This commit is contained in:
parent
0fd0141068
commit
742a48ceb3
@ -51,20 +51,25 @@ function BoardsAPI(ipfs){
|
|||||||
this.ipfs = ipfs
|
this.ipfs = ipfs
|
||||||
this.version = 'dev'
|
this.version = 'dev'
|
||||||
this.users = {} // userID : profileHash
|
this.users = {} // userID : profileHash
|
||||||
this.posts = {} // boardName : postsList
|
this.resolving_ipns = {} // to check if a resolve is already in progress
|
||||||
this.comments = {} // objectID : comments
|
|
||||||
this.ee = new EventEmitter()
|
this.ee = new EventEmitter()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrote this to use event emitters. Should also add periodic rechecking
|
// Rewrote this to use event emitters. Should also add periodic rechecking
|
||||||
BoardsAPI.prototype.resolveIPNS = function(n,handler){
|
BoardsAPI.prototype.resolveIPNS = function(n,handler){
|
||||||
this.ee.on(n,handler)
|
if(handler) this.ee.on(n,handler)
|
||||||
var cached = this.users[n]
|
var cached = this.users[n]
|
||||||
//console.log('Cached is',cached)
|
//console.log('Cached is',cached)
|
||||||
if(cached){
|
if(cached){
|
||||||
this.ee.emit(n,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.ipfs.name.resolve(n,(err,r) => {
|
||||||
|
setTimeout(_ => {
|
||||||
|
console.log('Launching automatic check for IPNS address',n)
|
||||||
|
this.prototype.resolveIPNS(n)
|
||||||
|
},20*1000)
|
||||||
if(!err) console.log('Resolved',n,'to',r.Path)
|
if(!err) console.log('Resolved',n,'to',r.Path)
|
||||||
if(err){
|
if(err){
|
||||||
// Communicate error
|
// Communicate error
|
||||||
@ -81,9 +86,14 @@ BoardsAPI.prototype.resolveIPNS = function(n,handler){
|
|||||||
this.ee.emit(n,r.Path)
|
this.ee.emit(n,r.Path)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
return this.ee
|
return this.ee
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BoardsAPI.prototype.getIPNS = function(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
BoardsAPI.prototype.isUserProfile = function(addr,done){
|
BoardsAPI.prototype.isUserProfile = function(addr,done){
|
||||||
this.ipfs.cat(addr+'/ipfs-boards-version.txt',(err,r) => {
|
this.ipfs.cat(addr+'/ipfs-boards-version.txt',(err,r) => {
|
||||||
if(err) return done(false)
|
if(err) return done(false)
|
||||||
|
Loading…
Reference in New Issue
Block a user