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
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-06-06 18:18:36 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-06-06 18:18:36 +0300
commit6503150dcdf03a450b58a2d264735393e8728879 (patch)
tree8900805eefd8474454b295ced683d667f33c4f98 /app
parent81a855a7df8cf24195b11dbec8f296b0bae440bb (diff)
Add latest changes from gitlab-org/gitlab@16-0-stable-ee
Diffstat (limited to 'app')
-rw-r--r--app/controllers/repositories/lfs_api_controller.rb56
1 files changed, 53 insertions, 3 deletions
diff --git a/app/controllers/repositories/lfs_api_controller.rb b/app/controllers/repositories/lfs_api_controller.rb
index d52ae723eee..32119ddf89e 100644
--- a/app/controllers/repositories/lfs_api_controller.rb
+++ b/app/controllers/repositories/lfs_api_controller.rb
@@ -6,6 +6,10 @@ module Repositories
include Gitlab::Utils::StrongMemoize
LFS_TRANSFER_CONTENT_TYPE = 'application/octet-stream'
+ # Downloading directly with presigned URLs via batch requests
+ # require longer expire time.
+ # The 1h should be enough to download 100 objects.
+ LFS_DIRECT_BATCH_EXPIRE_IN = 3600.seconds
skip_before_action :lfs_check_access!, only: [:deprecated]
before_action :lfs_check_batch_operation!, only: [:batch]
@@ -22,7 +26,11 @@ module Repositories
end
if download_request?
- render json: { objects: download_objects! }, content_type: LfsRequest::CONTENT_TYPE
+ if Feature.enabled?(:lfs_batch_direct_downloads, project)
+ render json: { objects: download_objects! }, content_type: LfsRequest::CONTENT_TYPE
+ else
+ render json: { objects: legacy_download_objects! }, content_type: LfsRequest::CONTENT_TYPE
+ end
elsif upload_request?
render json: { objects: upload_objects! }, content_type: LfsRequest::CONTENT_TYPE
else
@@ -52,11 +60,34 @@ module Repositories
end
def download_objects!
+ existing_oids = project.lfs_objects
+ .for_oids(objects_oids)
+ .index_by(&:oid)
+
+ objects.each do |object|
+ if lfs_object = existing_oids[object[:oid]]
+ object[:actions] = download_actions(object, lfs_object)
+
+ if Guest.can?(:download_code, project)
+ object[:authenticated] = true
+ end
+ else
+ object[:error] = {
+ code: 404,
+ message: _("Object does not exist on the server or you don't have permissions to access it")
+ }
+ end
+ end
+
+ objects
+ end
+
+ def legacy_download_objects!
existing_oids = project.lfs_objects_oids(oids: objects_oids)
objects.each do |object|
if existing_oids.include?(object[:oid])
- object[:actions] = download_actions(object)
+ object[:actions] = proxy_download_actions(object)
if Guest.can?(:download_code, project)
object[:authenticated] = true
@@ -85,7 +116,26 @@ module Repositories
objects
end
- def download_actions(object)
+ def download_actions(object, lfs_object)
+ if lfs_object.file.file_storage? || lfs_object.file.class.proxy_download_enabled?
+ proxy_download_actions(object)
+ else
+ direct_download_actions(lfs_object)
+ end
+ end
+
+ def direct_download_actions(lfs_object)
+ {
+ download: {
+ href: lfs_object.file.url(
+ content_type: "application/octet-stream",
+ expire_at: LFS_DIRECT_BATCH_EXPIRE_IN.since
+ )
+ }
+ }
+ end
+
+ def proxy_download_actions(object)
{
download: {
href: "#{project.http_url_to_repo}/gitlab-lfs/objects/#{object[:oid]}",