1
0
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:
Enrico Fasoli 2015-11-14 18:38:46 +01:00
parent 0fd0141068
commit 742a48ceb3

View File

@ -51,20 +51,25 @@ function BoardsAPI(ipfs){
this.ipfs = ipfs
this.version = 'dev'
this.users = {} // userID : profileHash
this.posts = {} // boardName : postsList
this.comments = {} // objectID : comments
this.resolving_ipns = {} // to check if a resolve is already in progress
this.ee = new EventEmitter()
}
// Rewrote this to use event emitters. Should also add periodic rechecking
BoardsAPI.prototype.resolveIPNS = function(n,handler){
this.ee.on(n,handler)
if(handler) 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) => {
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){
// Communicate error
@ -81,9 +86,14 @@ BoardsAPI.prototype.resolveIPNS = function(n,handler){
this.ee.emit(n,r.Path)
}
})
}
return this.ee
}
BoardsAPI.prototype.getIPNS = function(){
}
BoardsAPI.prototype.isUserProfile = function(addr,done){
this.ipfs.cat(addr+'/ipfs-boards-version.txt',(err,r) => {
if(err) return done(false)