@@ -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
@@ -82,7 +84,10 @@ func resolveAttachment(ctx context.Context, b courier.Backend, attachment string
82
84
}
83
85
84
86
mediaType , _ := parseContentType (media .ContentType ())
85
- mediaSupport := support [mediaType ]
87
+ mediaSupport , ok := support [MediaType (media .ContentType ())]
88
+ if ! ok {
89
+ mediaSupport = support [mediaType ]
90
+ }
86
91
87
92
// our candidates are the uploaded media and any alternates of the same media type
88
93
candidates := append ([]courier.Media {media }, filterMediaByType (media .Alternates (), mediaType )... )
@@ -97,6 +102,11 @@ func resolveAttachment(ctx context.Context, b courier.Backend, attachment string
97
102
candidates = filterMediaBySize (candidates , mediaSupport .MaxBytes )
98
103
}
99
104
105
+ // narrow down the candidates to the ones that don't exceed our max dimensions
106
+ if mediaSupport .MaxWidth > 0 && mediaSupport .MaxHeight > 0 {
107
+ candidates = filterMediaByDimensions (candidates , mediaSupport .MaxWidth , mediaSupport .MaxHeight )
108
+ }
109
+
100
110
// if we have no candidates, we can't use this media
101
111
if len (candidates ) == 0 {
102
112
return nil , nil
@@ -142,6 +152,10 @@ func filterMediaBySize(in []courier.Media, maxBytes int) []courier.Media {
142
152
return filterMedia (in , func (m courier.Media ) bool { return m .Size () <= maxBytes })
143
153
}
144
154
155
+ func filterMediaByDimensions (in []courier.Media , maxWidth int , MaxHeight int ) []courier.Media {
156
+ return filterMedia (in , func (m courier.Media ) bool { return m .Width () <= maxWidth && m .Height () <= MaxHeight })
157
+ }
158
+
145
159
func filterMedia (in []courier.Media , f func (courier.Media ) bool ) []courier.Media {
146
160
filtered := make ([]courier.Media , 0 , len (in ))
147
161
for _ , m := range in {
0 commit comments