summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-04 12:45:48 -0800
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-01-04 12:45:48 -0800
commitd25b5d029d539ccccbea25d7efceeddbf4002459 (patch)
tree9e7c0035f852613fb363d1a3ccd96e2851fbda9f /lib
parente680228bf21a20213560f93de1f573b4ab4c2f79 (diff)
parent7cc25205410efc6b20b11d94ab2cbc1a322ff816 (diff)
downloadgitlab-ce-d25b5d029d539ccccbea25d7efceeddbf4002459.tar.gz
Merge pull request #5891 from jhollingsworth/feature/zip-archive
Add support for various archive formats.
Diffstat (limited to 'lib')
-rw-r--r--lib/api/repositories.rb12
-rw-r--r--lib/gitlab/regex.rb5
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: