swift-enable the paperclip! 📎 (#2322)

pull/141/head
Adam Thurlow 2017-09-05 18:17:06 -03:00 committed by Eugen Rochko
parent be7ffa2d75
commit 6994664a13
5 changed files with 39 additions and 1 deletions

View File

@ -15,6 +15,7 @@ gem 'pghero', '~> 1.7'
gem 'dotenv-rails', '~> 2.2'
gem 'aws-sdk', '~> 2.9'
gem 'fog-openstack', '~> 0.1'
gem 'paperclip', '~> 5.1'
gem 'paperclip-av-transcoder', '~> 0.6'

View File

@ -154,12 +154,25 @@ GEM
erubis (2.7.0)
et-orbi (1.0.5)
tzinfo
excon (0.58.0)
execjs (2.7.0)
fabrication (2.16.2)
faker (1.7.3)
i18n (~> 0.5)
fast_blank (1.0.0)
ffi (1.9.18)
fog-core (1.45.0)
builder
excon (~> 0.58)
formatador (~> 0.2)
fog-json (1.0.2)
fog-core (~> 1.0)
multi_json (~> 1.10)
fog-openstack (0.1.21)
fog-core (>= 1.40)
fog-json (>= 1.0)
ipaddress (>= 0.8)
formatador (0.2.5)
fuubar (2.2.0)
rspec-core (~> 3.0)
ruby-progressbar (~> 1.4)
@ -211,6 +224,7 @@ GEM
rainbow (~> 2.2)
terminal-table (>= 1.5.1)
idn-ruby (0.1.0)
ipaddress (0.8.3)
jmespath (1.3.1)
json (2.1.0)
json-ld (2.1.5)
@ -535,6 +549,7 @@ DEPENDENCIES
fabrication (~> 2.16)
faker (~> 1.7)
fast_blank (~> 1.0)
fog-openstack (~> 0.1)
fuubar (~> 2.2)
goldfinger (~> 2.0)
hamlit-rails (~> 0.2)

View File

@ -12,8 +12,14 @@ module RoutingHelper
end
def full_asset_url(source, options = {})
source = ActionController::Base.helpers.asset_url(source, options) unless Rails.configuration.x.use_s3
source = ActionController::Base.helpers.asset_url(source, options) unless use_storage?
URI.join(root_url, source).to_s
end
private
def use_storage?
Rails.configuration.x.use_s3 || Rails.configuration.x.use_swift
end
end

View File

@ -12,6 +12,7 @@ Rails.application.configure do
config.x.web_domain = web_host
config.x.use_https = https
config.x.use_s3 = ENV['S3_ENABLED'] == 'true'
config.x.use_swift = ENV['SWIFT_ENABLED'] == 'true'
config.x.alternate_domains = alternate_domains.split(/\s*,\s*/)

View File

@ -40,6 +40,21 @@ if ENV['S3_ENABLED'] == 'true'
Paperclip::Attachment.default_options[:url] = ':s3_alias_url'
Paperclip::Attachment.default_options[:s3_host_alias] = ENV['S3_CLOUDFRONT_HOST']
end
elsif ENV['SWIFT_ENABLED'] == 'true'
Paperclip::Attachment.default_options.merge!(
path: ':class/:attachment/:id_partition/:style/:filename',
storage: :fog,
fog_credentials: {
provider: 'OpenStack',
openstack_username: ENV.fetch('SWIFT_USERNAME'),
openstack_tenant: ENV.fetch('SWIFT_TENANT'),
openstack_api_key: ENV.fetch('SWIFT_PASSWORD'),
openstack_auth_url: ENV.fetch('SWIFT_AUTH_URL'),
},
fog_directory: ENV.fetch('SWIFT_CONTAINER'),
fog_host: ENV.fetch('SWIFT_OBJECT_URL'),
fog_public: true
)
else
Paperclip::Attachment.default_options[:path] = (ENV['PAPERCLIP_ROOT_PATH'] || ':rails_root/public/system') + '/:class/:attachment/:id_partition/:style/:filename'
Paperclip::Attachment.default_options[:url] = (ENV['PAPERCLIP_ROOT_URL'] || '/system') + '/:class/:attachment/:id_partition/:style/:filename'