logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

paperclip.rb (2719B)


  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(&:blank?).join('.')
  6. end
  7. Paperclip::Attachment.default_options.merge!(
  8. use_timestamp: false,
  9. path: ':class/:attachment/:id_partition/:style/:filename',
  10. storage: :fog
  11. )
  12. if ENV['S3_ENABLED'] == 'true'
  13. require 'aws-sdk-s3'
  14. s3_region = ENV.fetch('S3_REGION') { 'us-east-1' }
  15. s3_protocol = ENV.fetch('S3_PROTOCOL') { 'https' }
  16. s3_hostname = ENV.fetch('S3_HOSTNAME') { "s3-#{s3_region}.amazonaws.com" }
  17. Paperclip::Attachment.default_options.merge!(
  18. storage: :s3,
  19. s3_protocol: s3_protocol,
  20. s3_host_name: s3_hostname,
  21. s3_headers: {
  22. 'Cache-Control' => 'max-age=315576000',
  23. },
  24. s3_permissions: ENV.fetch('S3_PERMISSION') { 'public-read' },
  25. s3_region: s3_region,
  26. s3_credentials: {
  27. bucket: ENV['S3_BUCKET'],
  28. access_key_id: ENV['AWS_ACCESS_KEY_ID'],
  29. secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
  30. },
  31. s3_options: {
  32. signature_version: ENV.fetch('S3_SIGNATURE_VERSION') { 'v4' },
  33. }
  34. )
  35. if ENV.has_key?('S3_ENDPOINT')
  36. Paperclip::Attachment.default_options[:s3_options].merge!(
  37. endpoint: ENV['S3_ENDPOINT'],
  38. force_path_style: true
  39. )
  40. Paperclip::Attachment.default_options[:url] = ':s3_path_url'
  41. end
  42. if ENV.has_key?('S3_CLOUDFRONT_HOST')
  43. Paperclip::Attachment.default_options.merge!(
  44. url: ':s3_alias_url',
  45. s3_host_alias: ENV['S3_CLOUDFRONT_HOST']
  46. )
  47. end
  48. elsif ENV['SWIFT_ENABLED'] == 'true'
  49. require 'fog/openstack'
  50. Paperclip::Attachment.default_options.merge!(
  51. fog_credentials: {
  52. provider: 'OpenStack',
  53. openstack_username: ENV['SWIFT_USERNAME'],
  54. openstack_project_name: ENV['SWIFT_TENANT'],
  55. openstack_tenant: ENV['SWIFT_TENANT'], # Some OpenStack-v2 ignores project_name but needs tenant
  56. openstack_api_key: ENV['SWIFT_PASSWORD'],
  57. openstack_auth_url: ENV['SWIFT_AUTH_URL'],
  58. openstack_domain_name: ENV.fetch('SWIFT_DOMAIN_NAME') { 'default' },
  59. openstack_region: ENV['SWIFT_REGION'],
  60. openstack_cache_ttl: ENV.fetch('SWIFT_CACHE_TTL') { 60 },
  61. },
  62. fog_directory: ENV['SWIFT_CONTAINER'],
  63. fog_host: ENV['SWIFT_OBJECT_URL'],
  64. fog_public: true
  65. )
  66. else
  67. require 'fog/local'
  68. Paperclip::Attachment.default_options.merge!(
  69. fog_credentials: {
  70. provider: 'Local',
  71. local_root: ENV.fetch('PAPERCLIP_ROOT_PATH') { Rails.root.join('public', 'system') },
  72. },
  73. fog_directory: '',
  74. fog_host: ENV.fetch('PAPERCLIP_ROOT_URL') { '/system' }
  75. )
  76. end