Skip to content

Commit

Permalink
Use route's first defined format as default (#394)
Browse files Browse the repository at this point in the history
* Use route's first defined format as default

instead of PNG

* add len check

* add format to DefaultCDNConfig

---------

Co-authored-by: topi314 <[email protected]>
  • Loading branch information
sebm253 and topi314 authored Sep 21, 2024
1 parent ef757ee commit daa1902
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions discord/cdn_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func (e CDNEndpoint) URL(format FileFormat, values QueryValues, params ...any) s
return urlPrint(CDN+e.Route+"."+format.String(), params...) + query
}

func DefaultCDNConfig() *CDNConfig {
func DefaultCDNConfig(format FileFormat) *CDNConfig {
return &CDNConfig{
Format: FileFormatPNG,
Format: format,
Values: QueryValues{},
}
}
Expand Down Expand Up @@ -136,7 +136,13 @@ func WithFormat(format FileFormat) CDNOpt {
}

func formatAssetURL(cdnRoute *CDNEndpoint, opts []CDNOpt, params ...any) string {
config := DefaultCDNConfig()
format := FileFormatNone
if len(cdnRoute.Formats) > 0 { // just in case someone fucks up
// use the first provided format in the route definition itself. if the user provides a different format, this will be overriden by the Apply function call below
// previously, the default format was png, which would cause issues for cdn endpoints like attachments and soundboard sounds, requiring custom "overrides"
format = cdnRoute.Formats[0]
}
config := DefaultCDNConfig(format)
config.Apply(opts)

var lastStringParam string
Expand Down

0 comments on commit daa1902

Please sign in to comment.