diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-04-04 20:57:43 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-04-04 20:57:43 +0200 |
| commit | 932fe6e61b0f7d1a94a9dd9b965637d0b3a699e4 (patch) | |
| tree | c8f3e496e454e89149384b32e437ecec87d1dfdf | |
| parent | 400cdb804dc0fe967393edd338ec8c094c4b0998 (diff) | |
stub sdk. add keywords fix. stub users
| -rw-r--r-- | bucky/app/api.js | 8 | ||||
| -rw-r--r-- | bucky/app/bucky.js | 15 | ||||
| -rw-r--r-- | bucky/app/pages.js | 7 | ||||
| -rw-r--r-- | bucky/db/index.js | 27 | ||||
| -rw-r--r-- | public/assets/js/lib/router.js | 8 | ||||
| -rw-r--r-- | public/assets/js/lib/views/keywords/keywords.js | 13 | ||||
| -rw-r--r-- | public/assets/js/lib/views/users/users.js | 76 | ||||
| -rw-r--r-- | sdk/auth.js | 1 | ||||
| -rw-r--r-- | sdk/index.js | 28 | ||||
| -rw-r--r-- | views/pages/users.ejs | 30 | ||||
| -rw-r--r-- | views/partials/scripts.ejs | 2 |
11 files changed, 207 insertions, 8 deletions
diff --git a/bucky/app/api.js b/bucky/app/api.js index b4231e7..a6aa83f 100644 --- a/bucky/app/api.js +++ b/bucky/app/api.js @@ -34,6 +34,12 @@ function route (app){ function(req, res){ res.json(util.sanitizeUser(res.user)) }) + app.get("/api/users", + middleware.ensureAuthenticated, + bucky.ensureUserlist, + function(req, res) { + res.json(res.users) + }) app.get("/api/profile/:username", middleware.ensureAuthenticated, bucky.ensureUser, @@ -259,9 +265,11 @@ function route (app){ middleware.ensureAuthenticated, bucky.ensureKeywords, bucky.ensureThreadGroups, + bucky.ensureLatestKeywordThreads, function(req, res){ res.json({ keywords: res.keywords, + threads: res.threads, threadGroups: res.threadGroups, }) }) diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 3824c5e..8ff0b15 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -296,6 +296,12 @@ var bucky = module.exports = { next() }) }, + ensureLatestKeywordThreads: function (req, res, next){ + db.getLatestKeywordThreads().then(function(threads){ + res.threads = threads + next() + }) + }, ensureThreadGroups: function (req, res, next){ db.getThreadGroups().then(function(threadGroups){ res.threadGroups = threadGroups @@ -564,6 +570,15 @@ var bucky = module.exports = { } }) }, + ensureUserlist: function (req, res, next){ + db.getUsers().then(function(users){ + if (! users) { + return res.sendStatus(404) + } + res.users = users + next() + }) + }, sanitizeUser: function(req, res, next) { res.user = util.sanitizeUser(res.user) next() diff --git a/bucky/app/pages.js b/bucky/app/pages.js index 7f666be..b007742 100644 --- a/bucky/app/pages.js +++ b/bucky/app/pages.js @@ -73,6 +73,13 @@ function route (app){ res.render("pages/profile_form", {title: "edit your profile"}) }) + app.get("/users", + middleware.ensureAuthenticated, + function(req, res){ + res.render("pages/users", { + }) + }) + app.get("/search/", middleware.ensureAuthenticated, function(req, res){ diff --git a/bucky/db/index.js b/bucky/db/index.js index f454c92..53e36dd 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -55,8 +55,13 @@ db.createUser = function(data){ } db.getUsers = function () { return User.query(function(qb){ - qb.orderBy("id", "desc") - }).fetchAll() + qb.orderBy("username", "desc") + }).fetchAll({ + columns: [ + "id", "username", "realname", "firstseen", "lastseen", + "location", "website", "avatar", + ] + }) } db.getUser = function(id) { var model = new User({'id': id}) @@ -281,8 +286,24 @@ db.getKeyword = function (keyword) { return Keyword.query("where", "keyword", "=", keyword).fetch() } db.getThreadGroups = function (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') + return ( + knex.column('keyword') + .sum('viewed').as('viewed') + .count('*').as('count') + .select().from('threads').groupBy('keyword') + ) } +db.getLatestKeywordThreads = function (keyword) { + var ids = knex('threads').max('id').groupBy('keyword') + return ( + knex.select('id', 'keyword', 'title', 'lastmodified', 'privacy').from('threads').where('id', 'in', ids) + ) +} + // .column('id') + // .column('title') + // .column('lastmodified') + // .column('privacy') + db.createKeyword = function(data){ return new db.Keyword(data).save() } diff --git a/public/assets/js/lib/router.js b/public/assets/js/lib/router.js index b6eff73..f856283 100644 --- a/public/assets/js/lib/router.js +++ b/public/assets/js/lib/router.js @@ -22,7 +22,8 @@ var SiteRouter = Router.extend({ "/mail/compose/:username": 'compose', "/mail/read/:id": 'message', "/mail/reply/:id": 'compose', - "/profile": 'profile', + "/users": 'users', + "/profile": 'profile', "/profile/:username": 'profile', "/profile/:username/edit": 'editProfile', "/adminz": 'adminz', @@ -85,6 +86,11 @@ var SiteRouter = Router.extend({ app.view.load(keyword || "") }, + users: function(username){ + app.view = new UsersView () + app.view.load() + }, + profile: function(username){ app.view = new ProfileView () app.view.load(username || auth.user.username) diff --git a/public/assets/js/lib/views/keywords/keywords.js b/public/assets/js/lib/views/keywords/keywords.js index 12bd5a8..c5a9491 100644 --- a/public/assets/js/lib/views/keywords/keywords.js +++ b/public/assets/js/lib/views/keywords/keywords.js @@ -19,16 +19,21 @@ var KeywordsView = View.extend({ populate: function(data){ // console.log(data) var keywordThreads = {} - data.threadGroups.forEach(kw => { + var keywordStats = {} + data.threads.forEach(kw => { keywordThreads[kw.keyword] = kw }) + data.threadGroups.forEach(kw => { + keywordStats[kw.keyword] = kw + }) data.keywords .map(a => [parseInt((keywordThreads[a.keyword] || {})['sum(`viewed`)']) || 0, a]) .sort((b,a) => cmp(a[0], b[0])) .map(a => a[1]) .forEach(keyword => { var thread = keywordThreads[keyword.keyword.toLowerCase()] || { - title: '', + } + var stats = keywordStats[keyword.keyword.toLowerCase()] || { } // { // keyword: "warez", @@ -38,9 +43,9 @@ var KeywordsView = View.extend({ // lastmodified: 1192401724 // }, // console.log(keyword, thread) - var viewed = thread['sum(`viewed`)'] + var viewed = stats['sum(`viewed`)'] var views = viewed ? hush_views(viewed) : ['',''] - var threadCountNum = thread['count(*)'] + var threadCountNum = stats['count(*)'] var threadCount = threadCountNum ? hush_threads(threadCountNum) : ['',''] var dot = privacy_dot(thread.privacy) var datetime = verbose_date(keyword.createdate) diff --git a/public/assets/js/lib/views/users/users.js b/public/assets/js/lib/views/users/users.js new file mode 100644 index 0000000..f3c0ef5 --- /dev/null +++ b/public/assets/js/lib/views/users/users.js @@ -0,0 +1,76 @@ +var UsersView = View.extend({ + + el: "#users_list", + + events: { + }, + + action: "/api/users", + + initialize: function(opt){ + this.template = this.$(".template").html() + this.form = new NewKeywordForm ({ parent: this }) + }, + + load: function(){ + $.get(this.action, this.populate.bind(this)) + }, + + populate: function(data){ + // console.log(data) + var keywordThreads = {} + data.threadGroups.forEach(kw => { + keywordThreads[kw.keyword] = kw + }) + data.keywords + .map(a => [parseInt((keywordThreads[a.keyword] || {})['sum(`viewed`)']) || 0, a]) + .sort((b,a) => cmp(a[0], b[0])) + .map(a => a[1]) + .forEach(keyword => { + var thread = keywordThreads[keyword.keyword.toLowerCase()] || { + title: '', + } + // { + // keyword: "warez", + // sum(`viewed`): "498", + // id: 701, + // title: "EMS SYNTHI PLUG FOR MAC", + // lastmodified: 1192401724 + // }, + // console.log(keyword, thread) + var viewed = thread['sum(`viewed`)'] + var views = viewed ? hush_views(viewed) : ['',''] + var threadCountNum = thread['count(*)'] + var threadCount = threadCountNum ? hush_threads(threadCountNum) : ['',''] + var dot = privacy_dot(thread.privacy) + var datetime = verbose_date(keyword.createdate) + var age = get_age(thread.lastmodified) + var id = thread.id + get_revision(thread) + var t = this.template + .replace(/{{keyword}}/g, sanitizeHTML(keyword.keyword)) + .replace(/{{id}}/g, id) + .replace(/{{username}}/g, keyword.username) + .replace(/{{privacy_dot}}/g, dot) + .replace(/{{title}}/g, thread.title) + .replace(/{{date}}/g, datetime[0]) + .replace(/{{time}}/g, datetime[1]) + .replace(/{{date_class}}/g, carbon_date(thread.lastmodified) ) + .replace(/{{views}}/g, views[1]) + .replace(/{{threadcount}}/, threadCount[1]) + .replace(/{{threadcount_class}}/, threadCount[0]) +// .replace(/{{comments}}/g, comments[1]) +// .replace(/{{files}}/g, files[1]) +// .replace(/{{size}}/g, size[1] ) + .replace(/{{views_class}}/g, views[0]) +// .replace(/{{comments_class}}/g, comments[0]) +// .replace(/{{files_class}}/g, files[0]) +// .replace(/{{show_files}}/g, thread.file_count == 0 ? "hidden" : "") +// .replace(/{{size_class}}/g, size[0] ) + .replace(/{{color}}/g, thread.color || "blue" ) + + this.$el.append(t) + }) + $("body").removeClass('loading') + }, + +}) diff --git a/sdk/auth.js b/sdk/auth.js new file mode 100644 index 0000000..72d38f1 --- /dev/null +++ b/sdk/auth.js @@ -0,0 +1 @@ +auth.js
\ No newline at end of file diff --git a/sdk/index.js b/sdk/index.js new file mode 100644 index 0000000..0c92f0c --- /dev/null +++ b/sdk/index.js @@ -0,0 +1,28 @@ +// bucky 3.0.0 sdk + +let env = 'development' +let endpoint = 'http://localhost:5000/' + +export function init(opt){ + env = opt.env || env + endpoint = opt.endpoint || endpoint + + switch (env) { + case 'test': + break + default: + case 'development': + break + case 'production': + break + } +} + +export function path(api){ + return endpoint + api +} + +export function image(file, size){ + return "https://" + sdk.opt.s3.bucket + sdk.opt.s3.path + "/data/" + file.thread + "/" + file.id +} + diff --git a/views/pages/users.ejs b/views/pages/users.ejs new file mode 100644 index 0000000..f18b254 --- /dev/null +++ b/views/pages/users.ejs @@ -0,0 +1,30 @@ +<% include ../partials/header %> + +<div class="subtitle"></div> + +<div id="content"> + <div id="user_list"> + <script type="text/html" class="template"> + <div class="user_row"> + <div class="username"><a href="/profile/{{username}}">{{username}}</a></div> + <div class='dot'> + · + </div> + <div class="date {{date_class}}"> + member since {{date}} <small>{{time}}</small> + </div> + <div class="threadcount {{threadcount_class}}"> + {{threadcount}} + </div> + <div class="filecount {{filecount_class}}"> + {{filecount}} + </div> + <div class="commentcount {{commentcount_class}}"> + {{commentcount}} + </div> + </div> + </script> + </div> +</div> + +<% include ../partials/footer %> diff --git a/views/partials/scripts.ejs b/views/partials/scripts.ejs index 765594b..765bf61 100644 --- a/views/partials/scripts.ejs +++ b/views/partials/scripts.ejs @@ -38,6 +38,8 @@ <script src="/assets/js/lib/views/profile/profile.js"></script> <script src="/assets/js/lib/views/profile/profile_edit.js"></script> +<script src="/assets/js/lib/views/users/users.js"></script> + <script src="/assets/js/lib/views/details/details.js"></script> <script src="/assets/js/lib/views/details/settings.js"></script> <script src="/assets/js/lib/views/details/comments.js"></script> |
