Skip to content

A platform for community discussion. Free, open, simple.

FIX: Use CDN URLs for topic thumbnails

David Taylor0495a748d098
diff --git a/app/models/topic.rb b/app/models/topic.rb
index cdbd6ee2852..22307a8dad1 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -84,6 +84,8 @@ class Topic < ActiveRecord::Base
Jobs.enqueue(:generate_topic_thumbnails, { topic_id: id, extra_sizes: extra_sizes })
end
+ infos.each { |i| i[:url] = UrlHelper.cook_url(i[:url], secure: original.secure?) }
+
infos.sort_by! { |i| -i[:width] * i[:height] }
end
@@ -102,7 +104,9 @@ class Topic < ActiveRecord::Base
record.max_width == Topic.share_thumbnail_size[0] &&
record.max_height == Topic.share_thumbnail_size[1]
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
def featured_users
diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb
index 73bb74ac256..d55a475c71e 100644
--- a/spec/components/topic_view_spec.rb
+++ b/spec/components/topic_view_spec.rb
@@ -726,9 +726,9 @@ describe TopicView do
end
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(2).image_url).to eq(op_upload.url)
- expect(topic_view_for_post(3).image_url).to eq(post3_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 end_with(op_upload.url)
+ expect(topic_view_for_post(3).image_url).to end_with(post3_upload.url)
end
end
@@ -736,7 +736,7 @@ describe TopicView 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(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
diff --git a/spec/integration/topic_thumbnail_spec.rb b/spec/integration/topic_thumbnail_spec.rb
index b288fb6c488..9ba35cbe970 100644
--- a/spec/integration/topic_thumbnail_spec.rb
+++ b/spec/integration/topic_thumbnail_spec.rb
@@ -31,7 +31,7 @@ describe "Topic Thumbnails" do
expect(thumbnails[0]["max_height"]).to eq(nil)
expect(thumbnails[0]["width"]).to eq(image.width)
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
args = Jobs::GenerateTopicThumbnails.jobs.last["args"].first
diff --git a/spec/serializers/topic_view_serializer_spec.rb b/spec/serializers/topic_view_serializer_spec.rb
index 0adfbfe08ae..5da26a674ec 100644
--- a/spec/serializers/topic_view_serializer_spec.rb
+++ b/spec/serializers/topic_view_serializer_spec.rb
@@ -54,7 +54,7 @@ describe TopicViewSerializer do
it 'should return the image url' do
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
it 'should have thumbnails' do