This commit is contained in:
2025-04-22 13:56:35 -04:00
parent a05558351f
commit c86eb6520d

View File

@@ -45,7 +45,12 @@ func Get(c echo.Context) error {
imageData = latestImageBin.Val()
}
if imageData == "" {
if imageData != "" {
c.Logger().Info("Image data fetched from cache")
return c.Blob(http.StatusOK, "image/jpeg", []byte(imageData))
}
response, err := http.Get(latestImageVal)
if err != nil {
return c.String(http.StatusInternalServerError, "Error fetching image")
@@ -65,8 +70,7 @@ func Get(c echo.Context) error {
}
imageData = string(imageDataBytes)
imageData, err := resize.Shrink(imageData, 1200, 70)
resized, err := resize.Shrink(imageData, 1200, 70)
if err != nil {
return c.String(http.StatusInternalServerError, "Error resizing image")
@@ -81,12 +85,9 @@ func Get(c echo.Context) error {
if err != nil {
c.Logger().Warn("could not cache image")
}
}(imageData)
} else {
c.Logger().Info("Image data fetched from cache")
}
}(resized)
c.Response().Header().Set("Cache-Control", "public, max-age=600")
return c.Blob(http.StatusOK, "image/jpeg", []byte(imageData))
return c.Blob(http.StatusOK, "image/jpeg", []byte(resized))
}