2013-04-03 02:26:38 -04:00
|
|
|
# Controller for viewing a file's raw
|
2013-06-23 12:47:22 -04:00
|
|
|
class Projects::RawController < Projects::ApplicationController
|
2013-04-03 02:26:38 -04:00
|
|
|
include ExtractsPath
|
2016-02-24 05:53:30 -05:00
|
|
|
include BlobHelper
|
2013-04-03 02:26:38 -04:00
|
|
|
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :assign_ref_vars
|
|
|
|
before_action :authorize_download_code!
|
2013-04-03 02:26:38 -04:00
|
|
|
|
|
|
|
def show
|
2013-10-01 13:34:41 -04:00
|
|
|
@blob = @repository.blob_at(@commit.id, @path)
|
2013-04-03 02:26:38 -04:00
|
|
|
|
2013-10-01 10:00:28 -04:00
|
|
|
if @blob
|
2013-09-03 13:55:01 -04:00
|
|
|
headers['X-Content-Type-Options'] = 'nosniff'
|
2016-03-07 08:27:53 -05:00
|
|
|
|
|
|
|
return if cached_blob?
|
2013-09-03 13:55:01 -04:00
|
|
|
|
2015-12-03 11:08:09 -05:00
|
|
|
if @blob.lfs_pointer?
|
|
|
|
send_lfs_object
|
|
|
|
else
|
2016-02-01 05:33:22 -05:00
|
|
|
headers.store(*Gitlab::Workhorse.send_git_blob(@repository, @blob))
|
2016-01-15 12:12:36 -05:00
|
|
|
headers['Content-Disposition'] = 'inline'
|
2016-02-24 05:53:30 -05:00
|
|
|
headers['Content-Type'] = safe_content_type(@blob)
|
2016-02-01 06:01:13 -05:00
|
|
|
head :ok # 'render nothing: true' messes up the Content-Type
|
2015-12-03 11:08:09 -05:00
|
|
|
end
|
2013-04-03 02:26:38 -04:00
|
|
|
else
|
2015-10-09 13:07:29 -04:00
|
|
|
render_404
|
2013-04-03 02:26:38 -04:00
|
|
|
end
|
|
|
|
end
|
2014-02-13 14:09:11 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2015-12-03 11:08:09 -05:00
|
|
|
def send_lfs_object
|
2015-12-07 09:03:50 -05:00
|
|
|
lfs_object = find_lfs_object
|
2015-12-03 11:08:09 -05:00
|
|
|
|
2015-12-07 09:03:50 -05:00
|
|
|
if lfs_object && lfs_object.project_allowed_access?(@project)
|
2015-12-03 11:08:09 -05:00
|
|
|
send_file lfs_object.file.path, filename: @blob.name, disposition: 'attachment'
|
2015-12-07 09:03:50 -05:00
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_lfs_object
|
|
|
|
lfs_object = LfsObject.find_by_oid(@blob.lfs_oid)
|
|
|
|
if lfs_object && lfs_object.file.exists?
|
|
|
|
lfs_object
|
|
|
|
else
|
|
|
|
nil
|
2015-12-03 11:08:09 -05:00
|
|
|
end
|
|
|
|
end
|
2013-04-03 02:26:38 -04:00
|
|
|
end
|