diff options
Diffstat (limited to 'lib/api/helpers/snippets_helpers.rb')
-rw-r--r-- | lib/api/helpers/snippets_helpers.rb | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/lib/api/helpers/snippets_helpers.rb b/lib/api/helpers/snippets_helpers.rb index 20aeca6a9d3..f95d066bd7c 100644 --- a/lib/api/helpers/snippets_helpers.rb +++ b/lib/api/helpers/snippets_helpers.rb @@ -3,15 +3,37 @@ module API module Helpers module SnippetsHelpers + extend Grape::API::Helpers + + params :raw_file_params do + requires :file_path, type: String, file_path: true, desc: 'The url encoded path to the file, e.g. lib%2Fclass%2Erb' + requires :ref, type: String, desc: 'The name of branch, tag or commit' + end + def content_for(snippet) if snippet.empty_repo? + env['api.format'] = :txt + content_type 'text/plain' + header['Content-Disposition'] = 'attachment' + snippet.content else blob = snippet.blobs.first - blob.load_all_data! - blob.data + + send_git_blob(blob.repository, blob) end end + + def file_content_for(snippet) + repo = snippet.repository + commit = repo.commit(params[:ref]) + not_found!('Reference') unless commit + + blob = repo.blob_at(commit.sha, params[:file_path]) + not_found!('File') unless blob + + send_git_blob(repo, blob) + end end end end |