diff --git a/app/assets/stylesheets/forum_post_votes_controller.scss b/app/assets/stylesheets/forum_post_votes_controller.scss
deleted file mode 100644
index 5aac47c6d..000000000
--- a/app/assets/stylesheets/forum_post_votes_controller.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-// Place all the styles related to the ForumPostVotesController controller here.
-// They will automatically be included in application.css.
-// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/assets/stylesheets/specific/dropzone.scss b/app/assets/stylesheets/specific/dropzone.scss
new file mode 100644
index 000000000..a3c33331e
--- /dev/null
+++ b/app/assets/stylesheets/specific/dropzone.scss
@@ -0,0 +1,41 @@
+#filedropzone {
+ border: 4px dashed #DDD;
+ padding: 0;
+ min-height: 100px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ border-radius: 4px;
+
+ .placeholder {
+ font-style: italic;
+ color: #333;
+ height: 100%;
+ }
+
+ &.error {
+ border-color: darken(#f2dede, 30%);
+ background-color: #f2dede;
+ }
+
+ &.success {
+ border-color: darken(#dff0d8, 30%);
+ background-color: #dff0d8;
+ }
+}
+
+.dz-preview {
+ margin-bottom: 1em;
+}
+
+.dz-progress {
+ height: 20px;
+ width: 300px;
+ border: 1px solid #CCC;
+
+ .dz-upload {
+ background-color: #F5F5FF;
+ display: block;
+ height: 20px;
+ }
+}
\ No newline at end of file
diff --git a/app/assets/stylesheets/specific/iqdb_queries.scss b/app/assets/stylesheets/specific/iqdb_queries.scss
index cab8d0f3b..5386b552d 100644
--- a/app/assets/stylesheets/specific/iqdb_queries.scss
+++ b/app/assets/stylesheets/specific/iqdb_queries.scss
@@ -9,5 +9,9 @@ div#c-iqdb-queries {
margin-top: 10px;
}
}
+
+ #filedropzone {
+ margin: 1em 0;
+ }
}
}
diff --git a/app/assets/stylesheets/specific/uploads.scss b/app/assets/stylesheets/specific/uploads.scss
index 1cc7bece5..49b71d0b1 100644
--- a/app/assets/stylesheets/specific/uploads.scss
+++ b/app/assets/stylesheets/specific/uploads.scss
@@ -34,48 +34,6 @@ div#c-uploads {
div.field_with_errors {
display: inline;
}
-
- #filedropzone {
- border: 4px dashed #DDD;
- padding: 0;
- min-height: 100px;
- display: flex;
- align-items: center;
- justify-content: center;
- border-radius: 4px;
-
- .placeholder {
- font-style: italic;
- color: #333;
- height: 100%;
- }
-
- &.error {
- border-color: darken(#f2dede, 30%);
- background-color: #f2dede;
- }
-
- &.success {
- border-color: darken(#dff0d8, 30%);
- background-color: #dff0d8;
- }
- }
-
- .dz-preview {
- margin-bottom: 1em;
- }
-
- .dz-progress {
- height: 20px;
- width: 300px;
- border: 1px solid #CCC;
-
- .dz-upload {
- background-color: #F5F5FF;
- display: block;
- height: 20px;
- }
- }
}
div#a-index {
diff --git a/app/controllers/iqdb_queries_controller.rb b/app/controllers/iqdb_queries_controller.rb
index ee865c974..b18425361 100644
--- a/app/controllers/iqdb_queries_controller.rb
+++ b/app/controllers/iqdb_queries_controller.rb
@@ -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
diff --git a/app/views/iqdb_queries/check.html.erb b/app/views/iqdb_queries/check.html.erb
deleted file mode 100644
index 891fdc4d0..000000000
--- a/app/views/iqdb_queries/check.html.erb
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
-
IQDB Queries
-
- <%= form_tag(check_iqdb_queries_path, :method => :get, :class => "simple_form inline-form" ) do %>
-
- <%= label_tag "url", "URL", class: "string optional" %>
- <%= text_field_tag "url", params[:url] %>
-
-
- <%= label_tag "post_id", "Post ID", class: "string optional" %>
- <%= text_field_tag "post_id", params[:post_id] %>
-
- <%= submit_tag "Check" %>
- <% end %>
-
- <% if params[:url].present? || params[:post_id].present? %>
-
- Similar results
- <% if @results.any? %>
- <% @results.each do |match| %>
- <%= PostPresenter.preview(match[:post], :tags => "status:any", :size => true, :similarity => match[:score]) %>
- <% end %>
- <% else %>
- No matches found
- <% end %>
-
- <% end %>
-
-
-
-<% content_for(:page_title) do %>
- IQDB Queries - <%= Danbooru.config.app_name %>
-<% end %>
diff --git a/app/views/iqdb_queries/show.html.erb b/app/views/iqdb_queries/show.html.erb
new file mode 100644
index 000000000..542be6a2f
--- /dev/null
+++ b/app/views/iqdb_queries/show.html.erb
@@ -0,0 +1,78 @@
+
+
+
Similar Images Search
+
+ You can upload a file or paste a URL to perform an image similarity search with every upload on <%= Danbooru.config.app_name %>. Note that this page will redirect you to <%= link_to "IQDBS", Danbooru.config.iqdbs_server %>. You will be redirected back here once the search is executed.
+
+ <%= form_tag("#{Danbooru.config.iqdbs_server}/similar", method: :post, class: "simple_form", multipart: true ) do %>
+ <%= hidden_field_tag "callback", iqdb_queries_url %>
+
+
+ <%= label_tag "url", "URL", class: "string optional" %>
+ <%= text_field_tag "url", params[:url] %>
+
+
+
+ <%= label_tag "file", "File", class: "string optional" %>
+ <%= file_field_tag :file, :size => 50 %>
+
+
+
+ Drag and drop a file here
+
+
+ <%= submit_tag "Search" %>
+ <% end %>
+
+
+ <% if @matches %>
+
+ Similar results
+ <% if @matches.any? %>
+ <% @matches.each do |post, score| %>
+ <%= PostPresenter.preview(post, :tags => "status:any", :size => true, :similarity => score) %>
+ <% end %>
+ <% else %>
+ No matches found
+ <% end %>
+
+ <% end %>
+
+
+
+<% content_for(:page_title) do %>
+ Similar Images Search - <%= Danbooru.config.app_name %>
+<% end %>
+
+<% content_for(:html_header) do %>
+
+
+<% end %>
diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb
index 731ac92c7..068319d4f 100644
--- a/app/views/static/site_map.html.erb
+++ b/app/views/static/site_map.html.erb
@@ -16,6 +16,7 @@
<% if CurrentUser.is_moderator? %>
<%= link_to("Mass Edit", edit_moderator_tag_path) %>
<% end %>
+ <%= link_to("Similar Images Search", iqdb_queries_path) %>
Post Events
@@ -33,7 +34,6 @@
- <%= link_to("Bookmarklet", bookmarklet_path) %>
- <%= link_to("User Scripts", wiki_pages_path(title: "about:userscripts")) %>
- <%= link_to("API Documentation", wiki_pages_path(:title => "help:api")) %>
- - <%= link_to("IQDB Queries", check_iqdb_queries_path) %>
Artists
diff --git a/app/views/uploads/_secondary_links.html.erb b/app/views/uploads/_secondary_links.html.erb
index 2bf7f9cda..678134ae3 100644
--- a/app/views/uploads/_secondary_links.html.erb
+++ b/app/views/uploads/_secondary_links.html.erb
@@ -3,7 +3,7 @@
- <%= link_to "Listing", uploads_path %>
- <%= link_to "New", new_upload_path %>
- <%= link_to "Batch Upload", batch_uploads_path %>
- - <%= link_to "IQDB", check_iqdb_queries_path %>
+ - <%= link_to "Similar Images Search", iqdb_queries_path %>
- <%= link_to "Help", wiki_pages_path(search: { title: "help:upload" }) %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 2a0664b0b..5e713c386 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -154,9 +154,7 @@ Rails.application.routes.draw do
resource :visit, :controller => "forum_topic_visits"
end
resources :ip_bans
- resource :iqdb_queries, :only => [:create, :show, :check] do
- get :check
- end
+ resource :iqdb_queries, :only => [:show]
resources :janitor_trials do
collection do
get :test
diff --git a/test/functional/iqdb_queries_controller_test.rb b/test/functional/iqdb_queries_controller_test.rb
index 4c488742f..6fc24b7a6 100644
--- a/test/functional/iqdb_queries_controller_test.rb
+++ b/test/functional/iqdb_queries_controller_test.rb
@@ -7,28 +7,12 @@ class IqdbQueriesControllerTest < ActionDispatch::IntegrationTest
as_user do
@posts = FactoryBot.create_list(:post, 2)
end
- mock_iqdb_service!
end
- context "create action" do
- should "render with a post_id" do
- mock_iqdb_matches!(@posts[0], @posts)
- post_auth iqdb_queries_path, @user, params: { post_id: @posts[0].id, format: "js" }
-
- assert_response :success
- end
-
- should "render with an url" do
- mock_iqdb_matches!(@posts[0].source, @posts)
- post_auth iqdb_queries_path, @user, params: { url: @posts[0].source }
-
- assert_response :success
- end
-
- should "render for a json response" do
- mock_iqdb_matches!(@posts[0].source, @posts)
- get_auth iqdb_queries_path, @user, params: { url: @posts[0].source, format: "json" }
-
+ context "show action" do
+ should "render with matches" do
+ json = @posts.map {|x| [x.id, 1]}.to_json
+ get_auth iqdb_queries_path, @user, params: { matches: json }
assert_response :success
end
end