From abee048de551d0171cb636673f425876a1c9a0ff Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 22 Oct 2019 12:59:00 -0500 Subject: [PATCH] iqdb: use preview image url for iqdb lookups. * Fix the IQDB lookup to handle error messages returned by IQDB. * Fix `undefined method `>=' for nil:NilClass` error when trying to upload ugoiras. Using the preview image for IQDB lookups should be faster and give the same results as the full image, plus it should work with things like ugoiras and videos that IQDB can't handle. Also add an image_url param so that API users can continue using the full image if needed. --- app/logical/iqdb_proxy.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/logical/iqdb_proxy.rb b/app/logical/iqdb_proxy.rb index efe51978f..dc033eebf 100644 --- a/app/logical/iqdb_proxy.rb +++ b/app/logical/iqdb_proxy.rb @@ -15,7 +15,10 @@ class IqdbProxy if params[:file].present? results = query(file: params[:file], limit: limit) elsif params[:url].present? - url = Sources::Strategies.find(params[:url]).image_url + url = Sources::Strategies.find(params[:url]).preview_url + results = query(url: url, limit: limit) + elsif params[:image_url].present? + url = Sources::Strategies.find(params[:image_url]).image_url results = query(url: url, limit: limit) elsif params[:post_id].present? url = Post.find(params[:post_id]).preview_file_url @@ -34,6 +37,7 @@ class IqdbProxy def self.query(params) response = HTTParty.post("#{Danbooru.config.iqdbs_server}/similar", body: params, **Danbooru.config.httparty_options) raise Error, "HTTP error: #{response.code} #{response.message}" unless response.success? + raise Error, "IQDB error: #{response.parsed_response.first}" if response.parsed_response.try(:first).is_a?(String) response.parsed_response end