иним чиним чиним чиним а так же новая система друзей и бутстраппера

This commit is contained in:
SashegDev
2026-06-07 12:32:34 +00:00
parent 166dbf8935
commit ec7ef01760
25 changed files with 3732 additions and 377 deletions
+78 -11
View File
@@ -28,6 +28,8 @@ from log_manager import init_logging
from auth import get_current_user, router as auth_router, init_db, verify_jwt
from roles import Permissions, has_permission
from admin_router import router as admin_router
from friends import router as friends_router, init_friends_db
from playtime import router as playtime_router, init_playtime_db
import asyncio
import hashlib
@@ -143,6 +145,8 @@ async def lifespan(app: FastAPI):
DATA_DIR.mkdir(exist_ok=True)
init_db()
init_friends_db()
init_playtime_db()
if args.test:
await run_test_mode()
@@ -754,6 +758,8 @@ async def send_file_async(
# Register routers
app.include_router(auth_router)
app.include_router(admin_router)
app.include_router(friends_router)
app.include_router(playtime_router)
# Monkey patch to catch invalid HTTP requests
@@ -842,17 +848,23 @@ async def list_packs(
updated_at = meta.get("updated_at")
if updated_at and isinstance(updated_at, datetime):
updated_at = updated_at.isoformat()
packs.append({
"name": pack_dir.name,
"version": meta.get("version", 1),
"files_count": len(meta.get("files", {})),
"updated_at": updated_at,
"minecraft_version": meta.get("minecraft_version", "unknown"),
"loader_type": meta.get("loader_type", "vanilla"),
"loader_version": meta.get("loader_version"),
"asset_index": meta.get("asset_index")
})
desc_path = pack_dir / "description.txt"
description = ""
if desc_path.exists():
description = desc_path.read_text(encoding="utf-8")
packs.append({
"name": pack_dir.name,
"version": meta.get("version", 1),
"files_count": len(meta.get("files", {})),
"updated_at": updated_at,
"minecraft_version": meta.get("minecraft_version", "unknown"),
"loader_type": meta.get("loader_type", "vanilla"),
"loader_version": meta.get("loader_version"),
"asset_index": meta.get("asset_index"),
"description": description
})
except Exception as e:
logger.error(f"Failed to load pack meta for {pack_dir.name}: {e}")
packs.append({
@@ -1698,6 +1710,61 @@ async def get_launcher_full_info():
return info
# ====================== НОВОСТИ ======================
NEWS_DIR = Path(__file__).parent / "news"
@app.get("/news")
async def list_news():
"""List all news files with their content"""
if not NEWS_DIR.exists():
return {"news": []}
news_list = []
for f in sorted(NEWS_DIR.iterdir()):
if f.is_file() and f.suffix == ".txt":
try:
content = f.read_text(encoding="utf-8").strip().split("\n")
if len(content) >= 4:
title = content[0].strip()
news_type = content[1].strip()
version = content[2].strip()
body = "\n".join(content[3:]).strip()
news_list.append({
"id": f.stem,
"title": title,
"type": news_type,
"version": version,
"body": body
})
except Exception as e:
logger.warning(f"Failed to read news file {f.name}: {e}")
news_list.reverse()
return {"news": news_list}
@app.get("/news/{news_id}")
async def get_news(news_id: str):
"""Get a single news item by ID"""
file_path = NEWS_DIR / f"{news_id}.txt"
if not file_path.exists():
raise HTTPException(404, "News not found")
content = file_path.read_text(encoding="utf-8").strip().split("\n")
if len(content) < 4:
raise HTTPException(400, "Invalid news file format")
return {
"id": file_path.stem,
"title": content[0].strip(),
"type": content[1].strip(),
"version": content[2].strip(),
"body": "\n".join(content[3:]).strip()
}
# ====================== ПРОКСИ ЭНДПОИНТЫ ======================
# Эти эндпоинты позволяют клиентам с сетевыми проблемами
# скачивать файлы через сервер Zern