mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: crash when calling badge endpoint with no filters applied (resolve #66)
This commit is contained in:
parent
68e66298b8
commit
96ff490d8d
@ -70,6 +70,8 @@ func (h *BadgeHandler) ApiGet(w http.ResponseWriter, r *http.Request) {
|
||||
filters = models.NewFiltersWith(models.SummaryLanguage, filterKey)
|
||||
case "machine":
|
||||
filters = models.NewFiltersWith(models.SummaryMachine, filterKey)
|
||||
default:
|
||||
filters = &models.Filters{}
|
||||
}
|
||||
|
||||
summary, err, status := h.loadUserSummary(user, interval)
|
||||
|
@ -43,7 +43,7 @@ func (h *AllTimeHandler) ApiGet(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
vm := v1.NewAllTimeFrom(summary, &models.Filters{Project: values.Get("project")})
|
||||
vm := v1.NewAllTimeFrom(summary, models.NewFiltersWith(models.SummaryProject, values.Get("project")))
|
||||
utils.RespondJSON(w, http.StatusOK, vm)
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/muety/wakapi/config"
|
||||
"sync"
|
||||
|
||||
@ -36,15 +35,19 @@ func (srv *AliasService) LoadUserAliases(userId string) error {
|
||||
}
|
||||
|
||||
func (srv *AliasService) GetAliasOrDefault(userId string, summaryType uint8, value string) (string, error) {
|
||||
if ua, ok := userAliases.Load(userId); ok {
|
||||
for _, a := range ua.([]*models.Alias) {
|
||||
if a.Type == summaryType && a.Value == value {
|
||||
return a.Key, nil
|
||||
}
|
||||
if !srv.IsInitialized(userId) {
|
||||
if err := srv.LoadUserAliases(userId); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
return "", errors.New("user aliases not initialized")
|
||||
|
||||
aliases, _ := userAliases.Load(userId)
|
||||
for _, a := range aliases.([]*models.Alias) {
|
||||
if a.Type == summaryType && a.Value == value {
|
||||
return a.Key, nil
|
||||
}
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (srv *AliasService) IsInitialized(userId string) bool {
|
||||
|
@ -1 +1 @@
|
||||
1.13.2
|
||||
1.13.3
|
||||
|
Loading…
Reference in New Issue
Block a user