Merge pull request #3373 from evazion/fix-3368
Fix #3368: "Fetch source data" on /uploads/new doesn't fetch artist tag
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
this.initialize_similar();
|
||||
this.initialize_shortcuts();
|
||||
$("#related-tags-button").trigger("click");
|
||||
$("#find-artist-button").trigger("click");
|
||||
|
||||
$("#toggle-artist-commentary").click(function(e) {
|
||||
Danbooru.Upload.toggle_commentary();
|
||||
@@ -59,56 +58,66 @@
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_info_bookmarklet = function() {
|
||||
$("#source-info ul").hide();
|
||||
$("#fetch-data-bookmarklet").click(function(e) {
|
||||
var xhr = $.get(e.target.href);
|
||||
xhr.success(Danbooru.Upload.fill_source_info);
|
||||
xhr.fail(function(data) {
|
||||
$("#source-info span#loading-data").html("Error: " + data.responseJSON["message"])
|
||||
});
|
||||
e.preventDefault();
|
||||
$("#upload_source").change(function (e) {
|
||||
$("#fetch-data-manual").click();
|
||||
});
|
||||
$("#fetch-data-bookmarklet").trigger("click");
|
||||
|
||||
$("#fetch-data-manual").click();
|
||||
}
|
||||
|
||||
Danbooru.Upload.initialize_info_manual = function() {
|
||||
$("#source-info ul").hide();
|
||||
|
||||
$("#fetch-data-manual").click(function(e) {
|
||||
var source = $("#upload_source,#post_source").val();
|
||||
if (!/\S/.test(source)) {
|
||||
Danbooru.error("Error: You must enter a URL into the source field to get its data");
|
||||
} else if (!/^https?:\/\//.test(source)) {
|
||||
Danbooru.error("Error: Source is not a URL");
|
||||
} else {
|
||||
var referer = $("#upload_referer_url").val();
|
||||
|
||||
if (/^https?:\/\//.test(source)) {
|
||||
$("#source-info span#loading-data").show();
|
||||
var xhr = $.get("/source.json?url=" + encodeURIComponent(source));
|
||||
xhr.success(Danbooru.Upload.fill_source_info);
|
||||
xhr.fail(function(data) {
|
||||
$("#source-info span#loading-data").html("Error: " + data.responseJSON["message"])
|
||||
});
|
||||
Danbooru.Upload.fetch_source_data(source, referer);
|
||||
}
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
Danbooru.Upload.fetch_source_data = function(url, referer_url) {
|
||||
var xhr = $.getJSON("/source.json", { url: url, ref: referer_url });
|
||||
|
||||
xhr.success(Danbooru.Upload.fill_source_info);
|
||||
xhr.fail(function(data) {
|
||||
$("#source-info span#loading-data").html("Error: " + data.responseJSON["message"])
|
||||
});
|
||||
|
||||
return xhr;
|
||||
}
|
||||
|
||||
Danbooru.Upload.fill_source_info = function(data) {
|
||||
$("#source-tags").empty();
|
||||
$.each(data.tags, function(i, v) {
|
||||
$("<a>").attr("href", v[1]).text(v[0]).appendTo("#source-tags");
|
||||
});
|
||||
|
||||
$("#source-artist").html($("<a>").attr("href", data.profile_url).text(data.artist_name));
|
||||
$("#source-artist-profile").attr("href", data.profile_url).text(data.artist_name);
|
||||
|
||||
Danbooru.RelatedTag.process_artist(data.artists);
|
||||
Danbooru.RelatedTag.translated_tags = data.translated_tags;
|
||||
Danbooru.RelatedTag.build_all();
|
||||
|
||||
var new_artist_href = "/artists/new?other_names="
|
||||
+ encodeURIComponent(data.artist_name)
|
||||
+ "&urls="
|
||||
+ encodeURIComponent($.unique([data.profile_url, data.normalized_for_artist_finder_url]).join("\n"));
|
||||
if (data.artists.length === 0) {
|
||||
var new_artist_params = $.param({
|
||||
name: data.unique_id,
|
||||
other_names: data.artist_name,
|
||||
urls: $.unique([data.profile_url, data.normalized_for_artist_finder_url]).join("\n")
|
||||
});
|
||||
|
||||
$("#source-record").html($("<a>").attr("href", new_artist_href).text("Create New"));
|
||||
var link = $("<a>").attr("href", "/artists/new?" + new_artist_params).text("Create new artist");
|
||||
$("#source-danbooru-artists").html(link);
|
||||
} else {
|
||||
var artistLinks = data.artists.map(function (artist) {
|
||||
return $('<a class="tag-type-1">').attr("href", "/artists/" + artist.id).text(artist.name);
|
||||
});
|
||||
|
||||
$("#source-danbooru-artists").html(artistLinks)
|
||||
}
|
||||
|
||||
if (data.image_urls.length > 1) {
|
||||
$("#gallery-warning").show();
|
||||
|
||||
@@ -494,22 +494,6 @@ div#c-posts {
|
||||
color: gray;
|
||||
}
|
||||
}
|
||||
|
||||
div#source-info {
|
||||
margin: 1em 0;
|
||||
padding: 1em;
|
||||
border: 1px solid gray;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
ul {
|
||||
a {
|
||||
margin-right: 1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div#quick-edit-div {
|
||||
@@ -529,6 +513,29 @@ div#c-post-versions, div#c-artist-versions {
|
||||
}
|
||||
}
|
||||
|
||||
div#c-posts, div#c-uploads {
|
||||
/* Fetch source data box */
|
||||
div#source-info {
|
||||
margin: 1em 0;
|
||||
padding: 1em;
|
||||
border: 1px solid gray;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
> ul {
|
||||
display: none;
|
||||
|
||||
.source-tags {
|
||||
a {
|
||||
margin-right: 1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div#c-explore-posts {
|
||||
a.desc {
|
||||
font-weight: bold;
|
||||
|
||||
@@ -26,23 +26,6 @@ div#c-uploads {
|
||||
display: block;
|
||||
}
|
||||
|
||||
div#source-info {
|
||||
margin: 1em 0;
|
||||
padding: 1em;
|
||||
border: 1px solid gray;
|
||||
min-height: 5em;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
ul {
|
||||
a {
|
||||
margin-right: 1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div.field_with_errors {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
@@ -101,14 +101,7 @@ class ArtistsController < ApplicationController
|
||||
end
|
||||
|
||||
def finder
|
||||
begin
|
||||
@artists = Artist.url_matches(params[:url]).order("id desc").limit(10)
|
||||
if @artists.empty? && params[:referer_url].present? && params[:referer_url] != params[:url]
|
||||
@artists = Artist.url_matches(params[:referer_url]).order("id desc").limit(20)
|
||||
end
|
||||
rescue PixivApiClient::Error => e
|
||||
@artists = []
|
||||
end
|
||||
@artists = Artist.find_artists(params[:url], params[:referer_url])
|
||||
|
||||
respond_with(@artists) do |format|
|
||||
format.xml do
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
module Sources
|
||||
class Site
|
||||
attr_reader :url, :strategy
|
||||
delegate :get, :get_size, :site_name, :artist_name,
|
||||
:profile_url, :image_url, :tags, :artist_record, :unique_id,
|
||||
delegate :get, :get_size, :site_name, :artist_name,
|
||||
:profile_url, :image_url, :tags, :artists, :unique_id,
|
||||
:file_url, :ugoira_frame_data, :ugoira_content_type, :image_urls,
|
||||
:artist_commentary_title, :artist_commentary_desc,
|
||||
:dtext_artist_commentary_title, :dtext_artist_commentary_desc,
|
||||
@@ -46,14 +46,13 @@ module Sources
|
||||
def to_h
|
||||
return {
|
||||
:artist_name => artist_name,
|
||||
:artists => artists.as_json(include: :sorted_urls),
|
||||
:profile_url => profile_url,
|
||||
:image_url => image_url,
|
||||
:image_urls => image_urls,
|
||||
:normalized_for_artist_finder_url => normalize_for_artist_finder!,
|
||||
:tags => tags,
|
||||
:translated_tags => translated_tags,
|
||||
:danbooru_name => artist_record.try(:first).try(:name),
|
||||
:danbooru_id => artist_record.try(:first).try(:id),
|
||||
:unique_id => unique_id,
|
||||
:artist_commentary => {
|
||||
:title => artist_commentary_title,
|
||||
|
||||
@@ -64,12 +64,8 @@ module Sources
|
||||
artist_name
|
||||
end
|
||||
|
||||
def artist_record
|
||||
if artist_name.present?
|
||||
Artist.other_names_match(artist_name)
|
||||
else
|
||||
nil
|
||||
end
|
||||
def artists
|
||||
Artist.find_artists(url, referer_url)
|
||||
end
|
||||
|
||||
def image_urls
|
||||
|
||||
@@ -357,6 +357,18 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
def find_artists(url, referer_url = nil)
|
||||
artists = url_matches(url).order("id desc").limit(10)
|
||||
|
||||
if artists.empty? && referer_url.present? && referer_url != url
|
||||
artists = url_matches(referer_url).order("id desc").limit(20)
|
||||
end
|
||||
|
||||
artists
|
||||
rescue PixivApiClient::Error => e
|
||||
[]
|
||||
end
|
||||
|
||||
def url_matches(string)
|
||||
matches = find_all_by_url(string).map(&:id)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= render "sources/info_for_post" %>
|
||||
<%= render "sources/info" %>
|
||||
|
||||
<%= form_for(post, :html => {:class => "simple_form", :id => "form"}) do |f| %>
|
||||
<%= hidden_field_tag :tags_query, params[:tags] %>
|
||||
|
||||
@@ -3,19 +3,13 @@
|
||||
-->
|
||||
|
||||
<div id="source-info">
|
||||
<% if source.try(:available?) %>
|
||||
<p><%= link_to "Fetch source data", source_path(:format => "json", :url => source.referer_url), :id => "fetch-data-bookmarklet", :style => "display: none;" %></p>
|
||||
<p><%= content_tag "span", "Loading #{source.site_name} data...", :id => "loading-data" %></p>
|
||||
<% else %>
|
||||
<p><%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %></p>
|
||||
<p><%= content_tag "span", "Loading source data...", :id => "loading-data", :style => "display: none;" %></p>
|
||||
<% end %>
|
||||
<p><%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %></p>
|
||||
<p><%= content_tag "span", "Loading source data...", :id => "loading-data", :style => "display: none;" %></p>
|
||||
<p id="remote-size" style="display: none;"></p>
|
||||
<p id="gallery-warning" style="display: none;"><%= content_tag "span", "Gallery. Tags may not apply to all images." %></p>
|
||||
|
||||
<ul>
|
||||
<li><strong>Artist</strong>: <span id="source-artist"></span></li>
|
||||
<li><strong>Tags</strong>: <span id="source-tags"></span></li>
|
||||
<li><strong>Record</strong>: <span id="source-record"></span></li>
|
||||
<li><strong>Artist</strong>: <a id="source-artist-profile"></a> (<span id="source-danbooru-artists"></span>)</li>
|
||||
<li class="source-tags"><strong>Tags</strong>: <span id="source-tags"></span></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<!--
|
||||
- source
|
||||
-->
|
||||
|
||||
<div id="source-info">
|
||||
<p><%= link_to "Fetch source data", source_path(:format => "json"), :id => "fetch-data-manual" %></p>
|
||||
<p><%= content_tag "span", "Loading source data...", :id => "loading-data", :style => "display: none;" %></p>
|
||||
<p><%= content_tag "span", "Gallery. Tags may not apply to all images.", :id => "gallery-warning", :style => "display: none;" %></p>
|
||||
|
||||
<ul>
|
||||
<li><strong>Artist</strong>: <span id="source-artist"></span></li>
|
||||
<li><strong>Tags</strong>: <span id="source-tags"></span></li>
|
||||
<li><strong>Record</strong>: <span id="source-record"></span></li>
|
||||
</ul>
|
||||
</div>
|
||||
Reference in New Issue
Block a user