post process attachments
This commit is contained in:
parent
1f8eaa6ca3
commit
da614597fe
|
@ -16,10 +16,26 @@ class CookedPostProcessor
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_process
|
def post_process
|
||||||
|
post_process_attachments
|
||||||
post_process_images
|
post_process_images
|
||||||
post_process_oneboxes
|
post_process_oneboxes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def post_process_attachments
|
||||||
|
attachments.each do |attachment|
|
||||||
|
href = attachment['href']
|
||||||
|
attachment['href'] = relative_to_absolute(href)
|
||||||
|
if upload = Upload.get_from_url(href)
|
||||||
|
# update reverse index
|
||||||
|
associate_to_post(upload)
|
||||||
|
# append the size
|
||||||
|
append_human_size!(attachment, upload)
|
||||||
|
end
|
||||||
|
# mark as dirty
|
||||||
|
@dirty = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def post_process_images
|
def post_process_images
|
||||||
images = extract_images
|
images = extract_images
|
||||||
return if images.blank?
|
return if images.blank?
|
||||||
|
@ -33,7 +49,7 @@ class CookedPostProcessor
|
||||||
# make sure the img has proper width and height attributes
|
# make sure the img has proper width and height attributes
|
||||||
update_dimensions!(img)
|
update_dimensions!(img)
|
||||||
# retrieve the associated upload, if any
|
# retrieve the associated upload, if any
|
||||||
if upload = Upload.get_from_url(img['src'])
|
if upload = Upload.get_from_url(src)
|
||||||
# update reverse index
|
# update reverse index
|
||||||
associate_to_post(upload)
|
associate_to_post(upload)
|
||||||
end
|
end
|
||||||
|
@ -209,6 +225,22 @@ class CookedPostProcessor
|
||||||
rescue URI::InvalidURIError
|
rescue URI::InvalidURIError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def attachments
|
||||||
|
if SiteSetting.enable_s3_uploads?
|
||||||
|
@doc.css("a[href^=\"#{S3.base_url}\"]")
|
||||||
|
else
|
||||||
|
# local uploads are identified using a relative uri
|
||||||
|
@doc.css("a[href^=\"#{LocalStore.directory}\"]")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def append_human_size!(attachment, upload)
|
||||||
|
size = Nokogiri::XML::Node.new("span", @doc)
|
||||||
|
size["class"] = "size"
|
||||||
|
size.content = "(#{number_to_human_size(upload.filesize)})"
|
||||||
|
attachment.add_next_sibling(size)
|
||||||
|
end
|
||||||
|
|
||||||
def dirty?
|
def dirty?
|
||||||
@dirty
|
@dirty
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue