diff options
| author | Jason Hollingsworth <jhworth.developer@gmail.com> | 2013-12-20 13:12:44 -0600 |
|---|---|---|
| committer | Jason Hollingsworth <jhworth.developer@gmail.com> | 2014-01-02 10:18:56 -0600 |
| commit | 7cc25205410efc6b20b11d94ab2cbc1a322ff816 (patch) | |
| tree | 8d8ce2cd304bd46426bb4c186ca690e6650e5d57 /lib | |
| parent | b512fbc0ecba0a8de9c9efe5c7d82a97f0ea744c (diff) | |
| download | gitlab-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')
| -rw-r--r-- | lib/api/repositories.rb | 12 | ||||
| -rw-r--r-- | lib/gitlab/regex.rb | 5 |
2 files changed, 13 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 diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index 93e013ab1b3..943dc9dc7ea 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -17,6 +17,11 @@ module Gitlab def path_regex default_regex end + + def archive_formats_regex + #|zip|tar| tar.gz | tar.bz2 | + /(zip|tar|tar\.gz|tgz|gz|tar\.bz2|tbz|tbz2|tb2|bz2)/ + end def git_reference_regex # Valid git ref regex, see: |
