From 6b4cd4f267165b4b92253c80bc44522f55741304 Mon Sep 17 00:00:00 2001 From: katboi01 Date: Thu, 2 Jan 2025 22:12:35 +0100 Subject: [PATCH] added filter by account rating --- modules/Archive/database.py | 4 +++- modules/Archive/endpoints/get_posts.py | 26 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/modules/Archive/database.py b/modules/Archive/database.py index 9352f5c..166a40e 100644 --- a/modules/Archive/database.py +++ b/modules/Archive/database.py @@ -49,7 +49,7 @@ class Database: result = result[-1] return get_post_dictionary(result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7]) - def get_posts(self, num_posts, actions_taken = [0, 1, 2, 3], last_id = -1, offset = 0): + def get_posts(self, num_posts, actions_taken = [0, 1, 2, 3], last_id = -1, offset = 0, include_ratings = ["SFW", "NSFW"]): num_posts = max(1, min(num_posts, 100)) where_query = "WHERE x_post_details.id NOT NULL AND x_posts.error_id = 0" @@ -57,6 +57,8 @@ class Database: where_query += f" AND x_posts.id < {last_id}" if actions_taken != [0, 1, 2, 3]: where_query += " AND (" + " OR ".join([f"x_posts.action_taken = {action}" for action in actions_taken]) + ")" + if include_ratings != ["SFW", "NSFW"]: + where_query += " AND (" + " OR ".join([f'account.rating = "{rating}"' for rating in include_ratings]) + ")" query = f''' SELECT x_posts.id, x_posts.action_taken, x_post_details.text, x_post_details.files, x_post_details.date, accounts.x_handle, accounts.rating FROM x_posts diff --git a/modules/Archive/endpoints/get_posts.py b/modules/Archive/endpoints/get_posts.py index ab546e0..f300dc7 100644 --- a/modules/Archive/endpoints/get_posts.py +++ b/modules/Archive/endpoints/get_posts.py @@ -19,22 +19,32 @@ class Archive_GetPosts(Resource): response.headers.add("Access-Control-Allow-Origin", "*") return response - param = [] + actions = [] if "undecided" in request.args: - param.append(0) + actions.append(0) if "approved" in request.args: - param.append(1) + actions.append(1) if "denied" in request.args: - param.append(2) + actions.append(2) if "hidden" in request.args: - param.append(3) - if param == []: - param = [0,1,2,3] + actions.append(3) + if actions == []: + actions = [0,1,2,3] + + ratings = [] + if "SFW" in request.args: + ratings.append("SFW") + if "NSFW" in request.args: + ratings.append("NSFW") + if "NSFL" in request.args: + ratings.append("NSFL") + if ratings == []: + ratings = ["SFW", "NSFW"] real_page = page-1 offset = real_page * count - result = db.get_posts(count, param, last_id, offset) + result = db.get_posts(count, actions_taken=actions, last_id= -1, offset= offset, ratings= ratings) if result is None: response = app.response_class(status=400)