iqdb: proxy iqdb searches through danbooru.

Previously the search form on the /iqdb_queries page submitted directly
to the iqdb service (karasuma.donmai.us), which redirected back to
Danbooru with the search results.

This was different than API requests, which submitted to
/iqdb_queries.json which proxied the call to iqdb through Danbooru.
Because of this, searches on the /iqdb_queries page had different
behavior than API requests. Things like filesize limits and referrer
spoofing were handled differently.

Now searches on the /iqdb_queries page submit directly to Danbooru. This
is simpler and it means that API requests and HTML requests have the
same behavior.
This commit is contained in:
evazion
2019-10-14 21:16:04 -05:00
parent f7116ad1c4
commit ae521e600e
5 changed files with 43 additions and 34 deletions

View File

@@ -2,16 +2,12 @@ class IqdbQueriesController < ApplicationController
respond_to :html, :json, :xml, :js
def show
if params[:url]
url = Sources::Strategies.find(params[:url]).image_url
@matches = IqdbProxy.query(url, params[:limit], params[:similarity])
elsif params[:post_id]
url = Post.find(params[:post_id]).preview_file_url
@matches = IqdbProxy.query(url, params[:limit], params[:similarity])
elsif params[:matches]
@matches = IqdbProxy.decorate_posts(JSON.parse(params[:matches]))
end
# XXX allow bare search params for backwards compatibility.
search_params.merge!(params.slice(:url, :post_id, :limit, :similarity).permit!)
respond_with(@matches)
@matches = IqdbProxy.search(search_params)
respond_with(@matches, template: "iqdb_queries/show")
end
alias create show
end