From 9a3824a87ed105797994768666405aeaba107582 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Fri, 17 Nov 2017 16:18:59 -0800 Subject: [PATCH] fixes #3382 --- app/controllers/sources_controller.rb | 7 +++++++ app/logical/image_proxy.rb | 2 ++ app/logical/sources/site.rb | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/app/controllers/sources_controller.rb b/app/controllers/sources_controller.rb index 6b86f08fa..1f67a2d77 100644 --- a/app/controllers/sources_controller.rb +++ b/app/controllers/sources_controller.rb @@ -1,5 +1,6 @@ class SourcesController < ApplicationController respond_to :json, :xml + rescue_from Sources::Site::NoStrategyError, :with => :no_strategy def show @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") } end end + +protected + + def no_strategy + render json: {message: "Unsupported site"}.to_json, status: 400 + end end diff --git a/app/logical/image_proxy.rb b/app/logical/image_proxy.rb index 6a93969aa..5b05627d2 100644 --- a/app/logical/image_proxy.rb +++ b/app/logical/image_proxy.rb @@ -1,6 +1,8 @@ class ImageProxy def self.needs_proxy?(url) fake_referer_for(url).present? + rescue Sources::Site::NoStrategyError + false end def self.fake_referer_for(url) diff --git a/app/logical/sources/site.rb b/app/logical/sources/site.rb index 2c5f75b9e..a2dc0a47f 100644 --- a/app/logical/sources/site.rb +++ b/app/logical/sources/site.rb @@ -2,6 +2,8 @@ module Sources class Site + class NoStrategyError < RuntimeError ; end + attr_reader :url, :strategy delegate :get, :get_size, :site_name, :artist_name, :profile_url, :image_url, :tags, :artists, :unique_id, @@ -22,6 +24,8 @@ module Sources @strategy = strategy.new(url, referer_url) break end + + raise NoStrategyError.new end end