refactor iqdb endpoints

This commit is contained in:
r888888888
2018-06-23 10:32:39 -07:00
parent 27baa08e59
commit 3ba5c6fb51
11 changed files with 93 additions and 53 deletions

View File

@@ -3,35 +3,27 @@ class IqdbQueriesController < ApplicationController
def show
if params[:url]
url = URI.parse(Danbooru.config.iqdbs_server)
url.path = "/similar"
url.query = {callback: iqdb_queries_url(format: params[:format]), url: params[:url]}.to_query
redirect_to url.to_s
return
@matches = IqdbProxy.query(params[:url])
end
if params[:post_id]
post = Post.find(params[:post_id])
url = URI.parse(Danbooru.config.iqdbs_server)
url.path = "/similar"
url.query = {callback: iqdb_queries_url(format: params[:format]), url: post.preview_file_url}.to_query
redirect_to url.to_s
return
@matches = IqdbProxy.query(Post.find(params[:post_id]).preview_file_url)
end
if params[:matches]
@matches = JSON.parse(params[:matches])
@matches = @matches.map {|x| [Post.find(x[0]), x[1]]}
@matches = IqdbProxy.decorate_posts(JSON.parse(params[:matches]))
end
respond_with(@matches)
end
respond_with(@matches) do |fmt|
fmt.html
def preview
url = URI.parse(Danbooru.config.iqdbs_server)
url.path = "/similar"
url.query = {url: params[:url]}.to_query
@results = HTTParty.get(url.to_s).parsed_response
render layout: false
fmt.html.xhr do
render layout: false
end
fmt.json do
render json: @matches
end
end
end
end