added filter by account rating

This commit is contained in:
katboi01 2025-01-02 22:12:35 +01:00
parent cbe0074c70
commit db69131681
2 changed files with 23 additions and 9 deletions

View File

@ -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
@ -68,6 +70,8 @@ class Database:
ORDER BY x_posts.id DESC
LIMIT {num_posts} OFFSET {offset}'''
print(query)
result = self.db.run_query(query)
posts = []
if result is not None:

View File

@ -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, include_ratings= ratings)
if result is None:
response = app.response_class(status=400)