Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-10 12:09:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-10 12:09:49 +0300
commit14b71b2795e7765989101241ee89d7bfa55bd838 (patch)
tree55289a166041cb93deea0457d69c6d00d82d54d4 /app/services
parent991caa14edb67f7fd575e981e4755cfc743bac31 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r--app/services/design_management/save_designs_service.rb2
-rw-r--r--app/services/lfs/file_transformer.rb16
2 files changed, 13 insertions, 5 deletions
diff --git a/app/services/design_management/save_designs_service.rb b/app/services/design_management/save_designs_service.rb
index 64537293e65..ea5675c6ddd 100644
--- a/app/services/design_management/save_designs_service.rb
+++ b/app/services/design_management/save_designs_service.rb
@@ -113,7 +113,7 @@ module DesignManagement
def file_content(file, full_path)
transformer = ::Lfs::FileTransformer.new(project, repository, target_branch)
- transformer.new_file(full_path, file.to_io).content
+ transformer.new_file(full_path, file.to_io, detect_content_type: Feature.enabled?(:design_management_allow_dangerous_images, project)).content
end
# Returns the latest blobs for the designs as a Hash of `{ Design => Blob }`
diff --git a/app/services/lfs/file_transformer.rb b/app/services/lfs/file_transformer.rb
index 69d33e1c873..a02fce552cf 100644
--- a/app/services/lfs/file_transformer.rb
+++ b/app/services/lfs/file_transformer.rb
@@ -29,11 +29,11 @@ module Lfs
@branch_name = branch_name
end
- def new_file(file_path, file_content, encoding: nil)
+ def new_file(file_path, file_content, encoding: nil, detect_content_type: false)
if project.lfs_enabled? && lfs_file?(file_path)
file_content = parse_file_content(file_content, encoding: encoding)
lfs_pointer_file = Gitlab::Git::LfsPointerFile.new(file_content)
- lfs_object = create_lfs_object!(lfs_pointer_file, file_content)
+ lfs_object = create_lfs_object!(lfs_pointer_file, file_content, detect_content_type)
link_lfs_object!(lfs_object)
@@ -63,9 +63,17 @@ module Lfs
end
# rubocop: disable CodeReuse/ActiveRecord
- def create_lfs_object!(lfs_pointer_file, file_content)
+ def create_lfs_object!(lfs_pointer_file, file_content, detect_content_type)
LfsObject.find_or_create_by(oid: lfs_pointer_file.sha256, size: lfs_pointer_file.size) do |lfs_object|
- lfs_object.file = CarrierWaveStringFile.new(file_content)
+ lfs_object.file = if detect_content_type && (content_type = Gitlab::Utils::MimeType.from_string(file_content))
+ CarrierWaveStringFile.new_file(
+ file_content: file_content,
+ filename: '',
+ content_type: content_type
+ )
+ else
+ CarrierWaveStringFile.new(file_content)
+ end
end
end
# rubocop: enable CodeReuse/ActiveRecord