Skip to content

Commit ebd5ad8

Browse files
authored
Merge pull request #713 from nyaruka/fix-media-resolve
Remove S3 region is media hostname before matching the media domain
2 parents f889b58 + 993344a commit ebd5ad8

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Diff for: backends/rapidpro/backend.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ func (b *backend) ResolveMedia(ctx context.Context, mediaUrl string) (courier.Me
679679
mediaUUID := uuidRegex.FindString(u.Path)
680680

681681
// if hostname isn't our media domain, or path doesn't contain a UUID, don't try to resolve
682-
if u.Hostname() != b.config.MediaDomain || mediaUUID == "" {
682+
if strings.Replace(u.Hostname(), fmt.Sprintf("%s.", b.config.S3Region), "", -1) != b.config.MediaDomain || mediaUUID == "" {
683683
return nil, nil
684684
}
685685

@@ -708,7 +708,7 @@ func (b *backend) ResolveMedia(ctx context.Context, mediaUrl string) (courier.Me
708708
}
709709

710710
// if we found a media record but it doesn't match the URL, don't use it
711-
if media == nil || media.URL() != mediaUrl {
711+
if media == nil || (media.URL() != mediaUrl && media.URL() != strings.Replace(mediaUrl, fmt.Sprintf("%s.", b.config.S3Region), "", -1)) {
712712
return nil, nil
713713
}
714714

Diff for: backends/rapidpro/backend_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,19 @@ func (ts *BackendTestSuite) TestResolveMedia() {
13661366
Alternates_: []*Media{},
13671367
},
13681368
},
1369+
{ // image upload that can be resolved
1370+
url: "http://nyaruka.us-east-1.s3.com/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg",
1371+
media: &Media{
1372+
UUID_: "ec6972be-809c-4c8d-be59-ba9dbd74c977",
1373+
Path_: "/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg",
1374+
ContentType_: "image/jpeg",
1375+
URL_: "http://nyaruka.s3.com/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg",
1376+
Size_: 123,
1377+
Width_: 1024,
1378+
Height_: 768,
1379+
Alternates_: []*Media{},
1380+
},
1381+
},
13691382
{ // same image upload, this time from cache
13701383
url: "http://nyaruka.s3.com/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg",
13711384
media: &Media{

0 commit comments

Comments
 (0)