Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/controllers/active_storage_db/files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def update
private

def acceptable_content?(token)
token[:content_type] == request.content_mime_type && token[:content_length] == request.content_length
token[:content_type] == request.content_mime_type &&
token[:content_length] == request.content_length
end

def db_service
Expand All @@ -53,15 +54,19 @@ def serve_file(key, content_type:, disposition:)
send_data(db_service.download(key), options)
end

def upload_file(token, body:)
def upload_file(token, body:) # rubocop:disable Naming/PredicateMethod
return false unless acceptable_content?(token)

db_service.upload(token[:key], request.body, checksum: token[:checksum])
true
end

def unprocessable
Gem::Version.new(Rails.version) >= Gem::Version.new("7.1") ? :unprocessable_content : :unprocessable_entity
if Rails::VERSION::MAJOR > 7 || (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1)
:unprocessable_content
else
:unprocessable_entity
end
end
end
end
Loading