mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user