Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cdn endpoint issues for stickers & avatar decorations #349

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions discord/cdn_endpoints.go
Original file line number Diff line number Diff line change
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
Loading