FIX: ensure local images use local CDN when uploads are stored on S3

When the S3 store was enabled, we were only applying the S3 CDN.
So all images stored locally, like the emojis, were never put on the local CDN.

Fixed a bunch of CookedPostProcessor test by adding a call to 'optimize_urls'
in order to get final URLs.

I also removed the unnecessary PrettyText.add_s3_cdn method since this is already
handled in the CookedPostProcessor.
This commit is contained in:
Régis Hanol
2019-02-20 19:24:38 +01:00
parent 964e7edcaf
commit 664e90bd17
6 changed files with 108 additions and 112 deletions

View File

@@ -389,7 +389,7 @@ class CookedPostProcessor
if upload
thumbnail = upload.thumbnail(w, h)
if thumbnail && thumbnail.filesize.to_i < upload.filesize
img["src"] = UrlHelper.cook_url(thumbnail.url)
img["src"] = thumbnail.url
srcset = +""
@@ -408,11 +408,11 @@ class CookedPostProcessor
img["srcset"] = "#{UrlHelper.cook_url(img["src"])}#{srcset}" if srcset.present?
end
else
img["src"] = UrlHelper.cook_url(upload.url)
img["src"] = upload.url
end
if small_upload = loading_image(upload)
img["data-small-upload"] = UrlHelper.cook_url(small_upload.url)
img["data-small-upload"] = small_upload.url
end
end
@@ -588,8 +588,10 @@ class CookedPostProcessor
end
end
@doc.css("img[src]").each do |img|
img["src"] = UrlHelper.cook_url(img["src"].to_s)
%w{src data-small-upload}.each do |selector|
@doc.css("img[#{selector}]").each do |img|
img[selector] = UrlHelper.cook_url(img[selector].to_s)
end
end
end