iqdb: fix error with file uploads.

Fix "cannot determine size of body" errors on upload page. Caused by
exception during IQDB lookup. We were posting the form data wrong, we
need to wrap the file with HTTP::FormData::File and pass it through the
`form` parameter.
This commit is contained in:
evazion
2020-06-17 02:28:16 -05:00
parent 91beb288b6
commit b8b5c8d6a0

View File

@@ -50,9 +50,12 @@ class IqdbProxy
file.try(:close)
end
def query(params)
def query(file: nil, url: nil, limit: 20)
raise NotImplementedError, "the IQDBs service isn't configured" unless enabled?
response = http.post("#{iqdbs_server}/similar", body: params)
file = HTTP::FormData::File.new(file) if file
form = { file: file, url: url, limit: limit }.compact
response = http.post("#{iqdbs_server}/similar", form: form)
raise Error, "IQDB error: #{response.status}" if response.status != 200
raise Error, "IQDB error: #{response.parse["error"]}" if response.parse.is_a?(Hash)