2016-12-04 12:07:02 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-08 12:12:54 -06:00
|
|
|
Paperclip.options[:read_timeout] = 60
|
2017-01-07 08:43:56 -06:00
|
|
|
|
2017-03-05 16:03:49 -06:00
|
|
|
Paperclip.interpolates :filename do |attachment, style|
|
|
|
|
return attachment.original_filename if style == :original
|
2017-05-05 14:32:14 -05:00
|
|
|
[basename(attachment, style), extension(attachment, style)].delete_if(&:blank?).join('.')
|
2017-03-05 16:03:49 -06:00
|
|
|
end
|
|
|
|
|
2017-11-07 07:30:31 -06:00
|
|
|
Paperclip::Attachment.default_options.merge!(
|
|
|
|
use_timestamp: false,
|
|
|
|
path: ':class/:attachment/:id_partition/:style/:filename',
|
|
|
|
storage: :fog
|
|
|
|
)
|
2017-10-09 10:52:02 -05:00
|
|
|
|
2016-11-06 11:35:46 -06:00
|
|
|
if ENV['S3_ENABLED'] == 'true'
|
2018-03-24 06:52:45 -05:00
|
|
|
require 'aws-sdk-s3'
|
2016-11-29 07:20:15 -06:00
|
|
|
|
2017-12-08 17:47:52 -06:00
|
|
|
s3_region = ENV.fetch('S3_REGION') { 'us-east-1' }
|
|
|
|
s3_protocol = ENV.fetch('S3_PROTOCOL') { 'https' }
|
2017-12-08 22:59:59 -06:00
|
|
|
s3_hostname = ENV.fetch('S3_HOSTNAME') { "s3-#{s3_region}.amazonaws.com" }
|
2016-11-06 11:35:46 -06:00
|
|
|
|
2017-11-07 07:30:31 -06:00
|
|
|
Paperclip::Attachment.default_options.merge!(
|
2017-12-08 17:47:52 -06:00
|
|
|
storage: :s3,
|
|
|
|
s3_protocol: s3_protocol,
|
|
|
|
s3_host_name: s3_hostname,
|
|
|
|
s3_headers: {
|
|
|
|
'Cache-Control' => 'max-age=315576000',
|
2017-11-07 07:30:31 -06:00
|
|
|
},
|
2017-12-08 17:47:52 -06:00
|
|
|
s3_permissions: ENV.fetch('S3_PERMISSION') { 'public-read' },
|
|
|
|
s3_region: s3_region,
|
|
|
|
s3_credentials: {
|
|
|
|
bucket: ENV['S3_BUCKET'],
|
|
|
|
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
|
|
|
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
|
|
|
|
},
|
|
|
|
s3_options: {
|
|
|
|
signature_version: ENV.fetch('S3_SIGNATURE_VERSION') { 'v4' },
|
2016-12-07 09:59:18 -06:00
|
|
|
}
|
2017-11-07 07:30:31 -06:00
|
|
|
)
|
2016-12-07 09:59:18 -06:00
|
|
|
|
2017-11-07 07:30:31 -06:00
|
|
|
if ENV.has_key?('S3_ENDPOINT')
|
2017-12-08 17:47:52 -06:00
|
|
|
Paperclip::Attachment.default_options[:s3_options].merge!(
|
2017-11-07 07:30:31 -06:00
|
|
|
endpoint: ENV['S3_ENDPOINT'],
|
2017-12-08 17:47:52 -06:00
|
|
|
force_path_style: true
|
2017-11-07 07:30:31 -06:00
|
|
|
)
|
2017-12-08 17:47:52 -06:00
|
|
|
Paperclip::Attachment.default_options[:url] = ':s3_path_url'
|
2016-12-07 09:59:18 -06:00
|
|
|
end
|
2016-12-07 10:19:29 -06:00
|
|
|
|
2018-08-25 06:27:08 -05:00
|
|
|
if ENV.has_key?('S3_ALIAS_HOST') || ENV.has_key?('S3_CLOUDFRONT_HOST')
|
2017-12-08 17:47:52 -06:00
|
|
|
Paperclip::Attachment.default_options.merge!(
|
|
|
|
url: ':s3_alias_url',
|
2018-08-25 06:27:08 -05:00
|
|
|
s3_host_alias: ENV['S3_ALIAS_HOST'] || ENV['S3_CLOUDFRONT_HOST']
|
2017-12-08 17:47:52 -06:00
|
|
|
)
|
2016-12-07 10:19:29 -06:00
|
|
|
end
|
2017-09-05 16:17:06 -05:00
|
|
|
elsif ENV['SWIFT_ENABLED'] == 'true'
|
2017-11-07 07:30:31 -06:00
|
|
|
require 'fog/openstack'
|
|
|
|
|
2017-09-05 16:17:06 -05:00
|
|
|
Paperclip::Attachment.default_options.merge!(
|
|
|
|
fog_credentials: {
|
|
|
|
provider: 'OpenStack',
|
2017-11-07 07:30:31 -06:00
|
|
|
openstack_username: ENV['SWIFT_USERNAME'],
|
2018-05-06 19:28:28 -05:00
|
|
|
openstack_project_id: ENV['SWIFT_PROJECT_ID'],
|
2017-11-07 07:30:31 -06:00
|
|
|
openstack_project_name: ENV['SWIFT_TENANT'],
|
|
|
|
openstack_tenant: ENV['SWIFT_TENANT'], # Some OpenStack-v2 ignores project_name but needs tenant
|
|
|
|
openstack_api_key: ENV['SWIFT_PASSWORD'],
|
|
|
|
openstack_auth_url: ENV['SWIFT_AUTH_URL'],
|
|
|
|
openstack_domain_name: ENV.fetch('SWIFT_DOMAIN_NAME') { 'default' },
|
2017-09-11 08:11:13 -05:00
|
|
|
openstack_region: ENV['SWIFT_REGION'],
|
2017-11-07 07:30:31 -06:00
|
|
|
openstack_cache_ttl: ENV.fetch('SWIFT_CACHE_TTL') { 60 },
|
2017-09-05 16:17:06 -05:00
|
|
|
},
|
2017-11-07 07:30:31 -06:00
|
|
|
fog_directory: ENV['SWIFT_CONTAINER'],
|
2017-11-07 12:06:30 -06:00
|
|
|
fog_host: ENV['SWIFT_OBJECT_URL'],
|
2017-09-05 16:17:06 -05:00
|
|
|
fog_public: true
|
|
|
|
)
|
2017-04-14 19:07:21 -05:00
|
|
|
else
|
2017-11-07 07:30:31 -06:00
|
|
|
Paperclip::Attachment.default_options.merge!(
|
2018-08-21 10:53:01 -05:00
|
|
|
storage: :filesystem,
|
|
|
|
use_timestamp: true,
|
|
|
|
path: (ENV['PAPERCLIP_ROOT_PATH'] || ':rails_root/public/system') + '/:class/:attachment/:id_partition/:style/:filename',
|
|
|
|
url: (ENV['PAPERCLIP_ROOT_URL'] || '/system') + '/:class/:attachment/:id_partition/:style/:filename',
|
2017-11-07 07:30:31 -06:00
|
|
|
)
|
2016-11-06 11:35:46 -06:00
|
|
|
end
|