mirror of
https://codeberg.org/pluja/kycnot.me
synced 2025-02-08 03:15:29 -05:00
fix nil pointer dereference
This commit is contained in:
parent
081d59e58f
commit
a636975aa2
@ -40,8 +40,17 @@ func (s *Server) handleVerifyPow(c iris.Context) {
|
|||||||
func (s *Server) handleApiPicture(c iris.Context) {
|
func (s *Server) handleApiPicture(c iris.Context) {
|
||||||
id := c.Params().Get("id")
|
id := c.Params().Get("id")
|
||||||
|
|
||||||
|
// Log and check s.Cache to make sure it is not nil
|
||||||
|
if s.Cache == nil {
|
||||||
|
err := fmt.Errorf("server's Cache is nil")
|
||||||
|
log.Error().Err(err).Msg("GetPicture: Fatal error")
|
||||||
|
respondWithPlaceholder(c, "?")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
imgCacheKey := fmt.Sprintf("img-%s", id)
|
imgCacheKey := fmt.Sprintf("img-%s", id)
|
||||||
cttCacheKey := fmt.Sprintf("ctt-%s", id)
|
cttCacheKey := fmt.Sprintf("ctt-%s", id)
|
||||||
|
|
||||||
if imageData, err := s.Cache.Get(imgCacheKey); err == nil {
|
if imageData, err := s.Cache.Get(imgCacheKey); err == nil {
|
||||||
if ctt, err := s.Cache.Get(cttCacheKey); err == nil {
|
if ctt, err := s.Cache.Get(cttCacheKey); err == nil {
|
||||||
c.ContentType(string(ctt))
|
c.ContentType(string(ctt))
|
||||||
@ -51,9 +60,29 @@ func (s *Server) handleApiPicture(c iris.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log and check database.Pb to make sure it is not nil
|
||||||
|
if database.Pb == nil {
|
||||||
|
err := fmt.Errorf("database.Pb is nil")
|
||||||
|
log.Error().Err(err).Msg("GetPicture: Fatal error")
|
||||||
|
respondWithPlaceholder(c, "?")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
service, err := database.Pb.GetServiceById(id)
|
service, err := database.Pb.GetServiceById(id)
|
||||||
if err != nil || service.LogoURL == "" {
|
if err != nil || service == nil || service.LogoURL == "" { // Include service nil check
|
||||||
log.Debug().Err(err).Msg("GetPicture: Could not get service or logo URL is empty")
|
log.Error().Err(err).Msg("GetPicture: Could not get service or logo URL is empty")
|
||||||
|
name := "?"
|
||||||
|
if service != nil {
|
||||||
|
name = service.Name
|
||||||
|
}
|
||||||
|
respondWithPlaceholder(c, name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log and check s.HttpClient to make sure it is not nil
|
||||||
|
if s.HttpClient == nil {
|
||||||
|
err := fmt.Errorf("server's HttpClient is nil")
|
||||||
|
log.Error().Err(err).Msg("GetPicture: Fatal error")
|
||||||
respondWithPlaceholder(c, service.Name)
|
respondWithPlaceholder(c, service.Name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -67,7 +96,7 @@ func (s *Server) handleApiPicture(c iris.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp, err := s.HttpClient.Do(req)
|
resp, err := s.HttpClient.Do(req)
|
||||||
if err != nil || resp.StatusCode != http.StatusOK {
|
if err != nil || resp == nil || resp.StatusCode != http.StatusOK { // Include resp nil check
|
||||||
log.Debug().Err(err).Msgf("GetPicture: Could not get image for %s", service.Name)
|
log.Debug().Err(err).Msgf("GetPicture: Could not get image for %s", service.Name)
|
||||||
respondWithPlaceholder(c, service.Name)
|
respondWithPlaceholder(c, service.Name)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user