summaryrefslogtreecommitdiff
path: root/lib/api/project_export.rb
blob: efc4a33ae1b2e6cadf772b6b1305d1c868398035 (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
46
module API
  class ProjectExport < Grape::API
    before do
      not_found! unless Gitlab::CurrentSettings.project_export_enabled?
      authorize_admin_project
    end

    params do
      requires :id, type: String, desc: 'The ID of a project'
    end
    resource :projects, requirements: { id: %r{[^/]+} } do
      desc 'Get export status' do
        detail 'This feature was introduced in GitLab 10.6.'
        success Entities::ProjectExportStatus
      end
      get ':id/export' do
        present user_project, with: Entities::ProjectExportStatus
      end

      desc 'Download export' do
        detail 'This feature was introduced in GitLab 10.6.'
      end
      get ':id/export/download' do
        path = user_project.export_project_path

        render_api_error!('404 Not found or has expired', 404) unless path

        present_disk_file!(path, File.basename(path), 'application/gzip')
      end

      desc 'Start export' do
        detail 'This feature was introduced in GitLab 10.6.'
      end
      params do
        optional :description, type: String, desc: 'Override the project description'
      end
      post ':id/export' do
        project_export_params = declared_params(include_missing: false)

        user_project.add_export_job(current_user: current_user, params: project_export_params)

        accepted!
      end
    end
  end
end