The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

46 lines
2.1 KiB

  1. # frozen_string_literal: true
  2. Paperclip.options[:read_timeout] = 60
  3. Paperclip.interpolates :filename do |attachment, style|
  4. return attachment.original_filename if style == :original
  5. [basename(attachment, style), extension(attachment, style)].delete_if(&:empty?).join('.')
  6. end
  7. if ENV['S3_ENABLED'] == 'true'
  8. Aws.eager_autoload!(services: %w(S3))
  9. Paperclip::Attachment.default_options[:storage] = :s3
  10. Paperclip::Attachment.default_options[:s3_protocol] = ENV.fetch('S3_PROTOCOL') { 'https' }
  11. Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
  12. Paperclip::Attachment.default_options[:s3_host_name] = ENV.fetch('S3_HOSTNAME') { "s3-#{ENV.fetch('S3_REGION')}.amazonaws.com" }
  13. Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'
  14. Paperclip::Attachment.default_options[:s3_headers] = { 'Cache-Control' => 'max-age=315576000' }
  15. Paperclip::Attachment.default_options[:s3_permissions] = 'public-read'
  16. Paperclip::Attachment.default_options[:s3_region] = ENV.fetch('S3_REGION') { 'us-east-1' }
  17. Paperclip::Attachment.default_options[:s3_credentials] = {
  18. bucket: ENV.fetch('S3_BUCKET'),
  19. access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
  20. secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
  21. }
  22. unless ENV['S3_ENDPOINT'].blank?
  23. Paperclip::Attachment.default_options[:s3_options] = {
  24. endpoint: ENV['S3_ENDPOINT'],
  25. signature_version: ENV['S3_SIGNATURE_VERSION'] || 'v4',
  26. force_path_style: true,
  27. }
  28. Paperclip::Attachment.default_options[:url] = ':s3_path_url'
  29. end
  30. unless ENV['S3_CLOUDFRONT_HOST'].blank?
  31. Paperclip::Attachment.default_options[:url] = ':s3_alias_url'
  32. Paperclip::Attachment.default_options[:s3_host_alias] = ENV['S3_CLOUDFRONT_HOST']
  33. end
  34. else
  35. Paperclip::Attachment.default_options[:path] = (ENV['PAPERCLIP_ROOT_PATH'] || ':rails_root/public/system') + '/:class/:attachment/:id_partition/:style/:filename'
  36. Paperclip::Attachment.default_options[:url] = (ENV['PAPERCLIP_ROOT_URL'] || '/system') + '/:class/:attachment/:id_partition/:style/:filename'
  37. end