You've already forked KemoFureApi
							
							added filter by account rating
This commit is contained in:
		| @@ -49,7 +49,7 @@ class Database: | |||||||
|             result = result[-1] |             result = result[-1] | ||||||
|             return get_post_dictionary(result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7]) |             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)) |         num_posts = max(1, min(num_posts, 100)) | ||||||
|  |  | ||||||
|         where_query = "WHERE x_post_details.id NOT NULL AND x_posts.error_id = 0" |         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}" |             where_query += f" AND x_posts.id < {last_id}" | ||||||
|         if actions_taken != [0, 1, 2, 3]: |         if actions_taken != [0, 1, 2, 3]: | ||||||
|             where_query += " AND (" + " OR ".join([f"x_posts.action_taken = {action}" for action in actions_taken]) + ")" |             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''' |         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  |         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  | ||||||
|   | |||||||
| @@ -19,22 +19,32 @@ class Archive_GetPosts(Resource): | |||||||
|             response.headers.add("Access-Control-Allow-Origin", "*") |             response.headers.add("Access-Control-Allow-Origin", "*") | ||||||
|             return response    |             return response    | ||||||
|  |  | ||||||
|         param = [] |         actions = [] | ||||||
|         if "undecided" in request.args: |         if "undecided" in request.args: | ||||||
|             param.append(0) |             actions.append(0) | ||||||
|         if "approved" in request.args: |         if "approved" in request.args: | ||||||
|             param.append(1) |             actions.append(1) | ||||||
|         if "denied" in request.args: |         if "denied" in request.args: | ||||||
|             param.append(2) |             actions.append(2) | ||||||
|         if "hidden" in request.args: |         if "hidden" in request.args: | ||||||
|             param.append(3) |             actions.append(3) | ||||||
|         if param == []: |         if actions == []: | ||||||
|             param = [0,1,2,3] |             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 |         real_page = page-1 | ||||||
|         offset = real_page * count |         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: |         if result is None: | ||||||
|             response = app.response_class(status=400) |             response = app.response_class(status=400) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user