A platform for community discussion. Free, open, simple.
FIX: Allow shared CDN for s3 and assets
Rafael dos Santos Silvab9a343afe7b5
diff --git a/app/models/upload.rb b/app/models/upload.rbindex 4d2e396a064..0e776d52676 100644--- a/app/models/upload.rb+++ b/app/models/upload.rb@@ -77,7 +77,7 @@ class Upload < ActiveRecord::Basedef self.get_from_url(url)return if url.blank?# we store relative urls, so we need to remove any host/cdn- url = url.sub(Discourse.asset_host, "") if Discourse.asset_host.present?+ url = url.sub(Discourse.asset_host, "") if Discourse.asset_host.present? && Discourse.asset_host != SiteSetting.Upload.s3_cdn_url# when using s3, we need to replace with the absolute base urlurl = url.sub(SiteSetting.Upload.s3_cdn_url, Discourse.store.absolute_base_url) if SiteSetting.Upload.s3_cdn_url.present?diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rbindex b8803fda54a..e7d9fdde7a8 100644--- a/spec/models/upload_spec.rb+++ b/spec/models/upload_spec.rb@@ -111,6 +111,22 @@ describe Upload doexpect(Upload.get_from_url(URI.join(s3_cdn_url, path).to_s)).to eq(upload)end++ it "should return the right upload when using one CDN for both s3 and assets" do+ begin+ original_asset_host = Rails.configuration.action_controller.asset_host+ cdn_url = 'http://my.cdn.com'+ Rails.configuration.action_controller.asset_host = cdn_url+ SiteSetting.s3_cdn_url = cdn_url+ upload++ expect(Upload.get_from_url(+ URI.join(cdn_url, path).to_s+ )).to eq(upload)+ ensure+ Rails.configuration.action_controller.asset_host = original_asset_host+ end+ endendend