fix it better

This commit is contained in:
Donovan Daniels 2024-10-13 03:56:39 -05:00
parent 217ae78374
commit d47f57850e
Signed by: Donovan_DMC
GPG Key ID: 907D29CBFD6157BA
2 changed files with 4 additions and 3 deletions

View File

@ -63,6 +63,7 @@ module YiffRest
def query_iqdb
@sp = search_iqdb_params
@sp[:image_id] ||= @sp[:md5]
@sc = (@sp[:score_cutoff].presence || 60).to_i
if @sp[:file].present?
@results = Iqdb.query_file(@sp[:file], @sc)
@ -92,7 +93,7 @@ module YiffRest
end
def search_iqdb_params
permit_search_params(%i[file url image_id score_cutoff])
permit_search_params(%i[file url image_id md5 score_cutoff])
end
def create_params

View File

@ -54,13 +54,13 @@ module Iqdb
end
def query_file(file, score_cutoff)
Tempfile.open("yiffy2-#{file.md5}") do |tempfile|
Tempfile.open("yiffy2-queryfile") 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
raise(Error, "failed to generate thumb for file") unless thumb
response = make_request("/query", :post, get_channels_data(thumb))
raise(Error, "iqdb request failed") if response.status != 200