fix skins and capes saves

This commit is contained in:
2025-12-04 01:21:07 +05:00
parent e89cb58b11
commit 3bef4f0ba0
5 changed files with 18 additions and 10 deletions

View File

@ -9,3 +9,9 @@ MONGO_URI = os.getenv("MONGO_URI")
SECRET_KEY = os.getenv("SECRET_KEY") SECRET_KEY = os.getenv("SECRET_KEY")
ALGORITHM = "HS256" ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 1440 # 24 часа ACCESS_TOKEN_EXPIRE_MINUTES = 1440 # 24 часа
BASE_DIR = Path(__file__).resolve().parent.parent # /app/app
STATIC_DIR = BASE_DIR / "static"
SKINS_DIR = STATIC_DIR / "skins"
CAPES_DIR = STATIC_DIR / "capes"
CAPES_STORE_DIR = STATIC_DIR / "capes_store"

View File

@ -1,5 +1,5 @@
from app.db.database import users_collection from app.db.database import users_collection
from app.core.config import FILES_URL from app.core.config import CAPES_DIR, FILES_URL
from fastapi import HTTPException, UploadFile from fastapi import HTTPException, UploadFile
from datetime import datetime from datetime import datetime
@ -30,7 +30,7 @@ class CapeService:
import os import os
old_url = user["cloak_url"] old_url = user["cloak_url"]
old_filename = os.path.basename(urlparse(old_url).path) old_filename = os.path.basename(urlparse(old_url).path)
old_path = os.path.join("/app/static/capes", old_filename) old_path = CAPES_DIR / old_filename
if os.path.exists(old_path): if os.path.exists(old_path):
try: try:
os.remove(old_path) os.remove(old_path)
@ -39,7 +39,7 @@ class CapeService:
# Создаем папку для плащей, если ее нет # Создаем папку для плащей, если ее нет
from pathlib import Path from pathlib import Path
cape_dir = Path("/app/static/capes") cape_dir = CAPES_DIR
cape_dir.mkdir(parents=True, exist_ok=True) cape_dir.mkdir(parents=True, exist_ok=True)
cape_filename = f"{username}_{int(datetime.now().timestamp())}.{ext}" cape_filename = f"{username}_{int(datetime.now().timestamp())}.{ext}"

View File

@ -1,7 +1,7 @@
from fastapi import HTTPException, UploadFile from fastapi import HTTPException, UploadFile
from datetime import datetime from datetime import datetime
from app.db.database import users_collection from app.db.database import users_collection
from app.core.config import FILES_URL from app.core.config import FILES_URL, SKINS_DIR
class SkinService: class SkinService:
async def set_skin(self, username: str, skin_file: UploadFile, skin_model: str = "classic"): async def set_skin(self, username: str, skin_file: UploadFile, skin_model: str = "classic"):
@ -24,7 +24,7 @@ class SkinService:
old_url = user["skin_url"] old_url = user["skin_url"]
# Получаем имя файла из url # Получаем имя файла из url
old_filename = os.path.basename(urlparse(old_url).path) old_filename = os.path.basename(urlparse(old_url).path)
old_path = os.path.join("app/static/skins", old_filename) old_path = SKINS_DIR / old_filename
print(f"Trying to delete old skin at: {old_path}") print(f"Trying to delete old skin at: {old_path}")
if os.path.exists(old_path): if os.path.exists(old_path):
try: try:
@ -34,7 +34,7 @@ class SkinService:
# Создаем папку для скинов, если ее нет # Создаем папку для скинов, если ее нет
from pathlib import Path from pathlib import Path
skin_dir = Path("/app/static/skins") skin_dir = SKINS_DIR
skin_dir.mkdir(parents=True, exist_ok=True) skin_dir.mkdir(parents=True, exist_ok=True)
# Генерируем имя файла # Генерируем имя файла

View File

@ -8,7 +8,7 @@ services:
- "3001:3000" - "3001:3000"
user: "${UID:-1000}:${GID:-1000}" user: "${UID:-1000}:${GID:-1000}"
volumes: volumes:
- ./app/static:/app/static:rw - ./app/static:/app/app/static:rw
env_file: env_file:
- .env - .env
depends_on: depends_on:

View File

@ -3,6 +3,8 @@ from fastapi.staticfiles import StaticFiles
from app.api import users, skins, capes, meta, server, store, pranks, marketplace, bonuses from app.api import users, skins, capes, meta, server, store, pranks, marketplace, bonuses
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from app.core.config import CAPES_DIR, CAPES_STORE_DIR, SKINS_DIR
app = FastAPI() app = FastAPI()
app.include_router(meta.router) app.include_router(meta.router)
@ -16,9 +18,9 @@ app.include_router(marketplace.router)
app.include_router(bonuses.router) app.include_router(bonuses.router)
# Монтируем статику # Монтируем статику
app.mount("/skins", StaticFiles(directory="app/static/skins"), name="skins") app.mount("/skins", StaticFiles(directory=str(SKINS_DIR)), name="skins")
app.mount("/capes", StaticFiles(directory="app/static/capes"), name="capes") app.mount("/capes", StaticFiles(directory=str(CAPES_DIR)), name="capes")
app.mount("/capes_store", StaticFiles(directory="app/static/capes_store"), name="capes_store") app.mount("/capes_store", StaticFiles(directory=str(CAPES_STORE_DIR)), name="capes_store")
# CORS, middleware и т.д. # CORS, middleware и т.д.
app.add_middleware( app.add_middleware(