From c0bd6253e21867f231b1952d9f495467be7f0594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Wed, 12 Jun 2024 22:31:52 +0800 Subject: [PATCH] Fix img src not decode. --- app/controllers/page_contents_controller.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/page_contents_controller.rb b/app/controllers/page_contents_controller.rb index 62c6476..1b698bc 100644 --- a/app/controllers/page_contents_controller.rb +++ b/app/controllers/page_contents_controller.rb @@ -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))