]> cat aescling's git repositories - mastodon.git/commitdiff
fix: `s3_force_single_request` not parsed (#17922)
authorHolger <holgerhuo@outlook.com>
Fri, 1 Apr 2022 21:56:23 +0000 (05:56 +0800)
committerGitHub <noreply@github.com>
Fri, 1 Apr 2022 21:56:23 +0000 (23:56 +0200)
config/application.rb
config/initializers/paperclip.rb
lib/paperclip/storage_extensions.rb [deleted file]

index eb5af9cc00d4ea859e9a069918f81c529fc5500a..bed935ce396e36083ed6f243526666a02d70a5d7 100644 (file)
@@ -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'
index e2a045647506223250609426075bcaf531f8fa68..26b0a2f7cd9b6edc1ba35283b4a40f9709676d5d 100644 (file)
@@ -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 (file)
index 95c3564..0000000
+++ /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