feat: working skins and capes(animated capes not :( )

This commit is contained in:
2025-07-17 02:07:32 +05:00
parent 3d310760ba
commit 9786d6d9b1
14 changed files with 307 additions and 37 deletions

View File

@ -1,13 +1,15 @@
import base64
from datetime import datetime
import json
from fastapi import FastAPI, Depends, HTTPException, Body, Request, Response
from fastapi import FastAPI, Depends, File, Form, HTTPException, Body, Request, Response, UploadFile
from fastapi.security import OAuth2PasswordBearer
from .models import UserCreate, UserLogin, ValidateRequest
from fastapi.staticfiles import StaticFiles
from .models import UserCreate, UserLogin, ValidateRequest, SkinUpdate, CapeUpdate
from .auth import AuthService
from .database import users_collection
from .utils import decode_token
import os
from pathlib import Path
from typing import Union
from fastapi.middleware.cors import CORSMiddleware
import logging
@ -16,6 +18,14 @@ import logging
app = FastAPI()
auth_service = AuthService()
skin_dir = Path("skins")
skin_dir.mkdir(exist_ok=True)
app.mount("/skins", StaticFiles(directory="skins"), name="skins")
cape_dir = Path("capes")
cape_dir.mkdir(exist_ok=True)
app.mount("/capes", StaticFiles(directory="capes"), name="capes")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Разрешить все домены
@ -32,8 +42,10 @@ def api_root():
"implementationVersion": "1.0.0",
"links": {
"homepage": "https://your-server.com"
}
}
},
},
"skinDomains": ["147.78.65.214"],
"capeDomains": ["147.78.65.214"]
}
# Эндпоинты Mojang-like API
@ -74,6 +86,39 @@ async def join_server(request_data: dict = Body(...)):
async def has_joined(username: str, serverId: str):
return await auth_service.has_joined(username, serverId)
@app.post("/user/{username}/skin")
async def set_skin(
username: str,
skin_file: UploadFile = File(...),
skin_model: str = Form("classic")
):
return await auth_service.set_skin(username, skin_file, skin_model)
@app.delete("/user/{username}/skin")
async def remove_skin(username: str):
return await auth_service.remove_skin(username)
@app.post("/user/{username}/cape")
async def set_cape(
username: str,
cape_file: UploadFile = File(...)
):
return await auth_service.set_cape(username, cape_file)
@app.delete("/user/{username}/cape")
async def remove_cape(username: str):
return await auth_service.remove_cape(username)
@app.get("/debug/profile/{uuid}")
async def debug_profile(uuid: str):
profile = await auth_service.get_minecraft_profile(uuid)
textures = base64.b64decode(profile['properties'][0]['value']).decode()
return {
"profile": profile,
"textures_decoded": json.loads(textures)
}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)