Files
Nikolay Tatarinov 6a6977ddff Enhance user profile management and Gravatar integration
- Added email field to user profile API and frontend components for better user identification.
- Implemented PATCH /map/api/me endpoint to update user email, enhancing user experience.
- Introduced useGravatarUrl composable for generating Gravatar URLs based on user email.
- Updated profile and layout components to display user avatars using Gravatar, improving visual consistency.
- Enhanced development documentation to guide testing of navbar and profile features.
2026-03-01 16:48:56 +03:00

83 lines
1.8 KiB
Go

package handlers
import (
"net/http"
"strings"
)
// APIRouter routes /map/api/* requests to the appropriate handler.
func (h *Handlers) APIRouter(rw http.ResponseWriter, req *http.Request) {
path := strings.TrimPrefix(req.URL.Path, "/map/api")
path = strings.TrimPrefix(path, "/")
switch path {
case "config":
h.APIConfig(rw, req)
return
case "v1/characters":
h.APIGetChars(rw, req)
return
case "v1/markers":
h.APIGetMarkers(rw, req)
return
case "maps":
h.APIGetMaps(rw, req)
return
case "setup":
h.APISetup(rw, req)
return
case "login":
h.APILogin(rw, req)
return
case "logout":
h.APILogout(rw, req)
return
case "me":
switch req.Method {
case http.MethodGet:
h.APIMe(rw, req)
case http.MethodPatch:
h.APIMeUpdate(rw, req)
default:
JSONError(rw, http.StatusMethodNotAllowed, "method not allowed", "METHOD_NOT_ALLOWED")
}
return
case "me/tokens":
h.APIMeTokens(rw, req)
return
case "me/password":
h.APIMePassword(rw, req)
return
}
switch {
case path == "oauth/providers":
h.APIOAuthProviders(rw, req)
return
case strings.HasPrefix(path, "oauth/"):
rest := strings.TrimPrefix(path, "oauth/")
parts := strings.SplitN(rest, "/", 2)
if len(parts) != 2 {
JSONError(rw, http.StatusNotFound, "not found", "NOT_FOUND")
return
}
provider := parts[0]
action := parts[1]
switch action {
case "login":
h.APIOAuthLogin(rw, req, provider)
case "callback":
h.APIOAuthCallback(rw, req, provider)
default:
JSONError(rw, http.StatusNotFound, "not found", "NOT_FOUND")
}
return
case strings.HasPrefix(path, "admin/"):
adminPath := strings.TrimPrefix(path, "admin/")
h.APIAdminRoute(rw, req, adminPath)
return
}
JSONError(rw, http.StatusNotFound, "not found", "NOT_FOUND")
}