1
0
mirror of https://github.com/fazo96/ipfs-boards synced 2025-01-10 12:24:20 +01:00

separate postDownload into its own api function

This commit is contained in:
Enrico Fasoli 2015-11-20 21:07:37 +01:00
parent 78e78e74fe
commit bda7708c70

View File

@ -258,20 +258,23 @@ BoardsAPI.prototype.getBoardSettings = function(userID,board){
return this.ee
}
BoardsAPI.prototype.downloadPost = function(hash,adminID,board,op){
this.ipfs.cat(hash,(err2,r) => {
if(err2){
this.ee.emit('error',err2)
console.log('Could not download post',hash,'of',board+'@'+adminID)
} else {
// It already returns a JSON?
var post = r
if(op) post.op = op // Inject op
if(board) this.ee.emit('post in '+board+'@'+adminID,post,hash)
this.ee.emit(hash,post,adminID,board)
}
})
return this.ee
}
BoardsAPI.prototype.getPostsInBoard = function(adminID,board){
var downloadPost = (hash,op) => {
this.ipfs.cat(hash,(err2,r) => {
if(err2){
this.ee.emit('error',err2)
console.log('Could not download post',hash,'of',board+'@'+adminID)
} else {
// It already returns a JSON?
var post = r
if(op) post.op = op // Inject op
this.ee.emit('post in '+board+'@'+adminID,post,hash)
}
})
}
this.getBoardSettings(adminID,board)
this.ee.on('settings for'+board+'@'+adminID,function(settings,addr){
// Download posts based on settings
@ -288,7 +291,7 @@ BoardsAPI.prototype.getPostsInBoard = function(adminID,board){
})
this.emit('approved posts for '+board+'@'+adminID,ret)
// Automatically download approved posts
ret.forEach(item => downloadPost(item.hash))
ret.forEach(item => this.downloadPost(item.hash,adminID,board))
}
})
if(settings.whitelist == true){
@ -304,7 +307,7 @@ BoardsAPI.prototype.getPostsInBoard = function(adminID,board){
this.getUserPostListInBoard(adminID,board,(err,res) => {
if(err){
console.log(err)
} else res.forEach(item => downloadPost(item.hash,adminID))
} else res.forEach(item => this.downloadPost(item.hash,adminID,board,adminID))
})
return this.ee
}