FIX: should be able to serve optimized image from local if its ... local...
This commit is contained in:
parent
90eaad336d
commit
eeda367e70
|
@ -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
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue