feat: добавить веб-интерфейс админ-панели для управления модпаками
All checks were successful
CI / lint (push) Successful in 1m1s
CI / test (push) Successful in 42s
CI / build (push) Successful in 18s
CI / docker (push) Successful in 1m16s

This commit is contained in:
2026-06-07 19:06:27 +03:00
parent f765fecf24
commit b9e986d25a
4 changed files with 352 additions and 17 deletions

View File

@@ -50,6 +50,7 @@ func (h *Handler) RegisterRoutes(mux *http.ServeMux) {
// Website endpoints.
mux.HandleFunc("POST /api/web/register", h.register)
mux.HandleFunc("POST /api/web/login", h.webLogin)
mux.HandleFunc("GET /api/web/me", h.webMe)
mux.HandleFunc("POST /api/web/profile/skin", h.uploadSkin)
mux.HandleFunc("POST /api/web/profile/cape", h.uploadCape)
mux.HandleFunc("DELETE /api/web/profile/skin", h.deleteSkin)
@@ -429,6 +430,29 @@ func (h *Handler) authenticateRequest(w http.ResponseWriter, r *http.Request) in
return userID
}
// webMe returns the current authenticated user's info (for checking admin status in UI).
func (h *Handler) webMe(w http.ResponseWriter, r *http.Request) {
userID := h.authenticateRequest(w, r)
if userID == 0 {
return
}
var username, uuid, role string
err := h.db.Pool().QueryRow(r.Context(),
`SELECT username, uuid, role FROM users WHERE id = $1`, userID,
).Scan(&username, &uuid, &role)
if err != nil {
utils.WriteError(w, http.StatusInternalServerError, "Database error")
return
}
utils.WriteJSON(w, http.StatusOK, map[string]string{
"username": username,
"uuid": uuid,
"role": role,
})
}
func (h *Handler) launcherLatest(w http.ResponseWriter, r *http.Request) {
osParam := r.URL.Query().Get("os")
archParam := r.URL.Query().Get("arch")