Browse Source

Fixes #4854 - Storage Provider Simple Storage (S3) is broken.

Tobias Schäfer 1 year ago
parent
commit
29bac4e1c8

+ 1 - 1
app/models/store.rb

@@ -26,7 +26,7 @@ class Store < ApplicationModel
   end
 
   def set_store_file
-    file = Store::File.add(data, content_type: preferences['Content-Type'], filename: filename)
+    file = Store::File.add(data)
     self.size = data.to_s.bytesize
     self.store_file_id = file.id
   end

+ 2 - 2
app/models/store/file.rb

@@ -17,7 +17,7 @@ do also verify of written data
 
 =end
 
-    def self.add(data, verify = true, *args)
+    def self.add(data, verify = true)
       sha = checksum(data)
 
       file = Store::File.find_by(sha: sha)
@@ -30,7 +30,7 @@ do also verify of written data
         end
 
         adapter = "Store::Provider::#{adapter_name}".constantize
-        adapter.add(data, sha, args)
+        adapter.add(data, sha)
         file = Store::File.create(
           provider: adapter_name,
           sha:      sha,

+ 1 - 1
app/models/store/provider/db.rb

@@ -5,7 +5,7 @@ class Store
     class DB < ApplicationModel
       self.table_name = 'store_provider_dbs'
 
-      def self.add(data, sha, *)
+      def self.add(data, sha)
         Store::Provider::DB.create(
           data: data,
           sha:  sha,

+ 1 - 1
app/models/store/provider/file.rb

@@ -3,7 +3,7 @@
 class Store::Provider::File
 
   # write file to fs
-  def self.add(data, sha, *)
+  def self.add(data, sha)
     location = get_location(sha)
 
     # write file to file system

+ 6 - 10
app/models/store/provider/s3.rb

@@ -8,19 +8,15 @@ module Store::Provider::S3
 
   class << self
 
-    def add(data, sha, content_type: 'application/octet-stream', filename: nil)
+    def add(data, sha)
       if data.bytesize > Store::Provider::S3::Config.max_chunk_size
         return upload(data, sha, content_type:, filename:)
       end
 
       client.put_object(
-        bucket:       bucket,
-        key:          sha,
-        body:         data,
-        content_type: content_type,
-        metadata:     {
-          filename: filename || sha,
-        }
+        bucket: bucket,
+        key:    sha,
+        body:   data
       )
 
       true
@@ -48,8 +44,8 @@ module Store::Provider::S3
       object.body.read
     end
 
-    def upload(data, sha, content_type: 'application/octet-stream', filename: nil)
-      id    = Store::Provider::S3::Upload.create(sha, content_type:, filename:)
+    def upload(data, sha)
+      id    = Store::Provider::S3::Upload.create(sha)
       parts = Store::Provider::S3::Upload.process(data, sha, id)
 
       Store::Provider::S3::Upload.complete(sha, parts, id)

+ 3 - 7
app/models/store/provider/s3/upload.rb

@@ -12,14 +12,10 @@ module Store::Provider::S3::Upload
       )
     end
 
-    def create(sha, content_type: 'application/octet-stream', filename: nil)
+    def create(sha)
       info = Store::Provider::S3.client.create_multipart_upload(
-        bucket:       bucket,
-        key:          sha,
-        content_type: content_type,
-        metadata:     {
-          filename: filename || sha,
-        }
+        bucket: bucket,
+        key:    sha
       )
 
       info['upload_id']

+ 1 - 3
spec/models/store/provider/s3_spec.rb

@@ -93,11 +93,9 @@ RSpec.describe Store::Provider::S3, authenticated_as: false, integration: true d
   describe '.add' do
     let(:data)         { Rails.root.join('spec/fixtures/files/image/large.png').read }
     let(:sha256)       { Digest::SHA256.hexdigest(data) }
-    let(:content_type) { 'image/png' }
-    let(:filename)     { 'large.png' }
 
     it 'adds a file' do
-      expect(described_class.add(data, sha256, content_type:, filename:)).to be_truthy
+      expect(described_class.add(data, sha256)).to be_truthy
     end
 
     context 'when connection fails' do