闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. Paperclip.options[:read_timeout] = 60
  3. if ENV['S3_ENABLED'] == 'true'
  4. Aws.eager_autoload!(services: %w(S3))
  5. Paperclip::Attachment.default_options[:storage] = :s3
  6. Paperclip::Attachment.default_options[:s3_protocol] = 'https'
  7. Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
  8. Paperclip::Attachment.default_options[:s3_host_name] = ENV.fetch('S3_HOSTNAME') { "s3-#{ENV.fetch('S3_REGION')}.amazonaws.com" }
  9. Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
  10. Paperclip::Attachment.default_options[:s3_headers] = { 'Cache-Control' => 'max-age=315576000', 'Expires' => 10.years.from_now.httpdate }
  11. Paperclip::Attachment.default_options[:s3_permissions] = 'public'
  12. Paperclip::Attachment.default_options[:s3_region] = ENV.fetch('S3_REGION') { 'us-east-1' }
  13. Paperclip::Attachment.default_options[:s3_credentials] = {
  14. bucket: ENV.fetch('S3_BUCKET'),
  15. access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
  16. secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
  17. }
  18. unless ENV['S3_ENDPOINT'].blank?
  19. Paperclip::Attachment.default_options[:s3_options] = {
  20. endpoint: ENV['S3_ENDPOINT'],
  21. force_path_style: true,
  22. }
  23. Paperclip::Attachment.default_options[:url] = ':s3_path_url'
  24. end
  25. unless ENV['S3_CLOUDFRONT_HOST'].blank?
  26. Paperclip::Attachment.default_options[:url] = ':s3_alias_url'
  27. Paperclip::Attachment.default_options[:s3_host_alias] = ENV['S3_CLOUDFRONT_HOST']
  28. end
  29. end