Fix img src not decode.

This commit is contained in:
邱博亞 2024-06-12 22:31:52 +08:00
parent 9056303b5d
commit c0bd6253e2
1 changed files with 9 additions and 6 deletions

View File

@ -28,12 +28,15 @@ class PageContentsController < OrbitAdminController
metas << {"property" => "og:image", "content" => URI.join(request.base_url, URI.encode(img_src)).to_s}
if img_src.start_with?('/')
img_src_path = File.join('public', img_src)
image = MiniMagick::Image.open(img_src_path)
if image[:width]
metas << {"property" => "og:image:width", "content" => image[:width].to_s}
end
if image[:height]
metas << {"property" => "og:image:height", "content" => image[:height].to_s}
img_src_path = URI.decode(img_src_path)
if File.exist?(img_src_path)
image = MiniMagick::Image.open(img_src_path)
if image[:width]
metas << {"property" => "og:image:width", "content" => image[:width].to_s}
end
if image[:height]
metas << {"property" => "og:image:height", "content" => image[:height].to_s}
end
end
else
res = get_response(URI.parse(img_src))