From 950fcdb7b2c15f09b6f3795b4aa1c7c4867a8180 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 6 Sep 2018 20:12:56 -0500 Subject: [PATCH] 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 %> -