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:
parent
78e78e74fe
commit
bda7708c70
@ -258,20 +258,23 @@ BoardsAPI.prototype.getBoardSettings = function(userID,board){
|
|||||||
return this.ee
|
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){
|
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.getBoardSettings(adminID,board)
|
||||||
this.ee.on('settings for'+board+'@'+adminID,function(settings,addr){
|
this.ee.on('settings for'+board+'@'+adminID,function(settings,addr){
|
||||||
// Download posts based on settings
|
// Download posts based on settings
|
||||||
@ -288,7 +291,7 @@ BoardsAPI.prototype.getPostsInBoard = function(adminID,board){
|
|||||||
})
|
})
|
||||||
this.emit('approved posts for '+board+'@'+adminID,ret)
|
this.emit('approved posts for '+board+'@'+adminID,ret)
|
||||||
// Automatically download approved posts
|
// Automatically download approved posts
|
||||||
ret.forEach(item => downloadPost(item.hash))
|
ret.forEach(item => this.downloadPost(item.hash,adminID,board))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if(settings.whitelist == true){
|
if(settings.whitelist == true){
|
||||||
@ -304,7 +307,7 @@ BoardsAPI.prototype.getPostsInBoard = function(adminID,board){
|
|||||||
this.getUserPostListInBoard(adminID,board,(err,res) => {
|
this.getUserPostListInBoard(adminID,board,(err,res) => {
|
||||||
if(err){
|
if(err){
|
||||||
console.log(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
|
return this.ee
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user