mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 19:53:53 -06:00
Merge pull request #1222 from ZogStriP/fix-s3-related-issues
Fix s3 related issues
This commit is contained in:
commit
ed745c3fdd
@ -99,7 +99,7 @@ class Upload < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.is_on_s3?(url)
|
def self.is_on_s3?(url)
|
||||||
SiteSetting.enable_s3_uploads? && (url.start_with?(S3Store.base_url) || url.start_with?(S3Store.base_url_old))
|
SiteSetting.enable_s3_uploads? && url.start_with?(S3Store.base_url)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_from_url(url)
|
def self.get_from_url(url)
|
||||||
|
@ -586,7 +586,7 @@ en:
|
|||||||
suggested_topics: "The number of suggested topics shown at the bottom of a topic"
|
suggested_topics: "The number of suggested topics shown at the bottom of a topic"
|
||||||
|
|
||||||
enable_s3_uploads: "Place uploads on Amazon S3"
|
enable_s3_uploads: "Place uploads on Amazon S3"
|
||||||
s3_upload_bucket: "The Amazon S3 bucket name that files will be uploaded into"
|
s3_upload_bucket: "The Amazon S3 bucket name that files will be uploaded into. WARNING: must be lowercase (cf. http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html)"
|
||||||
s3_access_key_id: "The Amazon S3 access key id that will be used to upload images"
|
s3_access_key_id: "The Amazon S3 access key id that will be used to upload images"
|
||||||
s3_secret_access_key: "The Amazon S3 secret access key that will be used to upload images"
|
s3_secret_access_key: "The Amazon S3 secret access key that will be used to upload images"
|
||||||
s3_region: "The Amazon S3 region name that will be used to upload images"
|
s3_region: "The Amazon S3 region name that will be used to upload images"
|
||||||
|
@ -556,7 +556,7 @@ fr:
|
|||||||
suggested_topics: "Nombre de discussions suggerées en dessous d'une discussion"
|
suggested_topics: "Nombre de discussions suggerées en dessous d'une discussion"
|
||||||
|
|
||||||
enable_s3_uploads: "S'il faut ou non uploader sur s3"
|
enable_s3_uploads: "S'il faut ou non uploader sur s3"
|
||||||
s3_upload_bucket: "Le bucket dans lequel uploader sur s3"
|
s3_upload_bucket: "Le nom du bucket s3 où seront uploader les fichiers. ATTENTION : le nom doit être en minuscule (cf. http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html)"
|
||||||
s3_secret_access_key: "La clé secrète Amazon S3 qui va être utilisée pour uploader des images"
|
s3_secret_access_key: "La clé secrète Amazon S3 qui va être utilisée pour uploader des images"
|
||||||
s3_region: "Le nom de la région Amazon S3 qui va être utilisée pour uploader des images"
|
s3_region: "Le nom de la région Amazon S3 qui va être utilisée pour uploader des images"
|
||||||
|
|
||||||
|
@ -13,10 +13,6 @@ module S3Store
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.base_url
|
def self.base_url
|
||||||
"//s3.amazonaws.com/#{SiteSetting.s3_upload_bucket}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.base_url_old
|
|
||||||
"//#{SiteSetting.s3_upload_bucket.downcase}.s3.amazonaws.com"
|
"//#{SiteSetting.s3_upload_bucket.downcase}.s3.amazonaws.com"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,8 +24,7 @@ describe S3Store do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the url of the S3 upload if successful' do
|
it 'returns the url of the S3 upload if successful' do
|
||||||
# NOTE: s3 bucket's name are case sensitive so we can't use it as a subdomain...
|
S3Store.store_file(file, "SHA", 1).should == '//s3_upload_bucket.s3.amazonaws.com/1SHA.png'
|
||||||
S3Store.store_file(file, "SHA", 1).should == '//s3.amazonaws.com/S3_Upload_Bucket/1SHA.png'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
after(:each) do
|
after(:each) do
|
||||||
|
@ -164,7 +164,7 @@ describe Upload do
|
|||||||
it "identifies S3 uploads" do
|
it "identifies S3 uploads" do
|
||||||
SiteSetting.stubs(:enable_s3_uploads).returns(true)
|
SiteSetting.stubs(:enable_s3_uploads).returns(true)
|
||||||
SiteSetting.stubs(:s3_upload_bucket).returns("Bucket")
|
SiteSetting.stubs(:s3_upload_bucket).returns("Bucket")
|
||||||
Upload.has_been_uploaded?("//s3.amazonaws.com/Bucket/1337.png").should == true
|
Upload.has_been_uploaded?("//bucket.s3.amazonaws.com/1337.png").should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "identifies external urls" do
|
it "identifies external urls" do
|
||||||
@ -174,24 +174,6 @@ describe Upload do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context ".is_on_s3?" do
|
|
||||||
|
|
||||||
before do
|
|
||||||
SiteSetting.stubs(:enable_s3_uploads).returns(true)
|
|
||||||
SiteSetting.stubs(:s3_upload_bucket).returns("BuCkEt")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "case-insensitively matches the old subdomain format" do
|
|
||||||
Upload.is_on_s3?("//bucket.s3.amazonaws.com/1337.png").should == true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "case-sensitively matches the new folder format" do
|
|
||||||
Upload.is_on_s3?("//s3.amazonaws.com/BuCkEt/1337.png").should == true
|
|
||||||
Upload.is_on_s3?("//s3.amazonaws.com/bucket/1337.png").should == false
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
context ".get_from_url" do
|
context ".get_from_url" do
|
||||||
|
|
||||||
it "works when the file has been uploaded" do
|
it "works when the file has been uploaded" do
|
||||||
|
Loading…
Reference in New Issue
Block a user