#1866: Normalize urls in artist finder

This commit is contained in:
Toks
2013-12-25 12:43:54 -05:00
parent 8055a7c64b
commit 3a9a6c6658
4 changed files with 23 additions and 2 deletions

View File

@@ -247,7 +247,7 @@
Danbooru.RelatedTag.find_artist = function(e) {
$("#artist-tags").html("<em>Loading...</em>");
var url = $("#upload_source,#post_source");
$.get("/artists.json", {"limit": 20, "search[name]": url.val()}).success(Danbooru.RelatedTag.process_artist);
$.get("/artists/finder.json", {"url": url.val()}).success(Danbooru.RelatedTag.process_artist);
e.preventDefault();
}

View File

@@ -110,4 +110,24 @@ class ArtistsController < ApplicationController
redirect_to new_artist_path(:name => params[:name])
end
end
def finder
url = params[:url]
headers = {
"User-Agent" => "#{Danbooru.config.safe_app_name}/#{Danbooru.config.version}"
}
Downloads::Strategies::Base.strategies.each do |strategy|
url, headers = strategy.new.rewrite(url, headers)
end
@artists = Artist.url_matches(url).order("id desc").limit(20)
respond_with(@artists) do |format|
format.xml do
render :xml => @artists.to_xml(:include => [:urls], :root => "artists")
end
format.json do
render :json => @artists.to_json(:include => [:urls])
end
end
end
end

View File

@@ -16,7 +16,7 @@
<%= error_messages_for "upload" %>
<%= form_for(@upload, :html => {:multipart => true, :class => "simple_form", :id => 'form'}) do |f| %>
<%= form_for(@upload, :html => {:multipart => true, :class => "simple_form", :id => "form"}) do |f| %>
<% if CurrentUser.is_contributor? %>
<div class="input">
<label for="upload_as_pending">

View File

@@ -68,6 +68,7 @@ Danbooru::Application.routes.draw do
collection do
get :show_or_new
get :banned
get :finder
end
end
resources :artist_versions, :only => [:index] do