FIX: ShrinkUploadedImage was broken since cb12a721 (#13474)

This commit is contained in:
Jarek Radosz 2021-06-22 14:34:38 +02:00 committed by GitHub
parent 1a6759a5d9
commit cd8a82a82f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,13 +75,9 @@ class ShrinkUploadedImage
posts.each do |post|
transform_post(post, original_upload, upload)
if post.custom_fields[Post::DOWNLOADED_IMAGES].present?
downloaded_images = JSON.parse(post.custom_fields[Post::DOWNLOADED_IMAGES])
end
if post.raw_changed?
log "Updating post"
elsif downloaded_images&.has_value?(original_upload.id)
elsif post.downloaded_images.has_value?(original_upload.id)
log "A hotlinked, unreferenced image"
elsif post.raw.include?(upload.short_url)
log "Already processed"
@ -192,14 +188,12 @@ class ShrinkUploadedImage
)
end
if existing_upload && post.custom_fields[Post::DOWNLOADED_IMAGES].present?
downloaded_images = JSON.parse(post.custom_fields[Post::DOWNLOADED_IMAGES])
downloaded_images.transform_values! do |upload_id|
if existing_upload && post.downloaded_images.present?
downloaded_images = post.downloaded_images.transform_values do |upload_id|
upload_id == original_upload.id ? upload.id : upload_id
end
post.custom_fields[Post::DOWNLOADED_IMAGES] = downloaded_images.to_json if downloaded_images.present?
post.custom_fields[Post::DOWNLOADED_IMAGES] = downloaded_images
post.save_custom_fields
end