diff options
| author | julian laplace <julescarbon@gmail.com> | 2022-10-26 18:52:52 +0200 |
|---|---|---|
| committer | julian laplace <julescarbon@gmail.com> | 2022-10-26 18:52:52 +0200 |
| commit | b05925febcabb4caa5e1f5d4503f7ddd23708b26 (patch) | |
| tree | 55274c185498e7f123f695bac3181b642cb6a96b /bucky/app/bucky.js | |
| parent | efd2c35d432dc2426bf1fd9c849eeabdf28e40e3 (diff) | |
upgrade knex and bookshelf and fix thread/keyword apis
Diffstat (limited to 'bucky/app/bucky.js')
| -rw-r--r-- | bucky/app/bucky.js | 69 |
1 files changed, 54 insertions, 15 deletions
diff --git a/bucky/app/bucky.js b/bucky/app/bucky.js index 86982f8..a2f677a 100644 --- a/bucky/app/bucky.js +++ b/bucky/app/bucky.js @@ -75,23 +75,62 @@ var bucky = (module.exports = { offset: req.query?.offset || 0, }; query.has_query = query.thread || query.keyword || query.username; - Promise.all([ - db.getHootstreamFiles(query), - db.getHootstreamComments(query), - ]).then(([files, comments]) => { - db.getHootstreamThreads({ files, comments }).then((threads) => { - res.query = query; - res.files = files; - res.comments = comments.map((comment) => { - comment.comment = comment.comment.toString(); - return comment; + + if (query.keyword) { + db.getThreadsForKeyword(query.keyword).then((threads) => + Promise.all([ + db.getHootstreamSomeFilesForThreads(threads, 3), + db.getHootstreamSomeCommentsForThreads(threads, 1), + ]).then(([files, comments]) => { + res.query = query; + res.files = files; + res.comments = comments.map((comment) => { + comment.set("comment", comment.get("comment").toString()); + return comment; + }); + res.threads = Array.from(threads); + res.threads_ids = threads.pluck("id").sort(); + res.keywords = _.uniq(threads.pluck("keyword")); + next(); + }) + ); + } else if (query.thread) { + db.getThread(query.thread).then((thread) => + Promise.all([ + db.getHootstreamAllFilesForThread(thread), + db.getHootstreamAllCommentsForThread(thread), + ]).then(([files, comments]) => { + res.query = query; + res.files = files; + res.comments = comments.map((comment) => { + comment.set("comment", comment.get("comment").toString()); + return comment; + }); + res.threads = [thread]; + res.threads_ids = [query.thread]; + res.keywords = [thread.get("keyword")]; + next(); + }) + ); + } else { + Promise.all([ + db.getHootstreamFiles(query), + db.getHootstreamComments(query), + ]).then(([files, comments]) => { + db.getHootstreamThreads({ files, comments }).then((threads) => { + res.query = query; + res.files = files; + res.comments = comments.map((comment) => { + comment.comment = comment.comment.toString(); + return comment; + }); + res.threads = threads; + res.threads_ids = res.threads.pluck("id").sort(); + res.keywords = _.uniq(res.threads.pluck("keyword")); + next(); }); - res.threads = threads; - res.threads_ids = res.threads.pluck("id").sort(); - res.keywords = _.uniq(res.threads.pluck("keyword")); - next(); }); - }); + } }, ensureLastlog: function (req, res, next) { db.getLastlog(5).then(function (lastlog) { |
