Skip to content

Commit

Permalink
Fix cdn endpoint issues for stickers & avatar decorations (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Apr 10, 2024
1 parent d861eea commit c13ef9f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions discord/cdn_endpoints.go
Expand Up @@ -4,7 +4,10 @@ import (
"strings"
)

const CDN = "https://cdn.discordapp.com"
const (
CDN = "https://cdn.discordapp.com"
CDNMedia = "https://media.discordapp.net"
)

var (
CustomEmoji = NewCDN("/emojis/{emote.id}", FileFormatPNG, FileFormatGIF)
Expand Down Expand Up @@ -87,6 +90,12 @@ func (e CDNEndpoint) URL(format FileFormat, values QueryValues, params ...any) s
if query != "" {
query = "?" + query
}

// for some reason custom gif stickers use a different cnd url, blame discord for this one
if format == FileFormatGIF && e.Route == "/stickers/{sticker.id}" {
return urlPrint(CDNMedia+e.Route+"."+format.String(), params...) + query
}

return urlPrint(CDN+e.Route+"."+format.String(), params...) + query
}

Expand Down Expand Up @@ -141,7 +150,8 @@ func formatAssetURL(cdnRoute *CDNEndpoint, opts []CDNOpt, params ...any) string
lastStringParam = *ptrStr
}

if strings.HasPrefix(lastStringParam, "a_") && !config.Format.Animated() {
// some endpoints have a_ prefix for animated images except the AvatarDecoration endpoint does not like this
if strings.HasPrefix(lastStringParam, "a_") && !config.Format.Animated() && cdnRoute.Route != "/avatar-decoration-presets/{user.avatar.decoration.hash}" {
config.Format = FileFormatGIF
}

Expand Down

0 comments on commit c13ef9f

Please sign in to comment.