Skip to content

Commit

Permalink
feat: add cache buster to thumbnail URL
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelMachado-dev authored Aug 12, 2024
1 parent 0d96067 commit 4161c0f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions handler/command_live_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"net/http"
"strings"
"time"

"github.com/MiguelMachado-dev/disc-go-bot/config"
"github.com/MiguelMachado-dev/disc-go-bot/utils"
Expand Down Expand Up @@ -118,6 +119,7 @@ func (h *LiveHandler) Handler(s *discordgo.Session, i *discordgo.InteractionCrea
if isLive {
streamTitle = streamInfo.Title
thumbnailURL = strings.Replace(streamInfo.ThumbnailURL, "{width}x{height}", "1280x720", 1)
thumbnailURL = addCacheBuster(thumbnailURL)
game = streamInfo.GameName
profilePic = channelInfo.ProfileImageURL
} else {
Expand Down Expand Up @@ -279,3 +281,10 @@ func (h *LiveHandler) getTwitchStreamInfo(username, accessToken string) (*Twitch

return nil, nil
}

func addCacheBuster(url string) string {
if strings.Contains(url, "?") {
return url + "&cb=" + fmt.Sprintf("%d", time.Now().UnixNano())
}
return url + "?cb=" + fmt.Sprintf("%d", time.Now().UnixNano())
}

0 comments on commit 4161c0f

Please sign in to comment.