FIX: return cdn url for uploads if available.

Currently it is displaying non-cdn urls in the composer preview.
This commit is contained in:
Vinoth Kannan 2020-07-02 06:36:14 +05:30
parent 8bc61e84a7
commit f11363d446
2 changed files with 8 additions and 1 deletions

View File

@ -16,7 +16,7 @@ class UploadSerializer < ApplicationSerializer
:human_filesize :human_filesize
def url def url
return object.url if !object.secure || !SiteSetting.secure_media? return Discourse.store.cdn_url(object.url) if !object.secure || !SiteSetting.secure_media?
UrlHelper.cook_url(object.url, secure: object.secure) UrlHelper.cook_url(object.url, secure: object.secure)
end end
end end

View File

@ -42,6 +42,13 @@ describe UploadsController do
expect(Jobs::CreateAvatarThumbnails.jobs.size).to eq(1) expect(Jobs::CreateAvatarThumbnails.jobs.size).to eq(1)
end end
it 'returns cdn url' do
set_cdn_url "https://awesome.com"
post "/uploads.json", params: { file: logo, type: "composer" }
expect(response.status).to eq 200
expect(response.parsed_body["url"]).to start_with("https://awesome.com/uploads/default/")
end
it 'is successful with an attachment' do it 'is successful with an attachment' do
SiteSetting.authorized_extensions = "*" SiteSetting.authorized_extensions = "*"