refactoring

This commit is contained in:
2025-07-17 03:45:44 +05:00
parent b79b0ae69f
commit 733977f56e
25 changed files with 300 additions and 363 deletions

0
app/api/__init__.py Normal file
View File

12
app/api/capes.py Normal file
View File

@ -0,0 +1,12 @@
from fastapi import APIRouter, UploadFile, File
from app.services.cape import CapeService
router = APIRouter(tags=["Capes"])
@router.post("/user/{username}/cape")
async def set_cape(username: str, cape_file: UploadFile = File(...)):
return await CapeService().set_cape(username, cape_file)
@router.delete("/user/{username}/cape")
async def remove_cape(username: str):
return await CapeService().remove_cape(username)

18
app/api/meta.py Normal file
View File

@ -0,0 +1,18 @@
from fastapi import APIRouter
router = APIRouter(tags=["Meta"])
@router.get("/")
def api_root():
return {
"meta": {
"serverName": "Your Auth Server",
"implementationName": "FastAPI",
"implementationVersion": "1.0.0",
"links": {
"homepage": "https://your-server.com"
},
},
"skinDomains": ["147.78.65.214"],
"capeDomains": ["147.78.65.214"]
}

12
app/api/skins.py Normal file
View File

@ -0,0 +1,12 @@
from fastapi import APIRouter, UploadFile, File, Form
from app.services.skin import SkinService
router = APIRouter(tags=["Skins"])
@router.post("/user/{username}/skin")
async def set_skin(username: str, skin_file: UploadFile = File(...), skin_model: str = Form("classic")):
return await SkinService().set_skin(username, skin_file, skin_model)
@router.delete("/user/{username}/skin")
async def remove_skin(username: str):
return await SkinService().remove_skin(username)

47
app/api/users.py Normal file
View File

@ -0,0 +1,47 @@
from fastapi import APIRouter, HTTPException, Body, Response
from app.models.user import UserCreate, UserLogin
from app.models.request import ValidateRequest
from app.services.auth import AuthService
router = APIRouter(
tags=["Users"]
)
@router.post("/auth/register")
async def register(user: UserCreate):
"""Регистрация нового пользователя"""
return await AuthService().register(user)
@router.post("/auth/authenticate")
async def authenticate(credentials: UserLogin):
"""Аутентификация пользователя"""
return await AuthService().login(credentials)
@router.post("/auth/validate")
async def validate_token(request: ValidateRequest):
is_valid = await AuthService().validate(request.accessToken, request.clientToken)
return {"valid": is_valid}
@router.post("/auth/refresh")
async def refresh_token(access_token: str, client_token: str):
result = await AuthService().refresh(access_token, client_token)
if not result:
raise HTTPException(status_code=401, detail="Invalid tokens")
return result
@router.get("/sessionserver/session/minecraft/profile/{uuid}")
async def get_minecraft_profile(uuid: str, unsigned: bool = False):
return await AuthService().get_minecraft_profile(uuid)
@router.post("/sessionserver/session/minecraft/join")
async def join_server(request_data: dict = Body(...)):
try:
await AuthService().join_server(request_data)
return Response(status_code=204)
except Exception as e:
print("Error in join_server:", str(e))
raise
@router.get("/sessionserver/session/minecraft/hasJoined")
async def has_joined(username: str, serverId: str):
return await AuthService().has_joined(username, serverId)