uploads: add new source:<url> 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.
This commit is contained in:
@@ -4,6 +4,7 @@ class UploadsController < ApplicationController
|
|||||||
skip_before_action :verify_authenticity_token, only: [:preprocess]
|
skip_before_action :verify_authenticity_token, only: [:preprocess]
|
||||||
|
|
||||||
def new
|
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_notice_wiki = WikiPage.titled(Danbooru.config.upload_notice_wiki_page).first
|
||||||
@upload, @remote_size = UploadService::ControllerHelper.prepare(
|
@upload, @remote_size = UploadService::ControllerHelper.prepare(
|
||||||
url: params[:url], ref: params[:ref]
|
url: params[:url], ref: params[:ref]
|
||||||
@@ -13,7 +14,7 @@ class UploadsController < ApplicationController
|
|||||||
|
|
||||||
def batch
|
def batch
|
||||||
@url = params.dig(:batch, :url) || params[:url]
|
@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)
|
respond_with(@source)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,19 @@ div#c-uploads {
|
|||||||
margin-bottom: 2em;
|
margin-bottom: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul#links {
|
ul#upload-image-metadata, ul#links {
|
||||||
margin-bottom: 1em;
|
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"] {
|
label[for="upload_as_pending"] {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,6 +179,18 @@ module Sources
|
|||||||
return {}
|
return {}
|
||||||
end
|
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
|
def to_h
|
||||||
return {
|
return {
|
||||||
:artist_name => artist_name,
|
:artist_name => artist_name,
|
||||||
|
|||||||
@@ -153,6 +153,10 @@ module Sources
|
|||||||
translated_tags
|
translated_tags
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def related_posts_search_query
|
||||||
|
illust_id.present? ? "pixiv:#{illust_id}" : "source:#{canonical_url}"
|
||||||
|
end
|
||||||
|
|
||||||
public
|
public
|
||||||
|
|
||||||
def image_urls_sub
|
def image_urls_sub
|
||||||
|
|||||||
@@ -23,11 +23,5 @@ class UploadService
|
|||||||
|
|
||||||
return [upload]
|
return [upload]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.batch(url, ref = nil)
|
|
||||||
if url
|
|
||||||
return Sources::Strategies.find(url, ref)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<% if @matches.present? %>
|
<% if @matches.present? %>
|
||||||
<h3>Similar</h3>
|
<h3>Similar Posts</h3>
|
||||||
|
<p class="hint">Found <%= pluralize(@matches.length, "similar post") %>:</p>
|
||||||
|
|
||||||
<% @matches.each do |match| %>
|
<% @matches.each do |match| %>
|
||||||
<%= PostPresenter.preview(match["post"], :tags => "status:any", :similarity => match["score"], :size => true) %>
|
<%= PostPresenter.preview(match["post"], :tags => "status:any", :similarity => match["score"], :size => true) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<h3>Similar</h3>
|
<h3>Similar Posts</h3>
|
||||||
<p>No matches found</p>
|
<p class="hint">No similar posts found.</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<%= image_tag(@source.image_url, :title => "Preview", :id => "image") %>
|
<%= image_tag(@source.image_url, :title => "Preview", :id => "image") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<ul>
|
<ul id="upload-image-metadata">
|
||||||
<% if @remote_size %>
|
<% if @remote_size %>
|
||||||
<li><strong>Size:</strong> <%= number_to_human_size(@remote_size) %></li>
|
<li><strong>Size:</strong> <%= number_to_human_size(@remote_size) %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
27
app/views/uploads/_related_posts.html.erb
Normal file
27
app/views/uploads/_related_posts.html.erb
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<%# source %>
|
||||||
|
|
||||||
|
<% if source.present? && source.related_posts.present? %>
|
||||||
|
<div id="related-posts-by-source">
|
||||||
|
<h3>Related Posts</h3>
|
||||||
|
|
||||||
|
<p class="hint">
|
||||||
|
Found <%= link_to pluralize(source.related_posts.total_count, "other post"), posts_path(tags: source.related_posts_search_query) %> from the same source:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<% source.related_posts.each do |post| %>
|
||||||
|
<%= PostPresenter.preview(post, show_deleted: true, size: true) %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<% if Danbooru.config.iqdbs_server %>
|
||||||
|
<% if params[:url] %>
|
||||||
|
<div class="input" id="iqdb-similar">
|
||||||
|
<p><em>Loading similar...</em></p>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<div class="input" id="iqdb-similar" style="display: none;"></div>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render "image" %>
|
<%= render "image" %>
|
||||||
|
<%= render "related_posts", source: @source %>
|
||||||
<%= render "sources/info" %>
|
<%= render "sources/info" %>
|
||||||
|
|
||||||
<div id="client-errors" class="error-messages ui-state-error ui-corner-all" style="display:none"></div>
|
<div id="client-errors" class="error-messages ui-state-error ui-corner-all" style="display:none"></div>
|
||||||
@@ -90,16 +91,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% if Danbooru.config.iqdbs_server %>
|
|
||||||
<% if params[:url] %>
|
|
||||||
<div class="input" id="iqdb-similar">
|
|
||||||
<p><em>Loading similar...</em></p>
|
|
||||||
</div>
|
|
||||||
<% else %>
|
|
||||||
<div class="input" id="iqdb-similar" style="display: none;"></div>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div class="input">
|
<div class="input">
|
||||||
<div>
|
<div>
|
||||||
<%= f.label :tag_string, "Tags" %>
|
<%= f.label :tag_string, "Tags" %>
|
||||||
|
|||||||
Reference in New Issue
Block a user