38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
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 |