blob: f95d066bd7cf353b38fb315ee353e07eb15ec8f0 (
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
|
# frozen_string_literal: true
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
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
|