From 97d0dca8a4f6c5ceb35f24bc3f772ead66713644 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Tue, 19 Jun 2018 13:27:58 -0700 Subject: [PATCH 1/2] increase timeout of deleting preprocessed images --- app/logical/upload_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/logical/upload_service.rb b/app/logical/upload_service.rb index 58ace4ff5..7a48e5234 100644 --- a/app/logical/upload_service.rb +++ b/app/logical/upload_service.rb @@ -192,7 +192,7 @@ class UploadService # in case this upload never finishes processing, we need to delete the # distributed files in the future Danbooru.config.other_server_hosts.each do |host| - UploadService::Utils.delay(queue: host, run_at: 10.minutes.from_now).delete_file(upload.md5, upload.file_ext, upload.id) + UploadService::Utils.delay(queue: host, run_at: 30.minutes.from_now).delete_file(upload.md5, upload.file_ext, upload.id) end end From 9510dead9f1d02d351fd43b6180d049d8ab0fae5 Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Thu, 14 Jun 2018 17:03:41 -0700 Subject: [PATCH 2/2] refactor iqdb query support --- .../forum_post_votes_controller.scss | 3 - app/assets/stylesheets/specific/dropzone.scss | 41 ++++++++++ .../stylesheets/specific/iqdb_queries.scss | 4 + app/assets/stylesheets/specific/uploads.scss | 42 ---------- app/controllers/iqdb_queries_controller.rb | 25 +----- app/views/iqdb_queries/check.html.erb | 34 -------- app/views/iqdb_queries/show.html.erb | 78 +++++++++++++++++++ app/views/static/site_map.html.erb | 2 +- app/views/uploads/_secondary_links.html.erb | 2 +- config/routes.rb | 4 +- .../iqdb_queries_controller_test.rb | 24 +----- 11 files changed, 134 insertions(+), 125 deletions(-) delete mode 100644 app/assets/stylesheets/forum_post_votes_controller.scss create mode 100644 app/assets/stylesheets/specific/dropzone.scss delete mode 100644 app/views/iqdb_queries/check.html.erb create mode 100644 app/views/iqdb_queries/show.html.erb 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) %>