From 07c0695ac1a76d4953bd6d3ffd3655e36ca00378 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 6 Sep 2018 14:45:42 -0500 Subject: [PATCH 1/3] uploads: remove "this post was probably already uploaded" dupe check. Also makes it so that using the bookmarklet always triggers async upload preprocessing. Before it was only triggered when the source passed a dupe check, but that check was inaccurate (#3873). --- app/controllers/uploads_controller.rb | 4 ++-- app/logical/upload_service/controller_helper.rb | 14 ++++---------- app/views/sources/_info.html.erb | 2 -- app/views/uploads/_post.html.erb | 6 ------ app/views/uploads/new.html.erb | 3 +-- 5 files changed, 7 insertions(+), 22 deletions(-) delete mode 100644 app/views/uploads/_post.html.erb diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index a4df65274..f5ce14ca2 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -5,7 +5,7 @@ class UploadsController < ApplicationController def new @upload_notice_wiki = WikiPage.titled(Danbooru.config.upload_notice_wiki_page).first - @upload, @post, @source, @remote_size = UploadService::ControllerHelper.prepare( + @upload, @remote_size = UploadService::ControllerHelper.prepare( url: params[:url], ref: params[:ref] ) respond_with(@upload) @@ -43,7 +43,7 @@ class UploadsController < ApplicationController end def preprocess - @upload, @post, @source, @remote_size = UploadService::ControllerHelper.prepare( + @upload, @remote_size = UploadService::ControllerHelper.prepare( url: upload_params[:source], file: upload_params[:file], ref: upload_params[:referer_url] ) render body: nil diff --git a/app/logical/upload_service/controller_helper.rb b/app/logical/upload_service/controller_helper.rb index d401be88b..ed69803c7 100644 --- a/app/logical/upload_service/controller_helper.rb +++ b/app/logical/upload_service/controller_helper.rb @@ -4,14 +4,8 @@ class UploadService upload = Upload.new if Utils.is_downloadable?(url) && file.nil? - strategy = Sources::Strategies.find(url, ref) - post = Post.where("SourcePattern(lower(posts.source)) IN (?)", [url, strategy.canonical_url]).first - - if post.nil? - # this gets called from UploadsController#new so we need - # to preprocess async - Preprocessor.new(source: url, referer_url: ref).delay(priority: -1, queue: "default").delayed_start(CurrentUser.id) - end + # this gets called from UploadsController#new so we need to preprocess async + Preprocessor.new(source: url, referer_url: ref).delay(priority: -1, queue: "default").delayed_start(CurrentUser.id) begin download = Downloads::File.new(url, ref) @@ -19,7 +13,7 @@ class UploadService rescue Exception end - return [upload, post, strategy, remote_size] + return [upload, remote_size] end if file @@ -36,4 +30,4 @@ class UploadService end end end -end \ No newline at end of file +end diff --git a/app/views/sources/_info.html.erb b/app/views/sources/_info.html.erb index 69780a02f..8dfb9ed0f 100644 --- a/app/views/sources/_info.html.erb +++ b/app/views/sources/_info.html.erb @@ -1,5 +1,3 @@ -<%# source %> -

<%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %>

<%= content_tag "span", "Loading source data...", :id => "loading-data", :style => "display: none;" %>

diff --git a/app/views/uploads/_post.html.erb b/app/views/uploads/_post.html.erb deleted file mode 100644 index d2b5a4258..000000000 --- a/app/views/uploads/_post.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -<%# post %> -<% if post %> -

- This post was probably already uploaded (<%= link_to "post ##{post.id}", post_path(post), :target => "_blank" %>) -

-<% end %> diff --git a/app/views/uploads/new.html.erb b/app/views/uploads/new.html.erb index 394a9cb79..ebc3758a2 100644 --- a/app/views/uploads/new.html.erb +++ b/app/views/uploads/new.html.erb @@ -12,8 +12,7 @@ <% end %> <%= render "image" %> - <%= render "post", :post => @post %> - <%= render "sources/info", :source => @source %> + <%= render "sources/info" %> From 950fcdb7b2c15f09b6f3795b4aa1c7c4867a8180 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 6 Sep 2018 20:12:56 -0500 Subject: [PATCH 2/3] uploads: add new source: dupe check (fix #3873) * On the /uploads/new page, instead of just showing a "This post has probably already been uploaded" message, show the actual thumbnails of posts having the same source as what the user is trying to upload. * Move the iqdb results section up top, beside the related posts section. --- app/controllers/uploads_controller.rb | 3 ++- .../src/styles/specific/uploads.scss | 11 +++++++- app/logical/sources/strategies/base.rb | 12 +++++++++ app/logical/sources/strategies/pixiv.rb | 4 +++ .../upload_service/controller_helper.rb | 6 ----- app/views/iqdb_queries/_matches.html.erb | 8 +++--- app/views/uploads/_image.html.erb | 2 +- app/views/uploads/_related_posts.html.erb | 27 +++++++++++++++++++ app/views/uploads/new.html.erb | 11 +------- 9 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 app/views/uploads/_related_posts.html.erb diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index f5ce14ca2..5af7fa47e 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -4,6 +4,7 @@ class UploadsController < ApplicationController skip_before_action :verify_authenticity_token, only: [:preprocess] def new + @source = Sources::Strategies.find(params[:url], params[:ref]) if params[:url].present? @upload_notice_wiki = WikiPage.titled(Danbooru.config.upload_notice_wiki_page).first @upload, @remote_size = UploadService::ControllerHelper.prepare( url: params[:url], ref: params[:ref] @@ -13,7 +14,7 @@ class UploadsController < ApplicationController def batch @url = params.dig(:batch, :url) || params[:url] - @source = UploadService::ControllerHelper.batch(@url, params[:ref]) + @source = Sources::Strategies.find(@url, params[:ref]) if @url.present? respond_with(@source) end diff --git a/app/javascript/src/styles/specific/uploads.scss b/app/javascript/src/styles/specific/uploads.scss index 49b71d0b1..c352b787f 100644 --- a/app/javascript/src/styles/specific/uploads.scss +++ b/app/javascript/src/styles/specific/uploads.scss @@ -9,10 +9,19 @@ div#c-uploads { margin-bottom: 2em; } - ul#links { + ul#upload-image-metadata, ul#links { margin-bottom: 1em; } + div#related-posts-by-source, div#iqdb-similar { + display: inline-block; + + .hint { + white-space: nowrap; + max-width: 100%; + } + } + label[for="upload_as_pending"] { display: inline; } diff --git a/app/logical/sources/strategies/base.rb b/app/logical/sources/strategies/base.rb index 36be7d6ae..311eff13e 100644 --- a/app/logical/sources/strategies/base.rb +++ b/app/logical/sources/strategies/base.rb @@ -179,6 +179,18 @@ module Sources return {} end + # A search query that should return any posts that were previously + # uploaded from the same source. These may be duplicates, or they may be + # other posts from the same gallery. + def related_posts_search_query + "source:#{canonical_url}" + end + + def related_posts(limit = 5) + CurrentUser.as_system { Post.tag_match(related_posts_search_query).paginate(1, limit: limit) } + end + memoize :related_posts + def to_h return { :artist_name => artist_name, diff --git a/app/logical/sources/strategies/pixiv.rb b/app/logical/sources/strategies/pixiv.rb index d2268e4b6..94fa34274 100644 --- a/app/logical/sources/strategies/pixiv.rb +++ b/app/logical/sources/strategies/pixiv.rb @@ -153,6 +153,10 @@ module Sources translated_tags end + def related_posts_search_query + illust_id.present? ? "pixiv:#{illust_id}" : "source:#{canonical_url}" + end + public def image_urls_sub diff --git a/app/logical/upload_service/controller_helper.rb b/app/logical/upload_service/controller_helper.rb index ed69803c7..395d91684 100644 --- a/app/logical/upload_service/controller_helper.rb +++ b/app/logical/upload_service/controller_helper.rb @@ -23,11 +23,5 @@ class UploadService return [upload] end - - def self.batch(url, ref = nil) - if url - return Sources::Strategies.find(url, ref) - end - end end end diff --git a/app/views/iqdb_queries/_matches.html.erb b/app/views/iqdb_queries/_matches.html.erb index 2b6e5a413..7b13e4f33 100644 --- a/app/views/iqdb_queries/_matches.html.erb +++ b/app/views/iqdb_queries/_matches.html.erb @@ -1,9 +1,11 @@ <% if @matches.present? %> -

Similar

+

Similar Posts

+

Found <%= pluralize(@matches.length, "similar post") %>:

+ <% @matches.each do |match| %> <%= PostPresenter.preview(match["post"], :tags => "status:any", :similarity => match["score"], :size => true) %> <% end %> <% else %> -

Similar

-

No matches found

+

Similar Posts

+

No similar posts found.

<% end %> diff --git a/app/views/uploads/_image.html.erb b/app/views/uploads/_image.html.erb index e63f6bbc3..8d82b5ec0 100644 --- a/app/views/uploads/_image.html.erb +++ b/app/views/uploads/_image.html.erb @@ -5,7 +5,7 @@ <%= image_tag(@source.image_url, :title => "Preview", :id => "image") %> <% end %> -
    +
      <% if @remote_size %>
    • Size: <%= number_to_human_size(@remote_size) %>
    • <% end %> diff --git a/app/views/uploads/_related_posts.html.erb b/app/views/uploads/_related_posts.html.erb new file mode 100644 index 000000000..9af989261 --- /dev/null +++ b/app/views/uploads/_related_posts.html.erb @@ -0,0 +1,27 @@ +<%# source %> + +<% if source.present? && source.related_posts.present? %> + +<% end %> + +<% if Danbooru.config.iqdbs_server %> + <% if params[:url] %> +
      +

      Loading similar...

      +
      + <% else %> + + <% end %> +<% end %> diff --git a/app/views/uploads/new.html.erb b/app/views/uploads/new.html.erb index ebc3758a2..077cc9cda 100644 --- a/app/views/uploads/new.html.erb +++ b/app/views/uploads/new.html.erb @@ -12,6 +12,7 @@ <% end %> <%= render "image" %> + <%= render "related_posts", source: @source %> <%= render "sources/info" %> @@ -90,16 +91,6 @@
- <% if Danbooru.config.iqdbs_server %> - <% if params[:url] %> -
-

Loading similar...

-
- <% else %> - - <% end %> - <% end %> -
<%= f.label :tag_string, "Tags" %> From 22c27f8910e26e34b7855bcdd470e6c4154747db Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 6 Sep 2018 20:04:48 -0500 Subject: [PATCH 3/3] post previews: fix css for captioned post previews. Captioned post previews (previews with the pool name, similarity, or size beneath) need to have `height: auto` set, otherwise they'll default to `height: 154px` (just enough for the image) and the caption won't be visible. --- app/javascript/src/styles/specific/posts.scss | 19 ++++--------------- app/presenters/post_presenter.rb | 6 +++--- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/app/javascript/src/styles/specific/posts.scss b/app/javascript/src/styles/specific/posts.scss index 19ded8736..e82b222ba 100644 --- a/app/javascript/src/styles/specific/posts.scss +++ b/app/javascript/src/styles/specific/posts.scss @@ -13,12 +13,14 @@ article.post-preview { @include inline-block; } - &.pooled { - height: 214px; + &.captioned { + height: auto; + vertical-align: text-top; } .desc { font-size: 80%; + margin-bottom: 0; } img { @@ -34,19 +36,6 @@ article.post-preview { } } -#iqdb-similar { - overflow: hidden; - - .post-preview { - height: auto; - margin-bottom: 0; - } - - p { - margin-bottom: 0; - } -} - #saved-searches-nav { margin-top: 1em; } diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 7961829ce..9bfb8b8b8 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -27,7 +27,7 @@ class PostPresenter < Presenter cropped_src = post.preview_file_url end - html = %{
} + html = %{
} if options[:tags].present? && !CurrentUser.is_anonymous? tag_param = "?tags=#{CGI::escape(options[:tags])}" elsif options[:pool_id] || options[:pool] @@ -72,10 +72,10 @@ class PostPresenter < Presenter html.html_safe end - def self.preview_class(post, description = nil, options = {}) + def self.preview_class(post, options = {}) klass = "post-preview" # klass << " large-cropped" if post.has_cropped? && options[:show_cropped] - klass << " pooled" if description + klass << " captioned" if options.values_at(:pooled, :size, :similarity).any?(&:present?) klass << " post-status-pending" if post.is_pending? klass << " post-status-flagged" if post.is_flagged? klass << " post-status-deleted" if post.is_deleted?