diff --git a/app/assets/stylesheets/specific/iqdb_queries.scss b/app/assets/stylesheets/specific/iqdb_queries.scss new file mode 100644 index 000000000..cab8d0f3b --- /dev/null +++ b/app/assets/stylesheets/specific/iqdb_queries.scss @@ -0,0 +1,13 @@ +div#c-iqdb-queries { + div#a-check { + article.post-preview { + height: 180px; + width: 180px; + border: lightgrey solid 1px; + + img { + margin-top: 10px; + } + } + } +} diff --git a/app/controllers/iqdb_queries_controller.rb b/app/controllers/iqdb_queries_controller.rb index abd23e002..b9aae52c0 100644 --- a/app/controllers/iqdb_queries_controller.rb +++ b/app/controllers/iqdb_queries_controller.rb @@ -2,31 +2,49 @@ class IqdbQueriesController < ApplicationController respond_to :html, :json, :xml - def index - if !Danbooru.config.iqdbs_server - raise NotImplementedError.new("the IQDBs service isn't configured. Similarity searches are not available.") - end - + def show + server_check if params[:url] create_by_url + respond_with(@results) do |fmt| + fmt.html { render :layout => false, :action => "create_by_url" } + end elsif params[:post_id] create_by_post + respond_with(@results) do |fmt| + fmt.js { render :layout => false, :action => "create_by_post" } + end else render :nothing => true, :status => 422 end end + def check + server_check + if params[:url].present? + create_by_url + elsif params[:post_id].present? + create_by_post + else + @results = [] + end + respond_with(@results) + end + # Support both POST /iqdb_queries and GET /iqdb_queries. - alias_method :create, :index + alias_method :create, :show protected + def server_check + if !Danbooru.config.iqdbs_server + raise NotImplementedError.new("the IQDBs service isn't configured. Similarity searches are not available.") + end + end + def create_by_url @download = Iqdb::Download.new(params[:url]) @download.find_similar @results = @download.matches - respond_with(@results) do |fmt| - fmt.html { render :layout => false, :action => "create_by_url" } - end end def create_by_post @@ -34,8 +52,5 @@ protected @download = Iqdb::Download.new(@post.complete_preview_file_url) @download.find_similar @results = @download.matches - respond_with(@results) do |fmt| - fmt.js { render :layout => false, :action => "create_by_post" } - end end end diff --git a/app/views/iqdb_queries/check.html.erb b/app/views/iqdb_queries/check.html.erb new file mode 100644 index 000000000..891fdc4d0 --- /dev/null +++ b/app/views/iqdb_queries/check.html.erb @@ -0,0 +1,34 @@ +
No matches found
+ <% end %> +