mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FIX: should be able to serve optimized image from local if its ... local...
This commit is contained in:
parent
90eaad336d
commit
eeda367e70
3 changed files with 20 additions and 1 deletions
|
@ -67,7 +67,7 @@ class UserAvatarsController < ApplicationController
|
||||||
original = Discourse.store.path_for(upload)
|
original = Discourse.store.path_for(upload)
|
||||||
if Discourse.store.external? || File.exists?(original)
|
if Discourse.store.external? || File.exists?(original)
|
||||||
if optimized = get_optimized_image(upload, size)
|
if optimized = get_optimized_image(upload, size)
|
||||||
if Discourse.store.external?
|
unless optimized.local?
|
||||||
expires_in 1.day, public: true
|
expires_in 1.day, public: true
|
||||||
return redirect_to optimized.url
|
return redirect_to optimized.url
|
||||||
end
|
end
|
||||||
|
|
|
@ -83,6 +83,10 @@ class OptimizedImage < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def local?
|
||||||
|
!(url =~ /^(https?:)?\/\//)
|
||||||
|
end
|
||||||
|
|
||||||
def self.resize_instructions(from, to, dimensions, opts={})
|
def self.resize_instructions(from, to, dimensions, opts={})
|
||||||
# NOTE: ORDER is important!
|
# NOTE: ORDER is important!
|
||||||
%W{
|
%W{
|
||||||
|
|
|
@ -5,6 +5,21 @@ describe OptimizedImage do
|
||||||
let(:upload) { build(:upload) }
|
let(:upload) { build(:upload) }
|
||||||
before { upload.id = 42 }
|
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
|
describe ".create_for" do
|
||||||
|
|
||||||
context "when using an internal store" do
|
context "when using an internal store" do
|
||||||
|
|
Loading…
Reference in a new issue