summaryrefslogtreecommitdiff
path: root/bucky/util/federate.js
diff options
context:
space:
mode:
Diffstat (limited to 'bucky/util/federate.js')
-rw-r--r--bucky/util/federate.js14
1 files changed, 6 insertions, 8 deletions
diff --git a/bucky/util/federate.js b/bucky/util/federate.js
index 5181d85..605d8d2 100644
--- a/bucky/util/federate.js
+++ b/bucky/util/federate.js
@@ -34,23 +34,21 @@ module.exports = {
req.params.keyword
).then(keyword => send("keyword", keyword)
).then(res => db.getThreadsForKeyword(req.params.keyword)
- ).then(threads => threads.reduce((promise, thread) => (
- promise.then(result => exportThread({ params: { id: thread.get('id') } }, res, function(){}))
- ), new Promise (resolve => resolve()))
- ).then(() => next())
+ ).then(threads => Promise.all(threads.map(thread => exportThread({ params: { id: thread.get('id') } }, res, function(){}))
+ )).then(() => next())
}
function exportThread (req, res, next) {
- var thread_id
+ let thread_id = 0
return db.getThread(
req.params.id
-
).then(thread => send("thread", thread)
).then(json => {
console.log('got thread id', json.el.id)
+ thread_id = json.el.id
return db.getCommentsForThread(req.params.id)
}).then(comments => comments.reduce((promise, comment) => (
- promise.then(result => {
+ promise.then(res => {
comment.set('thread', thread_id)
return send("comment", comment)
})
@@ -58,7 +56,7 @@ module.exports = {
).then(() => db.getFilesForThread(req.params.id)
).then(files => files.reduce((promise, file) => (
- promise.then(result => {
+ promise.then(res => {
copyFileToS3(file, thread_id)
file.set('thread', thread_id)
file.set('storage', process.env.S3_BUCKET)