added artist filter

This commit is contained in:
katboi01 2025-01-02 23:19:52 +01:00
parent db728f21ba
commit 6157eb1e40
2 changed files with 5 additions and 2 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, include_ratings = ["SFW", "NSFW"]):
def get_posts(self, num_posts, artist, 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"
@ -59,6 +59,8 @@ class Database:
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'accounts.rating = "{rating}"' for rating in include_ratings]) + ")"
if artist is not None and artist != "":
where_query += f' AND accounts.x_handle = "{artist}"'
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

View File

@ -13,6 +13,7 @@ class Archive_GetPosts(Resource):
try:
count = int(request.args["count"]) if "count" in request.args else 20
page = int(request.args["page"]) if "page" in request.args else 1
artist = request.args["artist"] if "artist" in request.args else None
last_id = int(request.args["last_id"]) if "last_id" in request.args else -1
except:
response = app.response_class(status=400)
@ -44,7 +45,7 @@ class Archive_GetPosts(Resource):
real_page = page-1
offset = real_page * count
result = db.get_posts(count, actions_taken=actions, last_id= -1, offset= offset, include_ratings= ratings)
result = db.get_posts(count, artist, actions_taken=actions, last_id= -1, offset= offset, include_ratings= ratings)
if result is None:
response = app.response_class(status=400)