refactor iqdb query support

This commit is contained in:
Albert Yi
2018-06-14 17:03:41 -07:00
parent 97d0dca8a4
commit 9510dead9f
11 changed files with 134 additions and 125 deletions

View File

@@ -1,29 +1,12 @@
# todo: move this to iqdbs
class IqdbQueriesController < ApplicationController
respond_to :html, :json, :xml
def show
@results = find_similar
respond_with(@results) do |fmt|
fmt.html { render :layout => false, :action => "create_by_url" }
fmt.js { render :layout => false, :action => "create_by_post" }
if params[:matches]
@matches = JSON.parse(params[:matches])
@matches = @matches.map {|x| [Post.find(x[0]), x[1]]}
end
end
def check
@results = find_similar
respond_with(@results)
end
# Support both POST /iqdb_queries and GET /iqdb_queries.
alias_method :create, :show
protected
def find_similar
return [] if params[:url].blank? && params[:post_id].blank?
params[:url] = Post.find(params[:post_id]).preview_file_url if params[:post_id].present?
Iqdb::Download.find_similar(params[:url])
respond_with(@matches)
end
end