KemoFureApi/modules/Archive/endpoints/posts_count.py

77 lines
2.5 KiB
Python

from __future__ import annotations
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 GetPostsCount(Resource):
def get(self):
db : Database = app.databases["Archive"]
try:
artist = request.args["artist"] if "artist" in request.args else None
except:
response = app.response_class(status=400)
response.headers.add("Access-Control-Allow-Origin", "*")
return response
actions = []
if "undecided" in request.args:
actions.append(0)
if "approved" in request.args:
actions.append(1)
if "denied" in request.args:
actions.append(2)
if "hidden" in request.args:
actions.append(3)
if actions == []:
actions = [0,1,2,3]
ratings = []
if "SFW" in request.args:
ratings.append("SFW")
if "NSFW" in request.args:
ratings.append("NSFW")
if "NSFL" in request.args:
ratings.append("NSFL")
if ratings == []:
ratings = ["SFW", "NSFW"]
result = db.get_posts_count(artist, actions_taken=actions, last_id= -1, include_ratings= ratings)
return db.wrap_query_response(result, mode="text")
class GetPostsCountOld(Resource):
def get(self):
db : Database = app.databases["ArchiveOld"]
try:
artist = request.args["artist"] if "artist" in request.args else None
except:
response = app.response_class(status=400)
response.headers.add("Access-Control-Allow-Origin", "*")
return response
actions = []
if "undecided" in request.args:
actions.append(0)
if "approved" in request.args:
actions.append(1)
if "denied" in request.args:
actions.append(2)
if "hidden" in request.args:
actions.append(3)
if actions == []:
actions = [0,1,2,3]
ratings = []
if "SFW" in request.args:
ratings.append("SFW")
if "NSFW" in request.args:
ratings.append("NSFW")
if "NSFL" in request.args:
ratings.append("NSFL")
if ratings == []:
ratings = ["SFW", "NSFW"]
result = db.get_posts_count(artist, actions_taken=actions, last_id= -1, include_ratings= ratings)
return db.wrap_query_response(result, mode="text")