Files
top-wallpaper/http/handler.go
Ron Rise d321d96fef
Some checks failed
🚨 Test Code Base / 🧹 Lint (push) Failing after 5m24s
🚨 Test Code Base / 🔍 🐹 Go Tests (push) Failing after 5m45s
🏗️✨ Build Workflow / 🖥️ 🔨 Build (push) Failing after 6m14s
Refactor caching logic and add support for a new feature
2026-01-21 21:08:26 -05:00

31 lines
670 B
Go

package http
import (
"net/http"
"os"
"github.com/labstack/echo/v4"
"github.com/siteworxpro/top-wallpaper/redis"
)
func Get(c echo.Context) error {
rc, err := redis.NewRedis()
if err != nil {
return c.String(http.StatusInternalServerError, "Internal Server Error: "+err.Error())
}
defer rc.Close()
nsfw := (c.QueryParam("nsfw") == "true" || c.QueryParam("nsfw") == "1") && os.Getenv("NSFW_MODE") == "true"
val, err := rc.Get(rc.GetCacheKey(nsfw))
if err != nil || val == "" {
return c.NoContent(http.StatusNoContent)
}
c.Response().Header().Set("Cache-Control", "public, max-age=600")
return c.Blob(http.StatusOK, "image/jpeg", []byte(val))
}