From e955a7b49de8db6b04676756ea93b4450171918f Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 24 Oct 2018 15:14:01 +1100 Subject: [PATCH] Revert "Revert "FIX: GlobalPath#upload_cdn_path when S3 bucket has a folder (#6523)"" This reverts commit 322b27b6dcba0ec37323b3fef64fec6075c68fe6. Oops rushed on the revert here... should be good --- lib/global_path.rb | 2 +- spec/components/global_path_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/global_path.rb b/lib/global_path.rb index fc9557210a8..e7f89c0ddff 100644 --- a/lib/global_path.rb +++ b/lib/global_path.rb @@ -9,7 +9,7 @@ module GlobalPath def upload_cdn_path(p) if SiteSetting.Upload.s3_cdn_url.present? - p = p.sub(Discourse.store.absolute_base_url, SiteSetting.Upload.s3_cdn_url) + p = Discourse.store.cdn_url(p) end p =~ /^http/ ? p : cdn_path(p) end diff --git a/spec/components/global_path_spec.rb b/spec/components/global_path_spec.rb index 41b778c9af3..daf8c49b0dc 100644 --- a/spec/components/global_path_spec.rb +++ b/spec/components/global_path_spec.rb @@ -25,6 +25,18 @@ describe GlobalPath do GlobalSetting.expects(:cdn_url).returns("https://something.com:221/foo") expect(cdn_relative_path("/test")).to eq("/foo/test") end + end + describe '#upload_cdn_path' do + it 'generates correctly when S3 bucket has a folder' do + global_setting :s3_access_key_id, 's3_access_key_id' + global_setting :s3_secret_access_key, 's3_secret_access_key' + global_setting :s3_bucket, 'file-uploads/folder' + global_setting :s3_region, 'us-west-2' + global_setting :s3_cdn_url, 'https://cdn-aws.com/folder' + + expect(GlobalPathInstance.upload_cdn_path("#{Discourse.store.absolute_base_url}/folder/upload.jpg")) + .to eq("https://cdn-aws.com/folder/upload.jpg") + end end end