feat(profile): implement yggdrasil profile signing

This commit is contained in:
2025-06-15 17:09:36 +03:00
parent 4d42cfff2d
commit 056aa05c50
6 changed files with 254 additions and 2 deletions

View File

@@ -0,0 +1,40 @@
package api
import (
"encoding/json"
"errors"
"net/http"
"gitea.mrixs.me/minecraft-platform/backend/internal/core"
"gitea.mrixs.me/minecraft-platform/backend/internal/database"
"github.com/go-chi/chi/v5"
"github.com/google/uuid"
)
type ProfileHandler struct {
Service *core.ProfileService
}
func (h *ProfileHandler) GetProfile(w http.ResponseWriter, r *http.Request) {
playerUUIDStr := chi.URLParam(r, "uuid")
playerUUID, err := uuid.Parse(playerUUIDStr)
if err != nil {
http.Error(w, "Invalid UUID format", http.StatusBadRequest)
return
}
profile, err := h.Service.GetSignedProfile(r.Context(), playerUUID)
if err != nil {
if errors.Is(err, database.ErrUserNotFound) {
// Yggdrasil возвращает 204 No Content, если профиль не найден
w.WriteHeader(http.StatusNoContent)
return
}
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(profile)
}