blob: 975050c26e4822d30fcc6f3a90b878cfa2c4efc5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# frozen_string_literal: true
module DesignManagement
# This Uploader is used to generate and serve the smaller versions of
# the design files.
#
# The original (full-sized) design files are stored in Git LFS, and so
# have a different uploader, `LfsObjectUploader`.
class DesignV432x230Uploader < GitlabUploader
include CarrierWave::MiniMagick
include RecordsUploads::Concern
include ObjectStorage::Concern
prepend ObjectStorage::Extension::RecordsUploads
# We choose not to resize `image/ico` as we assume there will be no
# benefit in generating an 432x230 sized icon.
#
# We currently cannot resize `image/tiff`.
# See https://gitlab.com/gitlab-org/gitlab/issues/207740
#
# We currently choose not to resize `image/svg+xml` for security reasons.
# See https://gitlab.com/gitlab-org/gitlab/issues/207740#note_302766171
MIME_TYPE_ALLOWLIST = %w(image/png image/jpeg image/bmp image/gif).freeze
process resize_to_fit: [432, 230]
# Allow CarrierWave to reject files without correct mimetypes.
def content_type_whitelist
MIME_TYPE_ALLOWLIST
end
# Override `GitlabUploader` and always return false, otherwise local
# `LfsObject` files would be deleted.
# https://github.com/carrierwaveuploader/carrierwave/blob/f84672a/lib/carrierwave/uploader/cache.rb#L131-L135
def move_to_cache
false
end
private
def dynamic_segment
File.join(model.class.underscore, mounted_as.to_s, model.id.to_s)
end
end
end
|