diff --git a/partner/tba.go b/partner/tba.go index b4fc4a5..73ec774 100644 --- a/partner/tba.go +++ b/partner/tba.go @@ -20,7 +20,7 @@ import ( const ( tbaBaseUrl = "https://www.thebluealliance.com" tbaAuthKey = "MAApv9MCuKY9MSFkXLuzTSYBCdosboxDq8Q3ujUE2Mn8PD3Nmv64uczu5Lvy0NQ3" - avatarsDir = "static/img/avatars" + AvatarsDir = "static/img/avatars" ) type TbaClient struct { @@ -242,7 +242,7 @@ func (client *TbaClient) DownloadTeamAvatar(teamNumber, year int) error { } // Store the avatar to disk as a PNG file. - avatarPath := fmt.Sprintf("%s/%d.png", avatarsDir, teamNumber) + avatarPath := fmt.Sprintf("%s/%d.png", AvatarsDir, teamNumber) ioutil.WriteFile(avatarPath, avatarBytes, 0644) return nil } diff --git a/static/js/audience_display.js b/static/js/audience_display.js index fb48b08..f35475e 100644 --- a/static/js/audience_display.js +++ b/static/js/audience_display.js @@ -450,7 +450,7 @@ var initializeSponsorDisplay = function() { }; var getAvatarUrl = function(teamId) { - return "/static/img/avatars/" + teamId + ".png"; + return "/api/teams/" + teamId + "/avatar"; }; $(function() { @@ -476,9 +476,6 @@ $(function() { overlayCenteringShowParams = overlayCenteringBottomShowParams; } - // Fall back to a blank avatar if one doesn't exist for the team. - $(".avatar, .final-avatar").attr("onerror", "this.src='" + getAvatarUrl(0) + "';"); - // Set up the websocket back to the server. websocket = new CheesyWebsocket("/displays/audience/websocket", { allianceSelection: function(event) { handleAllianceSelection(event.data); }, diff --git a/static/js/queueing_display.js b/static/js/queueing_display.js index a085b50..698c537 100644 --- a/static/js/queueing_display.js +++ b/static/js/queueing_display.js @@ -29,9 +29,6 @@ var handleMatchTime = function(data) { }; $(function() { - // Fall back to a blank avatar if one doesn't exist for the team. - $(".avatar").attr("onerror", "this.src='/static/img/avatars/0.png';"); - // Set up the websocket back to the server. websocket = new CheesyWebsocket("/displays/queueing/websocket", { matchLoad: function(event) { handleMatchLoad(event.data); }, diff --git a/templates/queueing_display.html b/templates/queueing_display.html index 6efda1f..6fe2f37 100644 --- a/templates/queueing_display.html +++ b/templates/queueing_display.html @@ -53,9 +53,9 @@ {{end}}
-
-
- +
+
+
{{$match.Red1}}
{{$match.Red2}}
{{$match.Red3}} @@ -64,9 +64,9 @@ {{$match.Blue1}}
{{$match.Blue2}}
{{$match.Blue3}}
-
-
- +
+
+
{{end}} diff --git a/web/api.go b/web/api.go index dfbce92..d983421 100644 --- a/web/api.go +++ b/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) +} diff --git a/web/web.go b/web/web.go index a3f600c..c1bf52d 100644 --- a/web/web.go +++ b/web/web.go @@ -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")