This commit is contained in:
r888888888
2017-09-14 11:37:42 -07:00
parent 3ffd871e8a
commit d12f082f9a
4 changed files with 26 additions and 4 deletions

View File

@@ -138,7 +138,7 @@
if (Danbooru.RelatedTag.recent_artists[0].is_banned === true) {
tags.push(["BANNED_ARTIST", "banned"]);
}
$.each(Danbooru.RelatedTag.recent_artists[0].urls, function(i, url) {
$.each(Danbooru.RelatedTag.recent_artists[0].sorted_urls, function(i, url) {
tags.push([" " + url.url, 0]);
});
} else if (Danbooru.RelatedTag.recent_artists.length >= 10) {

View File

@@ -102,7 +102,7 @@ class ArtistsController < ApplicationController
def finder
begin
@artists = Artist.url_matches(params[:url]).order("id desc").limit(20)
@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
@@ -112,10 +112,10 @@ class ArtistsController < ApplicationController
respond_with(@artists) do |format|
format.xml do
render :xml => @artists.to_xml(:include => [:urls], :root => "artists")
render :xml => @artists.to_xml(:include => [:sorted_urls], :root => "artists")
end
format.json do
render :json => @artists.to_json(:include => [:urls])
render :json => @artists.to_json(:include => [:sorted_urls])
end
end
end

View File

@@ -60,6 +60,10 @@ class Artist < ApplicationRecord
memoize :domains
end
def sorted_urls
urls.sort {|a, b| a.priority <=> b.priority}
end
def url_array
urls.map(&:url)
end

View File

@@ -53,6 +53,24 @@ class ArtistUrl < ApplicationRecord
url = url.gsub(/^http:\/\/i\d+\.pixiv\.net\/img\d+/, "http://*.pixiv.net/img*")
end
def priority
if normalized_url =~ /pixiv\.net\/member\.php/
10
elsif normalized_url =~ /seiga\.nicovideo\.jp\/user\/illust/
10
elsif normalized_url =~ /twitter\.com/ && normalized_url !~ /status/
10
elsif normalized_url =~ /tumblr|patreon|deviantart|artstation/
20
else
100
end
end
def normalize
if !Sources::Site.new(normalized_url).normalized_for_artist_finder?
self.normalized_url = self.class.normalize(url)