mirror of
https://github.com/discourse/discourse.git
synced 2025-06-05 14:07:30 +08:00
FIX: Copying image markdown for secure media loading full image (#9488)
* When copying the markdown for an image between posts, we were not adding the srcset and data-small-image attributes which are done by calling optimize_image! in cooked post processor * Refactored the code which was confusing in its current state (the consider_for_reuse method was super confusing) and fixed the issue
This commit is contained in:
@ -123,13 +123,26 @@ class Upload < ActiveRecord::Base
|
||||
"upload://#{short_url_basename}"
|
||||
end
|
||||
|
||||
def uploaded_before_secure_media_enabled?
|
||||
original_sha1.blank?
|
||||
end
|
||||
|
||||
def matching_access_control_post?(post)
|
||||
access_control_post_id == post.id
|
||||
end
|
||||
|
||||
def copied_from_other_post?(post)
|
||||
return false if access_control_post_id.blank?
|
||||
!matching_access_control_post?(post)
|
||||
end
|
||||
|
||||
def short_path
|
||||
self.class.short_path(sha1: self.sha1, extension: self.extension)
|
||||
end
|
||||
|
||||
def self.consider_for_reuse(upload, post)
|
||||
return upload if !SiteSetting.secure_media? || upload.blank? || post.blank?
|
||||
return nil if upload.access_control_post_id != post.id || upload.original_sha1.blank?
|
||||
return nil if !upload.matching_access_control_post?(post) || upload.uploaded_before_secure_media_enabled?
|
||||
upload
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user