mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 23:12:45 +08:00
parent
1a6759a5d9
commit
cd8a82a82f
|
@ -75,13 +75,9 @@ class ShrinkUploadedImage
|
||||||
posts.each do |post|
|
posts.each do |post|
|
||||||
transform_post(post, original_upload, upload)
|
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?
|
if post.raw_changed?
|
||||||
log "Updating post"
|
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"
|
log "A hotlinked, unreferenced image"
|
||||||
elsif post.raw.include?(upload.short_url)
|
elsif post.raw.include?(upload.short_url)
|
||||||
log "Already processed"
|
log "Already processed"
|
||||||
|
@ -192,14 +188,12 @@ class ShrinkUploadedImage
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
if existing_upload && post.custom_fields[Post::DOWNLOADED_IMAGES].present?
|
if existing_upload && post.downloaded_images.present?
|
||||||
downloaded_images = JSON.parse(post.custom_fields[Post::DOWNLOADED_IMAGES])
|
downloaded_images = post.downloaded_images.transform_values do |upload_id|
|
||||||
|
|
||||||
downloaded_images.transform_values! do |upload_id|
|
|
||||||
upload_id == original_upload.id ? upload.id : upload_id
|
upload_id == original_upload.id ? upload.id : upload_id
|
||||||
end
|
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
|
post.save_custom_fields
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user