You've already forked top-wallpaper
LOL!
This commit is contained in:
@@ -45,48 +45,49 @@ func Get(c echo.Context) error {
|
|||||||
imageData = latestImageBin.Val()
|
imageData = latestImageBin.Val()
|
||||||
}
|
}
|
||||||
|
|
||||||
if imageData == "" {
|
if imageData != "" {
|
||||||
response, err := http.Get(latestImageVal)
|
|
||||||
if err != nil {
|
|
||||||
return c.String(http.StatusInternalServerError, "Error fetching image")
|
|
||||||
}
|
|
||||||
|
|
||||||
if response.StatusCode != http.StatusOK {
|
|
||||||
return c.String(http.StatusInternalServerError, "Error fetching image")
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func(Body io.ReadCloser) {
|
|
||||||
_ = Body.Close()
|
|
||||||
}(response.Body)
|
|
||||||
|
|
||||||
imageDataBytes, err := io.ReadAll(response.Body)
|
|
||||||
if err != nil {
|
|
||||||
return c.String(http.StatusInternalServerError, "Error fetching image")
|
|
||||||
}
|
|
||||||
|
|
||||||
imageData = string(imageDataBytes)
|
|
||||||
|
|
||||||
imageData, err := resize.Shrink(imageData, 1200, 70)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return c.String(http.StatusInternalServerError, "Error resizing image")
|
|
||||||
}
|
|
||||||
|
|
||||||
go func(data string) {
|
|
||||||
if cc.redis == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = cc.redis.Set(context.TODO(), "latestImage:bin:"+latestImageVal, data, 600*time.Second).Result()
|
|
||||||
if err != nil {
|
|
||||||
c.Logger().Warn("could not cache image")
|
|
||||||
}
|
|
||||||
}(imageData)
|
|
||||||
} else {
|
|
||||||
c.Logger().Info("Image data fetched from cache")
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
if response.StatusCode != http.StatusOK {
|
||||||
|
return c.String(http.StatusInternalServerError, "Error fetching image")
|
||||||
|
}
|
||||||
|
|
||||||
|
defer func(Body io.ReadCloser) {
|
||||||
|
_ = Body.Close()
|
||||||
|
}(response.Body)
|
||||||
|
|
||||||
|
imageDataBytes, err := io.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
return c.String(http.StatusInternalServerError, "Error fetching image")
|
||||||
|
}
|
||||||
|
|
||||||
|
imageData = string(imageDataBytes)
|
||||||
|
resized, err := resize.Shrink(imageData, 1200, 70)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return c.String(http.StatusInternalServerError, "Error resizing image")
|
||||||
|
}
|
||||||
|
|
||||||
|
go func(data string) {
|
||||||
|
if cc.redis == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = cc.redis.Set(context.TODO(), "latestImage:bin:"+latestImageVal, data, 600*time.Second).Result()
|
||||||
|
if err != nil {
|
||||||
|
c.Logger().Warn("could not cache image")
|
||||||
|
}
|
||||||
|
}(resized)
|
||||||
|
|
||||||
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