From dd72ab05da17309fd5ee6005cdc1fae686b5fa9e Mon Sep 17 00:00:00 2001 From: julian laplace Date: Wed, 26 Oct 2022 17:05:14 +0200 Subject: filter by keyword, thread, or username --- bucky/db/index.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'bucky/db') diff --git a/bucky/db/index.js b/bucky/db/index.js index 36541f8..2a1a3bf 100644 --- a/bucky/db/index.js +++ b/bucky/db/index.js @@ -116,19 +116,41 @@ db.getLastlog = function (limit) { /** HOOTSTREAM */ -db.getHootstreamFiles = ({ limit, offset }) => +db.getHootstreamFiles = ({ limit, offset, thread, keyword, username }) => knex("files") .join("threads", "threads.id", "=", "files.thread") .select("files.*") - .where("threads.privacy", false) + .where((builder) => { + builder.where("threads.privacy", false); + if (keyword) { + builder.where("threads.keyword", keyword); + } + if (thread) { + builder.where("threads.id", thread); + } + if (username) { + builder.where("comments.username", username); + } + }) .orderBy("files.id", "desc") .offset(offset) .limit(limit); -db.getHootstreamComments = ({ limit, offset }) => +db.getHootstreamComments = ({ limit, offset, thread, keyword, username }) => knex("comments") .join("threads", "threads.id", "=", "comments.thread") .select("comments.*") - .where("threads.privacy", false) + .where((builder) => { + builder.where("threads.privacy", false); + if (keyword) { + builder.where("threads.keyword", keyword); + } + if (thread) { + builder.where("threads.id", thread); + } + if (username) { + builder.where("comments.username", username); + } + }) .orderBy("comments.id", "desc") .offset(offset) .limit(limit); -- cgit v1.2.3-70-g09d2