support json for iqdb query actions

This commit is contained in:
Albert Yi
2018-06-20 11:53:44 -07:00
parent 28663351d1
commit e262295cf1
4 changed files with 6 additions and 22 deletions

View File

@@ -1,11 +1,11 @@
class IqdbQueriesController < ApplicationController
respond_to :html, :json, :xml
respond_to :html, :json
def show
if params[:url]
url = URI.parse(Danbooru.config.iqdbs_server)
url.path = "/similar"
url.query = {callback: iqdb_queries_url, url: params[:url]}.to_query
url.query = {callback: iqdb_queries_url(format: params[:format]), url: params[:url]}.to_query
redirect_to url.to_s
return
end
@@ -14,7 +14,7 @@ class IqdbQueriesController < ApplicationController
post = Post.find(params[:post_id])
url = URI.parse(Danbooru.config.iqdbs_server)
url.path = "/similar"
url.query = {callback: iqdb_queries_url, url: post.preview_file_url}.to_query
url.query = {callback: iqdb_queries_url(format: params[:format]), url: post.preview_file_url}.to_query
redirect_to url.to_s
return
end

View File

@@ -1,10 +0,0 @@
var html = '';
<% if @results.any? %>
<% @results.each do |match| %>
html += '<%= j PostPresenter.preview(match[:post], :tags => "status:any") %>';
<% end %>
<% else %>
html += '<p>No matches found</p>';
<% end %>
$("<div></div>").html(html).dialog({title: "Similar Posts", modal: true, width: "600px"});

View File

@@ -1,9 +0,0 @@
<% if @results.any? %>
<h3>Similar</h3>
<% @results.each do |match| %>
<%= PostPresenter.preview(match[:post], :tags => "status:any", :size => true, :similarity => match[:score]) %>
<% end %>
<% else %>
<h3>Similar</h3>
<p>No matches found</p>
<% end %>

View File

@@ -0,0 +1,3 @@
<% if @matches %>
<%= raw @matches.to_json %>
<% end %>