debian-mirror-gitlab/app/uploaders/design_management/design_v432x230_uploader.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.5 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# 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
2022-08-27 11:52:29 +05:30
MIME_TYPE_ALLOWLIST = %w(image/png image/jpeg image/bmp image/gif).freeze
2020-05-24 23:13:21 +05:30
process resize_to_fit: [432, 230]
# Allow CarrierWave to reject files without correct mimetypes.
def content_type_whitelist
2022-08-27 11:52:29 +05:30
MIME_TYPE_ALLOWLIST
2020-05-24 23:13:21 +05:30
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