FIX: prevent infinite 'pull_hotlinked_images' jobs when a oneboxed image has a different scheme

This commit is contained in:
Régis Hanol 2017-10-18 01:50:23 +02:00
parent c1c03d8de0
commit 65dc47adb4
1 changed files with 12 additions and 3 deletions

View File

@ -110,8 +110,16 @@ class CookedPostProcessor
end end
def oneboxed_image_uploads def oneboxed_image_uploads
urls = oneboxed_images.map { |img| img["src"] } urls = Set.new
Upload.where(origin: urls)
oneboxed_images.each do |img|
url = img["src"].sub(/^https?:/i, "")
urls << url
urls << "http:#{url}"
urls << "https:#{url}"
end
Upload.where(origin: urls.to_a)
end end
def limit_size!(img) def limit_size!(img)
@ -323,7 +331,8 @@ class CookedPostProcessor
uploads = oneboxed_image_uploads.select(:url, :origin) uploads = oneboxed_image_uploads.select(:url, :origin)
oneboxed_images.each do |img| oneboxed_images.each do |img|
upload = uploads.detect { |u| u.origin == img["src"] } url = img["src"].sub(/^https?:/i, "")
upload = uploads.find { |u| u.origin.sub(/^https?:/i, "") == url }
next unless upload.present? next unless upload.present?
img["src"] = upload.url img["src"] = upload.url
# make sure we grab dimensions for oneboxed images # make sure we grab dimensions for oneboxed images