debian-mirror-gitlab/app/uploaders/dependency_proxy/file_uploader.rb

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

37 lines
935 B
Ruby
Raw Permalink Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
class DependencyProxy::FileUploader < GitlabUploader
2021-11-18 22:05:49 +05:30
extend Workhorse::UploadPath
2021-01-29 00:20:46 +05:30
include ObjectStorage::Concern
2021-04-17 20:07:23 +05:30
before :cache, :set_content_type
2023-05-27 22:25:52 +05:30
storage_location :dependency_proxy
2021-01-29 00:20:46 +05:30
alias_method :upload, :model
def filename
model.file_name
end
def store_dir
dynamic_segment
end
private
2021-04-17 20:07:23 +05:30
# Docker manifests return a custom content type
# GCP will only use the content-type that is stored with the file
# and will not allow it to be overwritten when downloaded
# so we must store the custom content type in object storage.
# This does not apply to DependencyProxy::Blob uploads.
def set_content_type(file)
2021-09-30 23:02:18 +05:30
return unless model.instance_of?(DependencyProxy::Manifest)
2021-04-17 20:07:23 +05:30
file.content_type = model.content_type
end
2021-01-29 00:20:46 +05:30
def dynamic_segment
Gitlab::HashedPath.new('dependency_proxy', model.group_id, 'files', model.id, root_hash: model.group_id)
end
end