diff --git a/app/logical/iqdb.rb b/app/logical/iqdb.rb index 4f208cb..cf5f881 100644 --- a/app/logical/iqdb.rb +++ b/app/logical/iqdb.rb @@ -54,18 +54,24 @@ module Iqdb end def query_file(file, score_cutoff) - thumb = generate_thumbnail(file.path) - return [] unless thumb + Tempfile.open("yiffy2-#{file.md5}") do |tempfile| + file.binmode + tempfile.binmode + tempfile.write(file.read) + tempfile.rewind + thumb = generate_thumbnail(tempfile.path) + raise(Error, "failed to generate thumb for #{file.md5}") unless thumb - response = make_request("/query", :post, get_channels_data(thumb)) - return [] if response.status != 200 + response = make_request("/query", :post, get_channels_data(thumb)) + raise(Error, "iqdb request failed") if response.status != 200 - process_iqdb_result(JSON.parse(response.body), score_cutoff) + process_iqdb_result(JSON.parse(response.body), score_cutoff) + end end def query_hash(hash, score_cutoff) response = make_request("/query", :post, { hash: hash }) - return [] if response.status != 200 + raise(Error, "iqdb request failed") if response.status != 200 process_iqdb_result(JSON.parse(response.body), score_cutoff) end @@ -73,7 +79,7 @@ module Iqdb def process_iqdb_result(json, score_cutoff) raise(Error, "Server returned an error. Most likely the url is not found.") unless json.is_a?(Array) - json.filter! { |entry| (entry["score"] || 0) >= (score_cutoff.presence || 60).to_i } + json.filter! { |entry| (entry["score"] || 0) >= (score_cutoff.presence || 50).to_i } json.map do |x| x["image"] = APIImage.find_by!(iqdb_id: x["post_id"]) x