diff options
Diffstat (limited to 'lib/bucky.js')
| -rw-r--r-- | lib/bucky.js | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/bucky.js b/lib/bucky.js index 9a43c0d..ad2018f 100644 --- a/lib/bucky.js +++ b/lib/bucky.js @@ -41,7 +41,6 @@ var bucky = module.exports = { keywords.forEach(function(k){ lookup[k.get('keyword')] = k }) - console.log(keywords) res.threads.forEach(function(t){ var kw = t.get('keyword') if (! kw) return @@ -49,7 +48,6 @@ var bucky = module.exports = { if (! k) return if (! t.get("color")) { t.set("color", k.get("color")) - console.log(k.get("color")) } }) next() @@ -71,13 +69,14 @@ var bucky = module.exports = { /* DETAILS */ ensureThread: function (req, res, next){ - db.getThread(req.param.id).then(function(thread){ + var id = req.params.id.replace(/\D/g, "") + db.getThread(id).then(function(thread){ if (thread) { res.thread = thread next() } else { - res.sendCode(404) + res.sendStatus(404) } }) }, @@ -90,16 +89,31 @@ var bucky = module.exports = { }) }, ensureCommentsForThread: function (req, res, next){ - db.getCommentsForThread(id).then(function(comments){ + db.getCommentsForThread(res.thread.get('id')).then(function(comments){ res.comments = comments next() }) }, ensureFilesForThread: function (req, res, next){ - db.getCommentsForThread(id).then(function(files){ + db.getFilesForThread(res.thread.get('id')).then(function(files){ res.files = files next() }) }, + + /* KEYWORDS */ + + ensureThreadsForKeyword: function (req, res, next){ + var keyword = req.params.keyword + if (! keyword) { + res.sendStatus(404) + } + db.getThreadsForKeyword(keyword).then(function(threads){ + res.threads = threads + res.threads_ids = res.threads.pluck("id").sort() + res.keywords = _.uniq(res.threads.pluck("keyword")) + next() + }) + }, }
\ No newline at end of file |
