Initial Commit.

ADD: Get User By Id
ADD: Get Release By Id
This commit is contained in:
Kentai Radiquum 2024-04-16 23:41:52 +05:00
commit 025ef2be93
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
5 changed files with 110 additions and 0 deletions

9
.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
# Python
__pycache__
venv
# VSCode
.VSCode
# NextJS
node_modules

View file

@ -0,0 +1,36 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black
args: [--safe]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: debug-statements
language_version: python3
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
language_version: python3
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.12.0
hooks:
- id: reorder-python-imports
args: [--py39-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py39-plus]

1
backend/.python-version Normal file
View file

@ -0,0 +1 @@
3.9.13

60
backend/main.py Normal file
View file

@ -0,0 +1,60 @@
import requests
from fastapi import FastAPI
from fastapi import Request
app = FastAPI()
API_URL = "https://api.anixart.tv"
ENDPOINTS = {
"release": f"{API_URL}/release",
"profile": f"{API_URL}/profile",
}
USER_AGENT = "AnixartApp/8.2.1-23121216 (Android 11; SDK 30; arm64-v8a;)"
async def apiRequest(
# noqa: E501
request: Request = None,
endpoint: str = "",
path: str = "",
query: str = "",
):
headers = {
"User-Agent": USER_AGENT,
"Content-Type": "application/json; charset=UTF-8",
}
if request.method == "POST":
r = requests.post(
# noqa: E501
f"{endpoint}/{path}{query}",
headers=headers,
data=await request.body(),
)
else:
r = requests.get(f"{endpoint}/{path}{query}", headers=headers)
if r.status_code != 200:
return {"error": r.text}
return r.json()
@app.get("/profile/{user_id}")
async def getUserById(request: Request, user_id: str, short: bool = False):
res = await apiRequest(request, ENDPOINTS["profile"], user_id)
if short is False:
return res
return {
"code": res["code"],
"profile": {
"id": res["profile"]["id"],
"login": res["profile"]["login"],
"avatar": res["profile"]["avatar"],
},
}
@app.get("/release/{release_id}")
async def GetReleaseById(request: Request, release_id: str):
return await apiRequest(request, ENDPOINTS["release"], release_id)

4
backend/requirements.txt Normal file
View file

@ -0,0 +1,4 @@
requests == 2.31.0
fastAPI == 0.110.1
uvicorn[standard]
pre-commit