@@ -20,8 +20,10 @@ const (
20
20
)
21
21
22
22
type MediaTypeSupport struct {
23
- Types []string
24
- MaxBytes int
23
+ Types []string
24
+ MaxBytes int
25
+ MaxWidth int
26
+ MaxHeight int
25
27
}
26
28
27
29
// Attachment is a resolved attachment
@@ -84,7 +86,10 @@ func resolveAttachment(ctx context.Context, b courier.Backend, contentType, medi
84
86
}
85
87
86
88
mediaType , _ := parseContentType (media .ContentType ())
87
- mediaSupport := support [mediaType ]
89
+ mediaSupport , ok := support [MediaType (media .ContentType ())]
90
+ if ! ok {
91
+ mediaSupport = support [mediaType ]
92
+ }
88
93
89
94
// our candidates are the uploaded media and any alternates of the same media type
90
95
candidates := append ([]courier.Media {media }, filterMediaByType (media .Alternates (), mediaType )... )
@@ -99,6 +104,11 @@ func resolveAttachment(ctx context.Context, b courier.Backend, contentType, medi
99
104
candidates = filterMediaBySize (candidates , mediaSupport .MaxBytes )
100
105
}
101
106
107
+ // narrow down the candidates to the ones that don't exceed our max dimensions
108
+ if mediaSupport .MaxWidth > 0 && mediaSupport .MaxHeight > 0 {
109
+ candidates = filterMediaByDimensions (candidates , mediaSupport .MaxWidth , mediaSupport .MaxHeight )
110
+ }
111
+
102
112
// if we have no candidates, we can't use this media
103
113
if len (candidates ) == 0 {
104
114
return nil , nil
@@ -144,6 +154,10 @@ func filterMediaBySize(in []courier.Media, maxBytes int) []courier.Media {
144
154
return filterMedia (in , func (m courier.Media ) bool { return m .Size () <= maxBytes })
145
155
}
146
156
157
+ func filterMediaByDimensions (in []courier.Media , maxWidth int , MaxHeight int ) []courier.Media {
158
+ return filterMedia (in , func (m courier.Media ) bool { return m .Width () <= maxWidth && m .Height () <= MaxHeight })
159
+ }
160
+
147
161
func filterMedia (in []courier.Media , f func (courier.Media ) bool ) []courier.Media {
148
162
filtered := make ([]courier.Media , 0 , len (in ))
149
163
for _ , m := range in {
0 commit comments