You've already forked KemoFureApi
							
							added account post count endpoint
This commit is contained in:
		
							
								
								
									
										13
									
								
								modules/Archive/endpoints/get_accounts_post_count.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								modules/Archive/endpoints/get_accounts_post_count.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| from __future__ import annotations | ||||
| from flask_restful import Resource | ||||
| from flask import current_app as app | ||||
| from typing import TYPE_CHECKING | ||||
|  | ||||
| if TYPE_CHECKING: | ||||
|     from modules.Archive.database import Database | ||||
|  | ||||
| class AccountsPostCount(Resource): | ||||
|     def get(self): | ||||
|         db : Database = app.databases["Archive"] | ||||
|         result = db.get_account_stats() | ||||
|         return db.wrap_query_response(result) | ||||
| @@ -1,27 +1,15 @@ | ||||
| from __future__ import annotations | ||||
| import json | ||||
| from flask_restful import Resource | ||||
| from flask import current_app as app, jsonify, request | ||||
| from flask import current_app as app | ||||
| from typing import TYPE_CHECKING | ||||
|  | ||||
| if TYPE_CHECKING: | ||||
|     from modules.Archive.database import Database | ||||
|  | ||||
| class Archive_GetPost(Resource): | ||||
| class GetPost(Resource): | ||||
|     def get(self, id): | ||||
|         id = int(id) | ||||
|         db : Database = app.databases["Archive"] | ||||
|  | ||||
|         result = db.get_post(id) | ||||
|  | ||||
|         if result is None: | ||||
|             response = app.response_class(status=404) | ||||
|         else: | ||||
|             response = app.response_class( | ||||
|                 response=json.dumps(result, ensure_ascii=False, indent=1), | ||||
|                 status=200, | ||||
|                 mimetype='application/json' | ||||
|             ) | ||||
|  | ||||
|         response.headers.add("Access-Control-Allow-Origin", "*") | ||||
|         return response    | ||||
|         return db.wrap_query_response(result)  | ||||
| @@ -1,13 +1,12 @@ | ||||
| from __future__ import annotations | ||||
| import json | ||||
| from flask_restful import Resource | ||||
| from flask import current_app as app, jsonify, request | ||||
| from flask import current_app as app, request | ||||
| from typing import TYPE_CHECKING | ||||
|  | ||||
| if TYPE_CHECKING: | ||||
|     from modules.Archive.database import Database | ||||
|  | ||||
| class Archive_GetPosts(Resource): | ||||
| class GetPosts(Resource): | ||||
|     def get(self): | ||||
|         db : Database = app.databases["Archive"] | ||||
|         try: | ||||
| @@ -53,15 +52,4 @@ class Archive_GetPosts(Resource): | ||||
|         offset = real_page * count | ||||
|  | ||||
|         result = db.get_posts(count, artist, actions_taken=actions, last_id= -1, offset= offset, include_ratings= ratings, order=order) | ||||
|  | ||||
|         if result is None: | ||||
|             response = app.response_class(status=400) | ||||
|         else: | ||||
|             response = app.response_class( | ||||
|                 response=json.dumps(result, ensure_ascii=False, indent=1), | ||||
|                 status=200, | ||||
|                 mimetype='application/json' | ||||
|             ) | ||||
|  | ||||
|         response.headers.add("Access-Control-Allow-Origin", "*") | ||||
|         return response    | ||||
|         return db.wrap_query_response(result) | ||||
| @@ -1,13 +1,12 @@ | ||||
| from __future__ import annotations | ||||
| import json | ||||
| from flask_restful import Resource | ||||
| from flask import current_app as app, jsonify, request | ||||
| from flask import current_app as app, request | ||||
| from typing import TYPE_CHECKING | ||||
|  | ||||
| if TYPE_CHECKING: | ||||
|     from modules.Archive.database import Database | ||||
|  | ||||
| class Archive_GetPostsCount(Resource): | ||||
| class GetPostsCount(Resource): | ||||
|     def get(self): | ||||
|         db : Database = app.databases["Archive"] | ||||
|         try: | ||||
| @@ -40,15 +39,4 @@ class Archive_GetPostsCount(Resource): | ||||
|             ratings = ["SFW", "NSFW"] | ||||
|  | ||||
|         result = db.get_posts_count(artist, actions_taken=actions, last_id= -1, include_ratings= ratings) | ||||
|  | ||||
|         if result is None: | ||||
|             response = app.response_class(status=400) | ||||
|         else: | ||||
|             response = app.response_class( | ||||
|                 response=str(result), | ||||
|                 status=200, | ||||
|                 mimetype='text/plain' | ||||
|             ) | ||||
|  | ||||
|         response.headers.add("Access-Control-Allow-Origin", "*") | ||||
|         return response    | ||||
|         return db.wrap_query_response(result, mode="text")  | ||||
| @@ -1,13 +1,12 @@ | ||||
| from __future__ import annotations | ||||
| import json | ||||
| from flask_restful import Resource | ||||
| from flask import current_app as app, jsonify, request | ||||
| from flask import current_app as app, request | ||||
| from typing import TYPE_CHECKING | ||||
|  | ||||
| if TYPE_CHECKING: | ||||
|     from modules.Archive.database import Database | ||||
|  | ||||
| class Archive_Query(Resource): | ||||
| class Query(Resource): | ||||
|     def post(self): | ||||
|         query = request.data.decode("utf-8") | ||||
|          | ||||
| @@ -15,14 +14,4 @@ class Archive_Query(Resource): | ||||
|  | ||||
|         result = db.db.run_query(query) | ||||
|  | ||||
|         if result is None: | ||||
|             response = app.response_class(status=400) | ||||
|         else: | ||||
|             response = app.response_class( | ||||
|                 response=json.dumps(result, ensure_ascii=False, indent=1), | ||||
|                 status=200, | ||||
|                 mimetype='application/json' | ||||
|             ) | ||||
|  | ||||
|         response.headers.add("Access-Control-Allow-Origin", "*") | ||||
|         return response    | ||||
|         return db.wrap_query_response(result) | ||||
| @@ -1,13 +1,13 @@ | ||||
| from __future__ import annotations | ||||
| import json | ||||
| from flask_restful import Resource | ||||
| from flask import current_app as app, jsonify, request | ||||
| from flask import current_app as app, request | ||||
| from typing import TYPE_CHECKING | ||||
|  | ||||
| if TYPE_CHECKING: | ||||
|     from modules.Archive.database import Database | ||||
|  | ||||
| class Archive_SetAction(Resource): | ||||
| class SetAction(Resource): | ||||
|     def post(self): | ||||
|         data = json.loads(request.data) | ||||
|  | ||||
| @@ -32,12 +32,4 @@ class Archive_SetAction(Resource): | ||||
|             query += " AND action_taken = 0" | ||||
|  | ||||
|         result = db.db.run_command(query) | ||||
|  | ||||
|         response = app.response_class( | ||||
|             response=str(result), | ||||
|             status=200, | ||||
|             mimetype='text/plain' | ||||
|         ) | ||||
|  | ||||
|         response.headers.add("Access-Control-Allow-Origin", "*") | ||||
|         return response    | ||||
|         return db.wrap_query_response(result, mode="text") | ||||
		Reference in New Issue
	
	Block a user