You've already forked KemoFureApi
							
							added get_posts endpoint
This commit is contained in:
		
							
								
								
									
										38
									
								
								modules/Archive/endpoints/get_posts.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								modules/Archive/endpoints/get_posts.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| from __future__ import annotations | ||||
| import json | ||||
| from flask_restful import Resource | ||||
| from flask import current_app as app, jsonify, request | ||||
| from typing import TYPE_CHECKING | ||||
|  | ||||
| if TYPE_CHECKING: | ||||
|     from modules.Archive.database import Database | ||||
|  | ||||
| class Archive_GetPosts(Resource): | ||||
|     def get(self): | ||||
|         db : Database = app.databases["Archive"] | ||||
|         count = request.args["count"] if "count" in request.args else 10 | ||||
|         last_id = request.args["last_id"] if "last_id" in request.args else -1 | ||||
|  | ||||
|         param = [] | ||||
|         if "undecided" in request.args: | ||||
|             param.append(0) | ||||
|         if "approved" in request.args: | ||||
|             param.append(1) | ||||
|         if "denied" in request.args: | ||||
|             param.append(2) | ||||
|         if param == []: | ||||
|             param = [0,1,2] | ||||
|  | ||||
|         result = db.get_posts(count, param, last_id) | ||||
|  | ||||
|         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    | ||||
		Reference in New Issue
	
	Block a user