35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from __future__ import annotations
|
|
import json
|
|
from flask_restful import Resource
|
|
from flask import current_app as app, request
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from modules.Archive.database import Database
|
|
|
|
class SetAction(Resource):
|
|
def post(self):
|
|
data = json.loads(request.data)
|
|
|
|
try:
|
|
bypass = ("allow_override" in data) and data["allow_override"]
|
|
action = data["action_taken"]
|
|
if "id_str" in data:
|
|
id = int(data["id_str"])
|
|
elif "id" in data:
|
|
id = data["id"]
|
|
else:
|
|
raise Exception("no id (int) or id_str (str) specified")
|
|
except Exception as e:
|
|
print(e)
|
|
response = app.response_class(response=e, status=400)
|
|
response.headers.add("Access-Control-Allow-Origin", "*")
|
|
return response
|
|
|
|
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)
|
|
return db.wrap_query_response(result, mode="text") |