]> cat aescling's git repositories - mastodon.git/commitdiff
Add S3_FORCE_SINGLE_REQUEST env var to work around S3 compatibility issues (#16866)
authorClaire <claire.github-309c@sitedethib.com>
Mon, 18 Oct 2021 16:29:04 +0000 (18:29 +0200)
committerGitHub <noreply@github.com>
Mon, 18 Oct 2021 16:29:04 +0000 (18:29 +0200)
Fixes #16822

config/application.rb
lib/paperclip/storage_extensions.rb [new file with mode: 0644]

index b92d749c1ef767c6f91a140cd28b1ff73e991657..5617228849bb057604f7c4ad9db6868bf39b3a5b 100644 (file)
@@ -27,6 +27,7 @@ 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/lib/paperclip/storage_extensions.rb b/lib/paperclip/storage_extensions.rb
new file mode 100644 (file)
index 0000000..95c3564
--- /dev/null
@@ -0,0 +1,21 @@
+# 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