Skip to content

Remove S3 region is media hostname before matching the media domain #713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2024
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
4 changes: 2 additions & 2 deletions backends/rapidpro/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func (b *backend) ResolveMedia(ctx context.Context, mediaUrl string) (courier.Me
mediaUUID := uuidRegex.FindString(u.Path)

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

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

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

Expand Down
13 changes: 13 additions & 0 deletions backends/rapidpro/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,19 @@ func (ts *BackendTestSuite) TestResolveMedia() {
Alternates_: []*Media{},
},
},
{ // image upload that can be resolved
url: "http://nyaruka.us-east-1.s3.com/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg",
media: &Media{
UUID_: "ec6972be-809c-4c8d-be59-ba9dbd74c977",
Path_: "/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg",
ContentType_: "image/jpeg",
URL_: "http://nyaruka.s3.com/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg",
Size_: 123,
Width_: 1024,
Height_: 768,
Alternates_: []*Media{},
},
},
{ // same image upload, this time from cache
url: "http://nyaruka.s3.com/orgs/1/media/ec69/ec6972be-809c-4c8d-be59-ba9dbd74c977/test.jpg",
media: &Media{
Expand Down
Loading