FIX: should be able to serve optimized image from local if its ... local...

This commit is contained in:
Sam 2015-05-26 12:32:52 +10:00
parent 90eaad336d
commit eeda367e70
3 changed files with 20 additions and 1 deletions

View File

@ -67,7 +67,7 @@ class UserAvatarsController < ApplicationController
original = Discourse.store.path_for(upload)
if Discourse.store.external? || File.exists?(original)
if optimized = get_optimized_image(upload, size)
if Discourse.store.external?
unless optimized.local?
expires_in 1.day, public: true
return redirect_to optimized.url
end

View File

@ -83,6 +83,10 @@ class OptimizedImage < ActiveRecord::Base
end
end
def local?
!(url =~ /^(https?:)?\/\//)
end
def self.resize_instructions(from, to, dimensions, opts={})
# NOTE: ORDER is important!
%W{

View File

@ -5,6 +5,21 @@ describe OptimizedImage do
let(:upload) { build(:upload) }
before { upload.id = 42 }
describe ".local?" do
def local(url)
OptimizedImage.new(url: url).local?
end
it "correctly detects local vs remote" do
expect(local("//hello")).to eq(false)
expect(local("http://hello")).to eq(false)
expect(local("https://hello")).to eq(false)
expect(local("https://hello")).to eq(false)
expect(local("/hello")).to eq(true)
end
end
describe ".create_for" do
context "when using an internal store" do