diff options
| -rw-r--r-- | bucky/app/site.js | 2 | ||||
| -rw-r--r-- | bucky/util/federate.js | 14 |
2 files changed, 7 insertions, 9 deletions
diff --git a/bucky/app/site.js b/bucky/app/site.js index 5fa044e..e266716 100644 --- a/bucky/app/site.js +++ b/bucky/app/site.js @@ -57,7 +57,7 @@ site.init = function(){ } app.use(session(sessionSettings)) upload.init() - // federate.route(app) + federate.route(app) // app.use(csurf({ // cookie: true, 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) |
