worikng base version

This commit is contained in:
2025-07-16 21:19:02 +05:00
parent c6d78e3648
commit 3d310760ba
2 changed files with 106 additions and 17 deletions

View File

@ -1,11 +1,17 @@
from fastapi import FastAPI, Depends, HTTPException, Body
import base64
from datetime import datetime
import json
from fastapi import FastAPI, Depends, HTTPException, Body, Request, Response
from fastapi.security import OAuth2PasswordBearer
from .models import UserCreate, UserLogin, ValidateRequest
from .auth import AuthService
from .database import users_collection
from .utils import decode_token
import os
from typing import Union
from fastapi.middleware.cors import CORSMiddleware
import logging
# logging.basicConfig(level=logging.DEBUG)
app = FastAPI()
auth_service = AuthService()
@ -51,23 +57,22 @@ async def refresh_token(access_token: str, client_token: str):
raise HTTPException(status_code=401, detail="Invalid tokens")
return result
# Эндпоинт для проверки скинов (Minecraft использует его)
@app.get("/session/hasJoined")
async def has_joined(username: str, serverId: str):
user = await users_collection.find_one({"username": username})
if not user:
raise HTTPException(status_code=404, detail="User not found")
@app.get("/sessionserver/session/minecraft/profile/{uuid}")
async def get_minecraft_profile(uuid: str, unsigned: bool = False):
return await auth_service.get_minecraft_profile(uuid)
return {
"id": user["uuid"],
"name": username,
"properties": [
{
"name": "textures",
"value": "base64_encoded_skin_data", # Здесь можно добавить скины
}
],
}
@app.post("/sessionserver/session/minecraft/join")
async def join_server(request_data: dict = Body(...)):
try:
await auth_service.join_server(request_data)
return Response(status_code=204)
except Exception as e:
print("Error in join_server:", str(e))
raise
@app.get("/sessionserver/session/minecraft/hasJoined")
async def has_joined(username: str, serverId: str):
return await auth_service.has_joined(username, serverId)
if __name__ == "__main__":
import uvicorn