mirror of
https://github.com/ReVanced/revanced-api.git
synced 2026-01-20 01:43:57 +00:00
feat: info endpoint (#71)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -4,7 +4,8 @@ from sanic import Blueprint
|
||||
from api.github import github
|
||||
from api.ping import ping
|
||||
from api.socials import socials
|
||||
from api.info import info
|
||||
from api.compat import github as old
|
||||
from api.donations import donations
|
||||
|
||||
api = Blueprint.group(ping, github, socials, donations, old, url_prefix="/")
|
||||
api = Blueprint.group(ping, github, info, socials, donations, old, url_prefix="/")
|
||||
|
||||
31
api/info.py
Normal file
31
api/info.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
This module provides a blueprint for the info endpoint.
|
||||
|
||||
Routes:
|
||||
- GET /info: Get info about the owner of the API.
|
||||
"""
|
||||
|
||||
from sanic import Blueprint, Request
|
||||
from sanic.response import JSONResponse, json
|
||||
from sanic_ext import openapi
|
||||
|
||||
from api.models.info import InfoResponseModel
|
||||
from config import api_version, default_info
|
||||
|
||||
info: Blueprint = Blueprint("info", version=api_version)
|
||||
|
||||
|
||||
@info.get("/info")
|
||||
@openapi.definition(
|
||||
summary="Information about the API",
|
||||
response=[InfoResponseModel],
|
||||
)
|
||||
async def root(request: Request) -> JSONResponse:
|
||||
"""
|
||||
Returns a JSONResponse with a dictionary containing info about the owner of the API.
|
||||
|
||||
**Returns:**
|
||||
- JSONResponse: A Sanic JSONResponse instance containing a dictionary with the info about the owner of the API.
|
||||
"""
|
||||
data: dict[str, dict] = {"info": default_info}
|
||||
return json(data, status=200)
|
||||
23
api/models/info.py
Normal file
23
api/models/info.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from api.models.donations import DonationFields
|
||||
from api.models.socials import SocialFields
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class InfoFields(BaseModel):
|
||||
"""
|
||||
Implements the fields for a API owner info.
|
||||
"""
|
||||
|
||||
name: str
|
||||
about: str
|
||||
contact: dict[str, str]
|
||||
socials: SocialFields
|
||||
donations: DonationFields
|
||||
|
||||
|
||||
class InfoResponseModel(BaseModel):
|
||||
"""
|
||||
A Pydantic BaseModel that represents a dictionary of info.
|
||||
"""
|
||||
|
||||
info: InfoFields
|
||||
@@ -1,7 +1,7 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class SocialField(BaseModel):
|
||||
class SocialFields(BaseModel):
|
||||
"""
|
||||
Implements the fields for a social network link.
|
||||
"""
|
||||
@@ -15,7 +15,7 @@ class SocialsResponseModel(BaseModel):
|
||||
A Pydantic BaseModel that represents a dictionary of social links.
|
||||
"""
|
||||
|
||||
socials: list[SocialField]
|
||||
socials: list[SocialFields]
|
||||
"""
|
||||
A dictionary where the keys are the names of the social networks, and
|
||||
the values are the links to the profiles or pages.
|
||||
|
||||
Reference in New Issue
Block a user