Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestMessagesGetUsesTheDefaultChannel(t *testing.T) {
func TestMessageDecodesEmbeds(t *testing.T) {
s := transport.NewStub().Reply(`{"id":"m1","content":"","embeds":[{
"title":"Quest failed","description":"stack trace here","url":"https://example.test/run/1",
"image":{"url":"https://cdn.example.test/shot.png"},
"image":{"url":"https://cdn.example.test/shot.png","proxy_url":"https://media.discordapp.net/external/shot.png"},
"thumbnail":{"url":"https://cdn.example.test/thumb.png"},
"fields":[{"name":"env","value":"prod"}]}]}`)
got, err := msgs(s, "def").Get(context.Background(), "c", "m1")
Expand All @@ -98,6 +98,9 @@ func TestMessageDecodesEmbeds(t *testing.T) {
if e.Image == nil || e.Image.URL != "https://cdn.example.test/shot.png" {
t.Errorf("image = %+v", e.Image)
}
if e.Image.ProxyURL != "https://media.discordapp.net/external/shot.png" {
t.Errorf("proxy url = %q", e.Image.ProxyURL)
}
if e.Thumbnail == nil || e.Thumbnail.URL != "https://cdn.example.test/thumb.png" {
t.Errorf("thumbnail = %+v", e.Thumbnail)
}
Expand Down
9 changes: 6 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ type Attachment struct {
Size int `json:"size"`
}

// EmbedMedia is an image carried by an embed. Only the URL is surfaced: it is
// what a reader needs to fetch the picture.
// EmbedMedia is an image carried by an embed. URL is where the picture actually
// lives, which for a link preview is a third-party site; ProxyURL is Discord's
// own copy of it and is present whenever Discord could fetch it. A reader that
// only trusts Discord hosts wants ProxyURL, falling back to URL.
type EmbedMedia struct {
URL string `json:"url"`
URL string `json:"url"`
ProxyURL string `json:"proxy_url"`
}

// EmbedField is one name/value pair in an embed's body.
Expand Down
Loading