renamed s3 to s3_store
This commit is contained in:
parent
f40cad0f4b
commit
7ae2fe304d
|
@ -2,7 +2,7 @@ require 'digest/sha1'
|
|||
require 'image_sizer'
|
||||
require 'tempfile'
|
||||
require 'pathname'
|
||||
require_dependency 's3'
|
||||
require_dependency 's3_store'
|
||||
require_dependency 'local_store'
|
||||
|
||||
class Upload < ActiveRecord::Base
|
||||
|
@ -77,12 +77,12 @@ class Upload < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.store_file(file, sha1, upload_id)
|
||||
return S3.store_file(file, sha1, upload_id) if SiteSetting.enable_s3_uploads?
|
||||
return S3Store.store_file(file, sha1, upload_id) if SiteSetting.enable_s3_uploads?
|
||||
return LocalStore.store_file(file, sha1, upload_id)
|
||||
end
|
||||
|
||||
def self.remove_file(url)
|
||||
return S3.remove_file(url) if SiteSetting.enable_s3_uploads?
|
||||
return S3Store.remove_file(url) if SiteSetting.enable_s3_uploads?
|
||||
return LocalStore.remove_file(url)
|
||||
end
|
||||
|
||||
|
@ -99,7 +99,7 @@ class Upload < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.is_on_s3?(url)
|
||||
SiteSetting.enable_s3_uploads? && url.start_with?(S3.base_url)
|
||||
SiteSetting.enable_s3_uploads? && url.start_with?(S3Store.base_url)
|
||||
end
|
||||
|
||||
def self.get_from_url(url)
|
||||
|
|
|
@ -223,7 +223,7 @@ class CookedPostProcessor
|
|||
|
||||
def attachments
|
||||
if SiteSetting.enable_s3_uploads?
|
||||
@doc.css("a[href^=\"#{S3.base_url}\"]")
|
||||
@doc.css("a[href^=\"#{S3Store.base_url}\"]")
|
||||
else
|
||||
# local uploads are identified using a relative uri
|
||||
@doc.css("a[href^=\"#{LocalStore.directory}\"]")
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
module S3
|
||||
module S3Store
|
||||
|
||||
def self.store_file(file, sha1, upload_id)
|
||||
S3.check_missing_site_settings
|
||||
S3Store.check_missing_site_settings
|
||||
|
||||
directory = S3.get_or_create_directory(SiteSetting.s3_upload_bucket)
|
||||
directory = S3Store.get_or_create_directory(SiteSetting.s3_upload_bucket)
|
||||
extension = File.extname(file.original_filename)
|
||||
remote_filename = "#{upload_id}#{sha1}#{extension}"
|
||||
|
||||
# if this fails, it will throw an exception
|
||||
file = S3.upload(file, remote_filename, directory)
|
||||
"#{S3.base_url}/#{remote_filename}"
|
||||
file = S3Store.upload(file, remote_filename, directory)
|
||||
"#{S3Store.base_url}/#{remote_filename}"
|
||||
end
|
||||
|
||||
def self.base_url
|
||||
|
@ -17,11 +17,11 @@ module S3
|
|||
end
|
||||
|
||||
def self.remove_file(url)
|
||||
S3.check_missing_site_settings
|
||||
S3Store.check_missing_site_settings
|
||||
|
||||
directory = S3.get_or_create_directory(SiteSetting.s3_upload_bucket)
|
||||
directory = S3Store.get_or_create_directory(SiteSetting.s3_upload_bucket)
|
||||
|
||||
file = S3.destroy(url, directory)
|
||||
file = S3Store.destroy(url, directory)
|
||||
end
|
||||
|
||||
def self.check_missing_site_settings
|
||||
|
@ -33,7 +33,7 @@ module S3
|
|||
def self.get_or_create_directory(name)
|
||||
@fog_loaded = require 'fog' unless @fog_loaded
|
||||
|
||||
options = S3.generate_options
|
||||
options = S3Store.generate_options
|
||||
|
||||
fog = Fog::Storage.new(options)
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
require 'spec_helper'
|
||||
require 'fog'
|
||||
require 's3'
|
||||
require 's3_store'
|
||||
|
||||
describe S3 do
|
||||
describe S3Store do
|
||||
|
||||
describe "store_file" do
|
||||
|
||||
|
@ -25,7 +25,7 @@ describe S3 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...
|
||||
S3.store_file(file, "SHA", 1).should == '//s3.amazonaws.com/S3_Upload_Bucket/1SHA.png'
|
||||
S3Store.store_file(file, "SHA", 1).should == '//s3.amazonaws.com/S3_Upload_Bucket/1SHA.png'
|
||||
end
|
||||
|
||||
after(:each) do
|
|
@ -119,12 +119,12 @@ describe Upload do
|
|||
it "store files on s3 when enabled" do
|
||||
SiteSetting.expects(:enable_s3_uploads?).returns(true)
|
||||
LocalStore.expects(:store_file).never
|
||||
S3.expects(:store_file)
|
||||
S3Store.expects(:store_file)
|
||||
Upload.store_file(image, image_sha1, 1)
|
||||
end
|
||||
|
||||
it "store files locally by default" do
|
||||
S3.expects(:store_file).never
|
||||
S3Store.expects(:store_file).never
|
||||
LocalStore.expects(:store_file)
|
||||
Upload.store_file(image, image_sha1, 1)
|
||||
end
|
||||
|
@ -136,12 +136,12 @@ describe Upload do
|
|||
it "remove files on s3 when enabled" do
|
||||
SiteSetting.expects(:enable_s3_uploads?).returns(true)
|
||||
LocalStore.expects(:remove_file).never
|
||||
S3.expects(:remove_file)
|
||||
S3Store.expects(:remove_file)
|
||||
Upload.remove_file(upload.url)
|
||||
end
|
||||
|
||||
it "remove files locally by default" do
|
||||
S3.expects(:remove_file).never
|
||||
S3Store.expects(:remove_file).never
|
||||
LocalStore.expects(:remove_file)
|
||||
Upload.remove_file(upload.url)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue