From ff3cd1443c253181eb7e7f3da94940ee73c4c228 Mon Sep 17 00:00:00 2001
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
Date: Tue, 7 Apr 2026 23:11:42 +0900
Subject: [PATCH] =?UTF-8?q?=E3=83=88=E3=82=A5=E3=83=BC=E3=83=88=E6=B7=BB?=
 =?UTF-8?q?=E4=BB=98=E3=81=AE=E5=8B=95=E7=94=BB=E3=82=92=E3=82=AF=E3=83=AA?=
 =?UTF-8?q?=E3=83=83=E3=82=AF=E3=81=97=E3=81=9F=E3=81=A8=E3=81=8D=E3=81=AB?=
 =?UTF-8?q?=E3=83=96=E3=83=A9=E3=82=A6=E3=82=B6=E3=81=A7=E9=96=8B=E3=81=8F?=
 =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B=20refs=20#1607?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 plugin/mastodon/parser.rb     |  2 +-
 plugin/openimg/model/photo.rb | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/plugin/mastodon/parser.rb b/plugin/mastodon/parser.rb
index e3c37b36..a37fac56 100644
--- a/plugin/mastodon/parser.rb
+++ b/plugin/mastodon/parser.rb
@@ -78,7 +78,7 @@ module Plugin::Mastodon::Parser
         Plugin::Score::HyperLinkNote.new(
           description: attachment.text_url || url,
           uri: url,
-          reference: Plugin.collect(:photo_filter, url).first
+          reference: (attachment.type == 'image') ? Plugin.collect(:photo_filter, url).first : nil
         )
     end
 
diff --git a/plugin/openimg/model/photo.rb b/plugin/openimg/model/photo.rb
index aed98641..9775f048 100644
--- a/plugin/openimg/model/photo.rb
+++ b/plugin/openimg/model/photo.rb
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+require 'uri'
+
 module Plugin::Openimg
   class Photo < Diva::Model
     include Diva::Model::PhotoMixin
@@ -7,8 +9,30 @@ module Plugin::Openimg
 
     field.uri    :perma_link
 
+    def self.supported_image_extensions
+      @supported_image_extensions ||= begin
+        GdkPixbuf::Pixbuf.formats.each_with_object({}) do |format, exts|
+          format.extensions.each do |ext|
+            exts[ext.downcase] = true
+          end
+        end.freeze
+      end
+    end
+
+    def self.supported_image_uri?(uri)
+      path = URI(uri.to_s).path
+      ext = File.extname(path).sub(/\A\./, '').downcase
+      return false if ext.empty?
+      supported_image_extensions.key?(ext)
+    rescue URI::InvalidURIError
+      false
+    end
+
     handle ->uri{
       uri_str = uri.to_s
+
+      next false unless supported_image_uri?(uri)
+
       openers = Plugin.collect(:openimg_image_openers)
       openers.any?{ |opener| opener.condition === uri_str } if !openers.first(1).empty?
     } do |uri|
-- 
2.53.0

