Don't redirect to api if we want something from images dir

This commit is contained in:
Piotr Sarnacki 2013-10-31 16:07:19 +01:00
parent 06d90dbc9b
commit 88c5bae9fc

View File

@ -4,7 +4,21 @@ class Travis::Web::ApiRedirect < Sinatra::Base
disable :protection, :static
set api_endpoint: 'https://api.travis-ci.org'
get '/:owner_name/:name.png' do
class NotPublicImages
Match = Struct.new(:captures)
def initialize(pattern, except)
@except = except
@pattern = pattern
@captures = Match.new([])
end
def match(str)
@captures if str =~ @pattern && str !~ @except
end
end
get NotPublicImages.new(%r{^/(\w+)/(\w+).png}, %r{^/images/}) do
redirect!
end
@ -14,6 +28,10 @@ class Travis::Web::ApiRedirect < Sinatra::Base
private
def public_image?
params[:owner_name] == 'images'
end
def redirect!(path = nil)
path = File.join(settings.api_endpoint, path || request.fullpath)
redirect(path, 301)