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 def query_iqdb
@sp = search_iqdb_params @sp = search_iqdb_params
@sp[:image_id] ||= @sp[:md5]
@sc = (@sp[:score_cutoff].presence || 60).to_i @sc = (@sp[:score_cutoff].presence || 60).to_i
if @sp[:file].present? if @sp[:file].present?
@results = Iqdb.query_file(@sp[:file], @sc) @results = Iqdb.query_file(@sp[:file], @sc)
@ -92,7 +93,7 @@ module YiffRest
end end
def search_iqdb_params 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 end
def create_params def create_params

View File

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