about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHolger <holgerhuo@outlook.com>2022-04-02 05:56:23 +0800
committerGitHub <noreply@github.com>2022-04-01 23:56:23 +0200
commit39b489ba4c362997b41dd039971b8b510f6fe10d (patch)
tree5e3437fec7a1060afb6e9d16a38324d07e0ed47a
parent44b7be45f1161d6378dba13e083b3c05d90cf0fa (diff)
fix: `s3_force_single_request` not parsed (#17922)
-rw-r--r--config/application.rb1
-rw-r--r--config/initializers/paperclip.rb20
-rw-r--r--lib/paperclip/storage_extensions.rb21
3 files changed, 20 insertions, 22 deletions
diff --git a/config/application.rb b/config/application.rb
index eb5af9cc0..bed935ce3 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -27,7 +27,6 @@ require_relative '../lib/sanitize_ext/sanitize_config'
 require_relative '../lib/redis/namespace_extensions'
 require_relative '../lib/paperclip/url_generator_extensions'
 require_relative '../lib/paperclip/attachment_extensions'
-require_relative '../lib/paperclip/storage_extensions'
 require_relative '../lib/paperclip/lazy_thumbnail'
 require_relative '../lib/paperclip/gif_transcoder'
 require_relative '../lib/paperclip/transcoder'
diff --git a/config/initializers/paperclip.rb b/config/initializers/paperclip.rb
index e2a045647..26b0a2f7c 100644
--- a/config/initializers/paperclip.rb
+++ b/config/initializers/paperclip.rb
@@ -83,6 +83,26 @@ if ENV['S3_ENABLED'] == 'true'
       s3_host_alias: ENV['S3_ALIAS_HOST'] || ENV['S3_CLOUDFRONT_HOST']
     )
   end
+
+  # Some S3-compatible providers might not actually be compatible with some APIs
+  # used by kt-paperclip, see https://github.com/mastodon/mastodon/issues/16822
+  if ENV['S3_FORCE_SINGLE_REQUEST'] == 'true'
+    module Paperclip
+      module Storage
+        module S3Extensions
+          def copy_to_local_file(style, local_dest_path)
+            log("copying #{path(style)} to local file #{local_dest_path}")
+            s3_object(style).download_file(local_dest_path, { mode: 'single_request' })
+          rescue Aws::Errors::ServiceError => e
+            warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
+            false
+          end
+        end
+      end
+    end
+
+    Paperclip::Storage::S3.prepend(Paperclip::Storage::S3Extensions)
+  end
 elsif ENV['SWIFT_ENABLED'] == 'true'
   require 'fog/openstack'
 
diff --git a/lib/paperclip/storage_extensions.rb b/lib/paperclip/storage_extensions.rb
deleted file mode 100644
index 95c35641e..000000000
--- a/lib/paperclip/storage_extensions.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-# frozen_string_literal: true
-
-# Some S3-compatible providers might not actually be compatible with some APIs
-# used by kt-paperclip, see https://github.com/mastodon/mastodon/issues/16822
-if ENV['S3_ENABLED'] == 'true' && ENV['S3_FORCE_SINGLE_REQUEST'] == 'true'
-  module Paperclip
-    module Storage
-      module S3Extensions
-        def copy_to_local_file(style, local_dest_path)
-          log("copying #{path(style)} to local file #{local_dest_path}")
-          s3_object(style).download_file(local_dest_path, { mode: 'single_request' })
-        rescue Aws::Errors::ServiceError => e
-          warn("#{e} - cannot copy #{path(style)} to local file #{local_dest_path}")
-          false
-        end
-      end
-    end
-  end
-
-  Paperclip::Storage::S3.prepend(Paperclip::Storage::S3Extensions)
-end