update-deps (#1)
All checks were successful
🚨 Test Code Base / 🔍 🐹 Go Tests (push) Successful in 1m22s
🚨 Test Code Base / 🧹 Lint (push) Successful in 1m31s
🏗️✨ Build Workflow / 🖥️ 🔨 Build (push) Successful in 11m11s

Reviewed-on: #1
Co-authored-by: Ron Rise <ron@siteworxpro.com>
Co-committed-by: Ron Rise <ron@siteworxpro.com>
This commit was merged in pull request #1.
This commit is contained in:
2025-08-26 16:36:17 +00:00
committed by Siteworx Pro Gitea
parent aa1699243a
commit ff66877192
12 changed files with 197 additions and 30 deletions

View File

@@ -2,9 +2,6 @@ package reddit
import (
"context"
"github.com/labstack/echo/v4"
"github.com/siteworxpro/top-wallpaper/redis"
"github.com/siteworxpro/top-wallpaper/resize"
"io"
"net/http"
"net/url"
@@ -12,6 +9,10 @@ import (
"strconv"
"strings"
"time"
"github.com/labstack/echo/v4"
"github.com/siteworxpro/top-wallpaper/redis"
"github.com/siteworxpro/top-wallpaper/resize"
)
func Fetch(ctx context.Context) {
@@ -50,6 +51,11 @@ func Fetch(ctx context.Context) {
default:
val, err := rc.Get(redis.CacheKey)
if err != nil {
l.Error("Error fetching from Redis: ", err)
break
}
if val != "" {
l.Info("Reddit image fetched from cache...")
@@ -76,11 +82,11 @@ func Fetch(ctx context.Context) {
Timeout: 10 * time.Second,
}
response, err := httpClient.Do(request)
response, e := httpClient.Do(request)
if err != nil {
l.Error("Error fetching image from Reddit: ", err)
return nil, err
if e != nil {
l.Error("Error fetching image from Reddit: ", e)
return nil, e
}
if response.StatusCode != http.StatusOK {
@@ -94,6 +100,11 @@ func Fetch(ctx context.Context) {
return response, nil
})
if err != nil {
l.Error("Error getting latest image URL: ", err)
break
}
response, err := http.Get(latestImageVal)
if err != nil {
l.Error("Error fetching image from Reddit: ", err)
@@ -119,6 +130,11 @@ func Fetch(ctx context.Context) {
imageData := string(imageDataBytes)
resized, err := resize.Shrink(imageData, uint(size), 70)
if err != nil {
l.Error("Error resizing image: ", err)
break
}
err = rc.Set(redis.CacheKey, resized, 10*time.Minute)
if err != nil {
l.Warn("could not cache image")