FIX: Use CDN URLs for topic thumbnails

This commit is contained in:
David Taylor 2020-05-15 13:35:20 +01:00
parent 162d125b83
commit 0495a748d0
No known key found for this signature in database
GPG Key ID: 46904C18B1D3F434
4 changed files with 11 additions and 7 deletions

View File

@ -84,6 +84,8 @@ class Topic < ActiveRecord::Base
Jobs.enqueue(:generate_topic_thumbnails, { topic_id: id, extra_sizes: extra_sizes }) Jobs.enqueue(:generate_topic_thumbnails, { topic_id: id, extra_sizes: extra_sizes })
end end
infos.each { |i| i[:url] = UrlHelper.cook_url(i[:url], secure: original.secure?) }
infos.sort_by! { |i| -i[:width] * i[:height] } infos.sort_by! { |i| -i[:width] * i[:height] }
end end
@ -102,7 +104,9 @@ class Topic < ActiveRecord::Base
record.max_width == Topic.share_thumbnail_size[0] && record.max_width == Topic.share_thumbnail_size[0] &&
record.max_height == Topic.share_thumbnail_size[1] record.max_height == Topic.share_thumbnail_size[1]
end end
thumbnail&.optimized_image&.url || image_upload&.url
raw_url = thumbnail&.optimized_image&.url || image_upload&.url
UrlHelper.cook_url(raw_url, secure: image_upload&.secure?)
end end
def featured_users def featured_users

View File

@ -726,9 +726,9 @@ describe TopicView do
end end
it "uses the topic image as a fallback when posts have no image" do it "uses the topic image as a fallback when posts have no image" do
expect(topic_view_for_post(1).image_url).to eq(op_upload.url) expect(topic_view_for_post(1).image_url).to end_with(op_upload.url)
expect(topic_view_for_post(2).image_url).to eq(op_upload.url) expect(topic_view_for_post(2).image_url).to end_with(op_upload.url)
expect(topic_view_for_post(3).image_url).to eq(post3_upload.url) expect(topic_view_for_post(3).image_url).to end_with(post3_upload.url)
end end
end end
@ -736,7 +736,7 @@ describe TopicView do
it "returns nil when posts have no image" do it "returns nil when posts have no image" do
expect(topic_view_for_post(1).image_url).to eq(nil) expect(topic_view_for_post(1).image_url).to eq(nil)
expect(topic_view_for_post(2).image_url).to eq(nil) expect(topic_view_for_post(2).image_url).to eq(nil)
expect(topic_view_for_post(3).image_url).to eq(post3_upload.url) expect(topic_view_for_post(3).image_url).to end_with(post3_upload.url)
end end
end end
end end

View File

@ -31,7 +31,7 @@ describe "Topic Thumbnails" do
expect(thumbnails[0]["max_height"]).to eq(nil) expect(thumbnails[0]["max_height"]).to eq(nil)
expect(thumbnails[0]["width"]).to eq(image.width) expect(thumbnails[0]["width"]).to eq(image.width)
expect(thumbnails[0]["height"]).to eq(image.height) expect(thumbnails[0]["height"]).to eq(image.height)
expect(thumbnails[0]["url"]).to eq(image.url) expect(thumbnails[0]["url"]).to end_with(image.url)
# Run the job # Run the job
args = Jobs::GenerateTopicThumbnails.jobs.last["args"].first args = Jobs::GenerateTopicThumbnails.jobs.last["args"].first

View File

@ -54,7 +54,7 @@ describe TopicViewSerializer do
it 'should return the image url' do it 'should return the image url' do
json = serialize_topic(topic, user) json = serialize_topic(topic, user)
expect(json[:image_url]).to eq(image_upload.url) expect(json[:image_url]).to end_with(image_upload.url)
end end
it 'should have thumbnails' do it 'should have thumbnails' do