DEV: allow using CDN URL for all s3 uploads (#20755)

This adds an option to allow non-image s3 files to be downloaded through CDN URL.

Addresses the issues in:

* meta.discourse.org/t/s3-cdn-url-not-being-used-on-non-image-uploads/175332
* meta.discourse.org/t/s3-uploads-using-cdn-for-pdfs/213218
This commit is contained in:
liushuyu
2023-07-12 12:06:49 +08:00
committed by GitHub
parent ad78d28b66
commit 8e63244e72
4 changed files with 17 additions and 0 deletions

View File

@ -375,6 +375,18 @@ RSpec.describe UploadCreator do
expect(stored_upload.url).not_to eq(signed_url)
expect(signed_url).to match(/Amz-Credential/)
end
it "should return CDN URL when enabled" do
SiteSetting.s3_use_cdn_url_for_all_uploads = true
SiteSetting.authorized_extensions = "pdf"
SiteSetting.s3_cdn_url = "https://example-cdn.com"
upload = UploadCreator.new(pdf_file, pdf_filename, opts).create_for(user.id)
stored_upload = Upload.last
cdn_url = Discourse.store.url_for(stored_upload)
expect(cdn_url).to match(/example-cdn\.com/)
end
end
context "when the upload already exists based on the sha1" do