summaryrefslogtreecommitdiff
path: root/bucky
diff options
context:
space:
mode:
Diffstat (limited to 'bucky')
-rw-r--r--bucky/app/api.js23
-rw-r--r--bucky/app/bucky.js31
-rw-r--r--bucky/db/index.js2
3 files changed, 40 insertions, 16 deletions
diff --git a/bucky/app/api.js b/bucky/app/api.js
index ff17626..63e480e 100644
--- a/bucky/app/api.js
+++ b/bucky/app/api.js
@@ -41,7 +41,7 @@ function route (app){
/* threads */
-
+
app.get("/api/index",
bucky.ensureLastlog,
middleware.ensureAuthenticated,
@@ -59,6 +59,13 @@ function route (app){
lastlog: res.lastlog,
})
})
+ app.post("/api/keyword/new",
+ bucky.ensureLastlog,
+ middleware.ensureAuthenticated,
+ bucky.createKeyword,
+ function(req, res){
+ res.json({ keyword: res.keyword })
+ })
app.get("/api/keyword/:keyword",
bucky.ensureLastlog,
middleware.ensureAuthenticated,
@@ -123,10 +130,10 @@ function route (app){
function(req, res){
res.send({ status: 'ok' })
})
-
+
/* comments */
- // one endpoint handles comments + files
+ // one endpoint handles comments + files
app.post("/api/thread/:id/comment",
middleware.ensureAuthenticated,
bucky.ensureThread,
@@ -178,7 +185,7 @@ function route (app){
})
/* search */
-
+
app.get("/api/search",
middleware.ensureAuthenticated,
search.search,
@@ -190,7 +197,7 @@ function route (app){
)
/* keywords */
-
+
app.get("/api/keywords",
middleware.ensureAuthenticated,
bucky.ensureKeywords,
@@ -223,10 +230,10 @@ function route (app){
threads: res.threads,
})
})
-
-
+
+
/* mail */
-
+
app.get("/api/mailbox/:box",
middleware.ensureAuthenticated,
bucky.ensureMailboxes,
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js
index dbb980d..cd70790 100644
--- a/bucky/app/bucky.js
+++ b/bucky/app/bucky.js
@@ -94,9 +94,9 @@ var bucky = module.exports = {
next()
})
},
-
+
/* DETAILS */
-
+
ensureThread: function (req, res, next){
var id = req.params.id.replace(/\D/g, "")
if (! id) {
@@ -253,7 +253,7 @@ var bucky = module.exports = {
res.sendStatus(500)
})
},
-
+
/* KEYWORDS */
ensureKeyword: function (req, res, next){
@@ -296,7 +296,24 @@ var bucky = module.exports = {
next()
})
},
-
+ createKeyword: function (req, res, next){
+ if (! req.body.keyword || ! req.body.keyword.length) {
+ res.json({ error: "no keyword" })
+ return
+ }
+ var data = {
+ keyword: req.body.keyword,
+ owner: req.user.get('username'),
+ createdate: util.now(),
+ public: 1,
+ color: req.body.color || 'blue',
+ }
+ db.createKeyword(data).then(function(keyword){
+ res.keyword = keyword
+ next()
+ })
+ },
+
/* POSTING */
verifyFilesOrComment: function (req, res, next){
@@ -308,9 +325,9 @@ var bucky = module.exports = {
}
next()
},
-
+
/* COMMENTS */
-
+
ensureComment: function (req, res, next){
var id = req.params.id.replace(/\D/g, "")
if (! id) {
@@ -442,7 +459,7 @@ var bucky = module.exports = {
/* PROFILE / USER */
-
+
ensureUser: function (req, res, next){
var username = util.sanitizeName(req.params.username)
if (! username) {
diff --git a/bucky/db/index.js b/bucky/db/index.js
index e26124a..d3ee2ea 100644
--- a/bucky/db/index.js
+++ b/bucky/db/index.js
@@ -224,7 +224,7 @@ db.getKeyword = function (keyword) {
return Keyword.query("where", "keyword", "=", keyword).fetch()
}
db.getThreadGroups = function (keyword) {
- return knex.column('keyword').sum('viewed').as('viewed').column('id').column('title').column('lastmodified').column('privacy').select().from('threads').groupBy('keyword')
+ return knex.column('keyword').sum('viewed').as('viewed').count('*').as('count').column('id').column('title').column('lastmodified').column('privacy').select().from('threads').groupBy('keyword')
}
db.createKeyword = function(data){
return new db.Keyword(data).save()