Class: Gitlab::Lfs::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/lfs/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(project, user, request) ⇒ Response

Returns a new instance of Response


5
6
7
8
9
10
11
# File 'lib/gitlab/lfs/response.rb', line 5

def initialize(project, user, request)
  @origin_project = project
  @project = storage_project(project)
  @user = user
  @env = request.env
  @request = request
end

Instance Method Details

#render_batch_operation_responseObject


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/lfs/response.rb', line 23

def render_batch_operation_response
  request_body = JSON.parse(@request.body.read)
  case request_body["operation"]
  when "download"
    render_batch_download(request_body)
  when "upload"
    render_batch_upload(request_body)
  else
    render_not_found
  end
end

#render_download_object_response(oid) ⇒ Object


13
14
15
16
17
18
19
20
21
# File 'lib/gitlab/lfs/response.rb', line 13

def render_download_object_response(oid)
  render_response_to_download do
    if check_download_sendfile_header?
      render_lfs_sendfile(oid)
    else
      render_not_found
    end
  end
end

#render_storage_upload_authorize_response(oid, size) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gitlab/lfs/response.rb', line 35

def render_storage_upload_authorize_response(oid, size)
  render_response_to_push do
    [
      200,
      { "Content-Type" => "application/json; charset=utf-8" },
      [JSON.dump({
        'StoreLFSPath' => "#{Gitlab.config.lfs.storage_path}/tmp/upload",
        'LfsOid' => oid,
        'LfsSize' => size
      })]
    ]
  end
end

#render_storage_upload_store_response(oid, size, tmp_file_name) ⇒ Object


49
50
51
52
53
# File 'lib/gitlab/lfs/response.rb', line 49

def render_storage_upload_store_response(oid, size, tmp_file_name)
  render_response_to_push do
    render_lfs_upload_ok(oid, size, tmp_file_name)
  end
end

#render_unsupported_deprecated_apiObject


55
56
57
58
59
60
61
62
63
64
# File 'lib/gitlab/lfs/response.rb', line 55

def render_unsupported_deprecated_api
  [
    501,
    { "Content-Type" => "application/json; charset=utf-8" },
    [JSON.dump({
      'message' => 'Server supports batch API only, please update your Git LFS client to version 1.0.1 and up.',
      'documentation_url' => "#{Gitlab.config.gitlab.url}/help",
    })]
  ]
end