You've already forked KemoFureApi
added GetPosts/Count endpoint
This commit is contained in:
54
modules/Archive/endpoints/get_posts_count.py
Normal file
54
modules/Archive/endpoints/get_posts_count.py
Normal file
@@ -0,0 +1,54 @@
|
||||
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_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)
|
||||
|
||||
if result is None:
|
||||
response = app.response_class(status=400)
|
||||
else:
|
||||
response = app.response_class(
|
||||
response=str(result),
|
||||
status=200,
|
||||
mimetype='text/plain'
|
||||
)
|
||||
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
return response
|
||||
Reference in New Issue
Block a user