mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-08-18 05:54:57 +00:00
* Revert "Bump version to 2.3.2rc1" This reverts commitcdf8b92fea
. * Revert "Downgrade Dockerfile to Ruby 2.4.3 on Alpine 3.6 (#6806)" This reverts commit0074cad44f
. * Revert "Handle Mastodon::HostValidationError when pulling remoteable assets (#6782)" This reverts commit4a0a19fe54
. * Revert "Correct the reference to user's password in mastodon:add_user task (#6800)" This reverts commit338bff8b93
. * Revert "Upgrade Paperclip to version 6.0.0 (#6754)" This reverts commitb88fcd53f7
.
88 lines
2.7 KiB
Ruby
88 lines
2.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
Paperclip.options[:read_timeout] = 60
|
|
|
|
Paperclip.interpolates :filename do |attachment, style|
|
|
return attachment.original_filename if style == :original
|
|
[basename(attachment, style), extension(attachment, style)].delete_if(&:blank?).join('.')
|
|
end
|
|
|
|
Paperclip::Attachment.default_options.merge!(
|
|
use_timestamp: false,
|
|
path: ':class/:attachment/:id_partition/:style/:filename',
|
|
storage: :fog
|
|
)
|
|
|
|
if ENV['S3_ENABLED'] == 'true'
|
|
require 'aws-sdk'
|
|
Aws.eager_autoload!(services: %w(S3))
|
|
|
|
s3_region = ENV.fetch('S3_REGION') { 'us-east-1' }
|
|
s3_protocol = ENV.fetch('S3_PROTOCOL') { 'https' }
|
|
s3_hostname = ENV.fetch('S3_HOSTNAME') { "s3-#{s3_region}.amazonaws.com" }
|
|
|
|
Paperclip::Attachment.default_options.merge!(
|
|
storage: :s3,
|
|
s3_protocol: s3_protocol,
|
|
s3_host_name: s3_hostname,
|
|
s3_headers: {
|
|
'Cache-Control' => 'max-age=315576000',
|
|
},
|
|
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' },
|
|
}
|
|
)
|
|
|
|
if ENV.has_key?('S3_ENDPOINT')
|
|
Paperclip::Attachment.default_options[:s3_options].merge!(
|
|
endpoint: ENV['S3_ENDPOINT'],
|
|
force_path_style: true
|
|
)
|
|
Paperclip::Attachment.default_options[:url] = ':s3_path_url'
|
|
end
|
|
|
|
if ENV.has_key?('S3_CLOUDFRONT_HOST')
|
|
Paperclip::Attachment.default_options.merge!(
|
|
url: ':s3_alias_url',
|
|
s3_host_alias: ENV['S3_CLOUDFRONT_HOST']
|
|
)
|
|
end
|
|
elsif ENV['SWIFT_ENABLED'] == 'true'
|
|
require 'fog/openstack'
|
|
|
|
Paperclip::Attachment.default_options.merge!(
|
|
fog_credentials: {
|
|
provider: 'OpenStack',
|
|
openstack_username: ENV['SWIFT_USERNAME'],
|
|
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' },
|
|
openstack_region: ENV['SWIFT_REGION'],
|
|
openstack_cache_ttl: ENV.fetch('SWIFT_CACHE_TTL') { 60 },
|
|
},
|
|
fog_directory: ENV['SWIFT_CONTAINER'],
|
|
fog_host: ENV['SWIFT_OBJECT_URL'],
|
|
fog_public: true
|
|
)
|
|
else
|
|
require 'fog/local'
|
|
|
|
Paperclip::Attachment.default_options.merge!(
|
|
fog_credentials: {
|
|
provider: 'Local',
|
|
local_root: ENV.fetch('PAPERCLIP_ROOT_PATH') { Rails.root.join('public', 'system') },
|
|
},
|
|
fog_directory: '',
|
|
fog_host: ENV.fetch('PAPERCLIP_ROOT_URL') { '/system' }
|
|
)
|
|
end
|