This commit is contained in:
r888888888
2017-11-17 16:18:59 -08:00
parent e8ff733b3c
commit 9a3824a87e
3 changed files with 13 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
class SourcesController < ApplicationController class SourcesController < ApplicationController
respond_to :json, :xml respond_to :json, :xml
rescue_from Sources::Site::NoStrategyError, :with => :no_strategy
def show def show
@source = Sources::Site.new(params[:url], :referer_url => params[:ref]) @source = Sources::Site.new(params[:url], :referer_url => params[:ref])
@@ -9,4 +10,10 @@ class SourcesController < ApplicationController
format.xml { render xml: @source.to_h.to_xml(root: "source") } format.xml { render xml: @source.to_h.to_xml(root: "source") }
end end
end end
protected
def no_strategy
render json: {message: "Unsupported site"}.to_json, status: 400
end
end end

View File

@@ -1,6 +1,8 @@
class ImageProxy class ImageProxy
def self.needs_proxy?(url) def self.needs_proxy?(url)
fake_referer_for(url).present? fake_referer_for(url).present?
rescue Sources::Site::NoStrategyError
false
end end
def self.fake_referer_for(url) def self.fake_referer_for(url)

View File

@@ -2,6 +2,8 @@
module Sources module Sources
class Site class Site
class NoStrategyError < RuntimeError ; end
attr_reader :url, :strategy attr_reader :url, :strategy
delegate :get, :get_size, :site_name, :artist_name, delegate :get, :get_size, :site_name, :artist_name,
:profile_url, :image_url, :tags, :artists, :unique_id, :profile_url, :image_url, :tags, :artists, :unique_id,
@@ -22,6 +24,8 @@ module Sources
@strategy = strategy.new(url, referer_url) @strategy = strategy.new(url, referer_url)
break break
end end
raise NoStrategyError.new
end end
end end