mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 23:11:13 +08:00
FEATURE: pull onebox images
This commit is contained in:
@ -51,7 +51,7 @@ class CookedPostProcessor
|
||||
end
|
||||
|
||||
def keep_reverse_index_up_to_date
|
||||
upload_ids = Set.new
|
||||
upload_ids = Array.new
|
||||
|
||||
@doc.css("a/@href", "img/@src").each do |media|
|
||||
if upload = Upload.get_from_url(media.value)
|
||||
@ -59,6 +59,8 @@ class CookedPostProcessor
|
||||
end
|
||||
end
|
||||
|
||||
upload_ids.concat(oneboxed_image_uploads.pluck(:id))
|
||||
|
||||
values = upload_ids.map{ |u| "(#{@post.id},#{u})" }.join(",")
|
||||
PostUpload.transaction do
|
||||
PostUpload.delete_all(post_id: @post.id)
|
||||
@ -105,7 +107,12 @@ class CookedPostProcessor
|
||||
end
|
||||
|
||||
def oneboxed_images
|
||||
@doc.css(".onebox-result img, .onebox img")
|
||||
@doc.css(".onebox-body img, .onebox img")
|
||||
end
|
||||
|
||||
def oneboxed_image_uploads
|
||||
urls = oneboxed_images.map { |img| img["src"] }
|
||||
Upload.where(origin: urls)
|
||||
end
|
||||
|
||||
def limit_size!(img)
|
||||
@ -301,8 +308,14 @@ class CookedPostProcessor
|
||||
Oneboxer.onebox(url, args)
|
||||
end
|
||||
|
||||
# make sure we grab dimensions for oneboxed images
|
||||
oneboxed_images.each { |img| limit_size!(img) }
|
||||
uploads = oneboxed_image_uploads.select(:url, :origin)
|
||||
oneboxed_images.each do |img|
|
||||
upload = uploads.detect { |u| u.origin == img["src"] }
|
||||
next unless upload.present?
|
||||
img["src"] = upload.url
|
||||
# make sure we grab dimensions for oneboxed images
|
||||
limit_size!(img)
|
||||
end
|
||||
|
||||
# respect nofollow admin settings
|
||||
if !@cooking_options[:omit_nofollow] && SiteSetting.add_rel_nofollow_to_user_content
|
||||
|
Reference in New Issue
Block a user