2025-01-02 19:05:25 +08:00
|
|
|
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):
|
2025-01-02 20:17:17 +08:00
|
|
|
data = json.loads(request.data)
|
2025-01-02 19:05:25 +08:00
|
|
|
|
|
|
|
try:
|
2025-01-02 20:17:17 +08:00
|
|
|
bypass = ("allow_override" in data) and data["allow_override"]
|
2025-01-02 19:05:25 +08:00
|
|
|
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)
|
2025-01-02 20:17:17 +08:00
|
|
|
response.headers.add("Access-Control-Allow-Origin", "*")
|
|
|
|
return response
|
2025-01-02 19:05:25 +08:00
|
|
|
|
|
|
|
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(
|
2025-01-02 20:17:17 +08:00
|
|
|
response=str(result),
|
2025-01-02 19:05:25 +08:00
|
|
|
status=200,
|
2025-01-02 20:17:17 +08:00
|
|
|
mimetype='text/plain'
|
2025-01-02 19:05:25 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
response.headers.add("Access-Control-Allow-Origin", "*")
|
|
|
|
return response
|