diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bucky.js | 22 | ||||
| -rw-r--r-- | lib/db/index.js | 8 | ||||
| -rw-r--r-- | lib/index.js | 2 |
3 files changed, 31 insertions, 1 deletions
diff --git a/lib/bucky.js b/lib/bucky.js index ef6fbbc..9a43c0d 100644 --- a/lib/bucky.js +++ b/lib/bucky.js @@ -1,4 +1,5 @@ var db = require('./db') +var _ = require('lodash') var bucky = module.exports = { @@ -8,6 +9,7 @@ var bucky = module.exports = { db.getLatestThreads().then(function(threads){ res.threads = threads res.threads_ids = res.threads.pluck("id").sort() + res.keywords = _.uniq(res.threads.pluck("keyword")) next() }) }, @@ -33,6 +35,26 @@ var bucky = module.exports = { next() }) }, + ensureKeywordsForThreads: function (req, res, next){ + db.getKeywords(res.keywords).then(function(keywords){ + var lookup = {} + 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 + var k = lookup[kw] + if (! k) return + if (! t.get("color")) { + t.set("color", k.get("color")) + console.log(k.get("color")) + } + }) + next() + }) + }, ensureHootbox: function (req, res, next){ db.getCommentsForThread(1, 9).then(function(hootbox){ res.hootbox = hootbox diff --git a/lib/db/index.js b/lib/db/index.js index e7ad632..899abcc 100644 --- a/lib/db/index.js +++ b/lib/db/index.js @@ -67,6 +67,7 @@ db.getLatestThreads = function () { } /* FILES */ + db.getFilesForThread = function (id){ return File.query("where", "thread", "=", id).fetchAll() } @@ -78,6 +79,7 @@ db.getFileSizes = function(ids){ } /* COMMENTS */ + db.getCommentsForThread = function (id, limit, offset){ return Comment.query(function(qb){ qb.where("thread", "=", id).orderBy("id", "desc") @@ -98,6 +100,12 @@ db.getCommentCounts = function(ids){ return knex.column('thread').count('* as count').select().from('comments').where('thread', 'in', ids).groupBy('thread') } +/* KEYWORDS */ +db.getKeywords = function (keywords){ + return Keyword.query("where", "keyword", "in", keywords).fetchAll() +} + + /* PRIVATE MESSAGES */ db.getMessage = function (id){ diff --git a/lib/index.js b/lib/index.js index ace34af..c1ded7e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -87,7 +87,7 @@ site.route = function(){ bucky.ensureLatestThreads, bucky.ensureCommentCountsForThreads, bucky.ensureFileCountsForThreads, -// bucky.ensureFileSizeForThreads, + bucky.ensureKeywordsForThreads, bucky.ensureHootbox, bucky.ensureLastlog, function(req, res){ |
