summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorJason Hollingsworth <jhworth.developer@gmail.com>2013-12-20 13:12:44 -0600
committerJason Hollingsworth <jhworth.developer@gmail.com>2014-01-02 10:18:56 -0600
commit7cc25205410efc6b20b11d94ab2cbc1a322ff816 (patch)
tree8d8ce2cd304bd46426bb4c186ca690e6650e5d57 /lib/api
parentb512fbc0ecba0a8de9c9efe5c7d82a97f0ea744c (diff)
downloadgitlab-ce-7cc25205410efc6b20b11d94ab2cbc1a322ff816.tar.gz
Add support for various archive formats.
Used mime-types gem instead of hardcoding content types. Allow multiple extensions in archive route (.tar.gz, .tar.bz2). Change content disposition from infile(?) to attachment for api. Fixed api would return “archive” instead of {project}-{hash}.{ext}
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/repositories.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index 6a9dc9a39f1..0a32135ff10 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -1,3 +1,5 @@
+require 'mime/types'
+
module API
# Projects API
class Repositories < Grape::API
@@ -206,18 +208,20 @@ module API
# sha (optional) - the commit sha to download defaults to the tip of the default branch
# Example Request:
# GET /projects/:id/repository/archive
- get ":id/repository/archive" do
+ get ":id/repository/archive", requirements: { format: Gitlab::Regex.archive_formats_regex } do
authorize! :download_code, user_project
repo = user_project.repository
ref = params[:sha]
+ format = params[:format]
storage_path = Rails.root.join("tmp", "repositories")
- file_path = repo.archive_repo(ref, storage_path)
+ file_path = repo.archive_repo(ref, storage_path, format)
if file_path && File.exists?(file_path)
data = File.open(file_path, 'rb').read
- header "Content-Disposition:", " infile; filename=\"#{File.basename(file_path)}\""
- content_type 'application/x-gzip'
+ header["Content-Disposition"] = "attachment; filename=\"#{File.basename(file_path)}\""
+
+ content_type MIME::Types.type_for(file_path).first.content_type
env['api.format'] = :binary