You've already forked top-wallpaper
LOL!
This commit is contained in:
@@ -45,7 +45,12 @@ func Get(c echo.Context) error {
|
|||||||
imageData = latestImageBin.Val()
|
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)
|
response, err := http.Get(latestImageVal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.String(http.StatusInternalServerError, "Error fetching image")
|
return c.String(http.StatusInternalServerError, "Error fetching image")
|
||||||
@@ -65,8 +70,7 @@ func Get(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
imageData = string(imageDataBytes)
|
imageData = string(imageDataBytes)
|
||||||
|
resized, err := resize.Shrink(imageData, 1200, 70)
|
||||||
imageData, err := resize.Shrink(imageData, 1200, 70)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.String(http.StatusInternalServerError, "Error resizing image")
|
return c.String(http.StatusInternalServerError, "Error resizing image")
|
||||||
@@ -81,12 +85,9 @@ func Get(c echo.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
c.Logger().Warn("could not cache image")
|
c.Logger().Warn("could not cache image")
|
||||||
}
|
}
|
||||||
}(imageData)
|
}(resized)
|
||||||
} else {
|
|
||||||
c.Logger().Info("Image data fetched from cache")
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Response().Header().Set("Cache-Control", "public, max-age=600")
|
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))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user