28 lines
1.2 KiB
Python
28 lines
1.2 KiB
Python
"""Публичное чтение ачивок: список и иконки (для отображения; выдача — на будущее)."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from fastapi.responses import FileResponse
|
|
|
|
from app.auth.deps import get_current_user
|
|
from app.models import User
|
|
from app.schemas import api as s
|
|
from app.services import achievement_service
|
|
|
|
router = APIRouter(prefix="/achievements", tags=["achievements"])
|
|
|
|
|
|
@router.get("", response_model=list[s.AchievementRead])
|
|
def list_achievements(_user: User = Depends(get_current_user)) -> list[dict]:
|
|
return achievement_service.list_achievements()
|
|
|
|
|
|
# Иконка — без auth: косметический ассет, нужен и игроку, и в админ-панели (cookie
|
|
# админа scoped на /api/admin и сюда не отправляется). Отдаётся по известному slug.
|
|
@router.get("/{slug}/icon")
|
|
def get_icon(slug: str) -> FileResponse:
|
|
path, media_type = achievement_service.icon_file(slug)
|
|
return FileResponse(
|
|
path, media_type=media_type, headers={"Cache-Control": "public, max-age=3600"}
|
|
)
|