diff options
Diffstat (limited to 'bucky')
| -rw-r--r-- | bucky/app/bucky.js | 6 | ||||
| -rw-r--r-- | bucky/app/index.js | 6 | ||||
| -rw-r--r-- | bucky/app/router.js | 14 | ||||
| -rw-r--r-- | bucky/db/index.js | 42 |
4 files changed, 49 insertions, 19 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 008427d..757592a 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -21,7 +21,9 @@ var bucky = module.exports = { lookup[c.thread] = c }) res.threads.forEach(function(thread){ - thread.set("comment_count", lookup[thread.id].count) + if (lookup[thread.id]) { + thread.set("comment_count", lookup[thread.id].count) + } }) next() }) @@ -58,7 +60,7 @@ var bucky = module.exports = { }) }, ensureHootbox: function (req, res, next){ - db.getCommentsForThread(1, 9, 0, "desc").then(function(hootbox){ + db.getCommentsForThread(1, 15, 0, "desc").then(function(hootbox){ res.hootbox = hootbox next() }) diff --git a/bucky/app/index.js b/bucky/app/index.js index 2260cfe..03c5593 100644 --- a/bucky/app/index.js +++ b/bucky/app/index.js @@ -40,9 +40,9 @@ site.init = function(){ type: 'mongodb', host: 'localhost', port: 27017, - dbName: 'sessionDb', + dbName: 'buckySessionDb', collectionName: 'sessions', - timeout: 10000 + timeout: 10000, }), resave: true, saveUninitialized: false, @@ -53,7 +53,7 @@ site.init = function(){ app.use(passport.initialize()) app.use(passport.session()) - server = http.createServer(app).listen(5000, function () { + server = http.createServer(app).listen(process.env.PORT || 5000, function () { console.log('Bucky listening at http://5.k:%s', server.address().port) }) diff --git a/bucky/app/router.js b/bucky/app/router.js index fe7d336..c3af565 100644 --- a/bucky/app/router.js +++ b/bucky/app/router.js @@ -1,8 +1,9 @@ -var auth = require('../util/auth') -var middleware = require('../util/middleware') -var fortune = require('../db/fortune') -var bucky = require('../app/bucky') -var util = require('../util/util') +var auth = require('./auth') +var middleware = require('./middleware') +var fortune = require('./fortune') +var bucky = require('./bucky') +var db = require('./db') +var util = require('./util') module.exports = function(app){ app.all('*', middleware.ensureLocals) @@ -29,13 +30,13 @@ module.exports = function(app){ app.post("/api/login", auth.loggedInLocal) app.get("/api/index", + bucky.ensureLastlog, middleware.ensureAuthenticated, bucky.ensureLatestThreads, bucky.ensureCommentCountsForThreads, bucky.ensureFileCountsForThreads, bucky.ensureKeywordsForThreads, bucky.ensureHootbox, - bucky.ensureLastlog, function(req, res){ res.json({ threads: res.threads, @@ -69,7 +70,6 @@ module.exports = function(app){ bucky.ensureThread, // ensure thread privacy bucky.createComment, - // add comments and files function(req, res){ res.json({ comment: res.comment diff --git a/bucky/db/index.js b/bucky/db/index.js index 77e94fa..f376308 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -58,12 +58,11 @@ db.getLastlog = function(limit){ return knex.column('username').column('lastseen').select().from('users').orderBy('lastseen', 'desc').limit(limit || 10) } - /* THREADS */ db.getLatestThreads = function () { return Thread.query(function(qb){ - qb.orderBy("id", "desc").limit(50) + qb.orderBy("lastmodified", "desc").limit(50) }).fetchAll() } db.getThreadsForKeyword = function (keyword) { @@ -74,7 +73,13 @@ db.getThreadsForKeyword = function (keyword) { db.getThread = function (id) { return Thread.query("where", "id", "=", id).fetch() } - +db.createThread = function(data){ + return new db.Thread(data).save() +} +db.updateThread = function(data){ +} +db.removeThread = function(id){ +} /* FILES */ @@ -87,7 +92,11 @@ db.getFileCounts = function(ids){ db.getFileSizes = function(ids){ return knex.column('thread').sum('size as size').select().from('files').where('thread', 'in', ids).groupBy('thread') } - +db.createFile = function(data){ + return new db.File(data).save() +} +db.removeFile = function(id){ +} /* COMMENTS */ @@ -111,8 +120,12 @@ db.getCommentsForThread = function (id, limit, offset, order){ db.getCommentCounts = function(ids){ return knex.column('thread').count('* as count').select().from('comments').where('thread', 'in', ids).groupBy('thread') } -db.createComment = function(comment){ - return new Comment(comment).save() +db.createComment = function(data){ + return new db.Comment(data).save() +} +db.updateComment = function(data){ +} +db.removeComment = function(id){ } @@ -124,6 +137,13 @@ db.getKeywords = function (keywords){ db.getKeyword = function (keyword) { return Keyword.query("where", "keyword", "=", keyword).fetch() } +db.createKeyword = function(data){ + return new db.Keyword(data).save() +} +db.updateKeyword = function(data){ +} +db.removeKeyword = function(id){ +} /* MAILBOXES */ @@ -134,7 +154,8 @@ db.getMailboxes = function(username){ db.getMailboxCounts = function(boxes){ return knex.column('mbox').count('* as count').select().from('messages').where('mbox', 'in', boxes).groupBy('mbox') } - +db.createMailbox = function(data){ +} /* MESSAGES */ @@ -157,3 +178,10 @@ db.getMessage = function (id){ return message }) } +db.createMessage = function(data){ + return new db.Message(data).save() +} +db.updateMessage = function(data){ +} +db.removeMessage = function(id){ +} |
