mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Move missing avatar logic from JavaScript to server.
This commit is contained in:
21
web/api.go
21
web/api.go
@@ -7,11 +7,15 @@ package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/Team254/cheesy-arena/game"
|
||||
"github.com/Team254/cheesy-arena/model"
|
||||
"github.com/Team254/cheesy-arena/partner"
|
||||
"github.com/Team254/cheesy-arena/websocket"
|
||||
"github.com/gorilla/mux"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type MatchResultWithSummary struct {
|
||||
@@ -194,3 +198,20 @@ func (web *Web) arenaWebsocketApiHandler(w http.ResponseWriter, r *http.Request)
|
||||
// Subscribe the websocket to the notifiers whose messages will be passed on to the client.
|
||||
ws.HandleNotifiers(web.arena.MatchTimingNotifier, web.arena.MatchLoadNotifier, web.arena.MatchTimeNotifier)
|
||||
}
|
||||
|
||||
// Serves the avatar for a given team, or a default if none exists.
|
||||
func (web *Web) teamAvatarsApiHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
teamId, err := strconv.Atoi(vars["teamId"])
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
avatarPath := fmt.Sprintf("%s/%d.png", partner.AvatarsDir, teamId)
|
||||
if _, err := os.Stat(avatarPath); os.IsNotExist(err) {
|
||||
avatarPath = fmt.Sprintf("%s/0.png", partner.AvatarsDir)
|
||||
}
|
||||
|
||||
http.ServeFile(w, r, avatarPath)
|
||||
}
|
||||
|
||||
@@ -106,6 +106,7 @@ func (web *Web) newHandler() http.Handler {
|
||||
router.HandleFunc("/api/matches/{type}", web.matchesApiHandler).Methods("GET")
|
||||
router.HandleFunc("/api/rankings", web.rankingsApiHandler).Methods("GET")
|
||||
router.HandleFunc("/api/sponsor_slides", web.sponsorSlidesApiHandler).Methods("GET")
|
||||
router.HandleFunc("/api/teams/{teamId}/avatar", web.teamAvatarsApiHandler).Methods("GET")
|
||||
router.HandleFunc("/display", web.placeholderDisplayHandler).Methods("GET")
|
||||
router.HandleFunc("/display/websocket", web.placeholderDisplayWebsocketHandler).Methods("GET")
|
||||
router.HandleFunc("/displays/alliance_station", web.allianceStationDisplayHandler).Methods("GET")
|
||||
|
||||
Reference in New Issue
Block a user