You've already forked KemoFureApi
additional archive endpoints
This commit is contained in:
27
modules/Archive/endpoints/get_post.py
Normal file
27
modules/Archive/endpoints/get_post.py
Normal file
@@ -0,0 +1,27 @@
|
||||
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_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
|
||||
36
modules/Archive/endpoints/set_action.py
Normal file
36
modules/Archive/endpoints/set_action.py
Normal file
@@ -0,0 +1,36 @@
|
||||
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_SetAction(Resource):
|
||||
def post(self):
|
||||
data = request.json
|
||||
|
||||
try:
|
||||
bypass = "allow_override" in data and data["allow_override"]
|
||||
action = data["action_taken"]
|
||||
id = data["id"]
|
||||
except Exception as e:
|
||||
print(e)
|
||||
response = app.response_class(response=e, status=400)
|
||||
|
||||
db : Database = app.databases["Archive"]
|
||||
query = f"UPDATE x_posts SET action_taken = {action} WHERE id = {id}"
|
||||
if not bypass:
|
||||
query += " AND action_taken = 0"
|
||||
|
||||
result = db.db.run_command(query)
|
||||
|
||||
response = app.response_class(
|
||||
response=result,
|
||||
status=200,
|
||||
mimetype='application/json'
|
||||
)
|
||||
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
return response
|
||||
Reference in New Issue
Block a user