mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-19 09:36:47 +10:00
Move the file serving to Raw controller, add a few ifs to view.
This commit is contained in:
@@ -17,7 +17,6 @@ class Projects::BlobController < Projects::ApplicationController
|
||||
before_action :require_branch_head, only: [:edit, :update]
|
||||
before_action :editor_variables, except: [:show, :preview, :diff]
|
||||
before_action :after_edit_path, only: [:edit, :update]
|
||||
before_action :show_lfs_object, only: :show
|
||||
|
||||
def new
|
||||
commit unless @repository.empty?
|
||||
@@ -194,20 +193,4 @@ class Projects::BlobController < Projects::ApplicationController
|
||||
file_content_encoding: params[:encoding]
|
||||
}
|
||||
end
|
||||
|
||||
def show_lfs_object
|
||||
return unless @blob && @blob.text? && @blob.data.present?
|
||||
|
||||
if @blob.data.starts_with?("version https://git-lfs.github.com/spec")
|
||||
oid = @blob.data.match(/#{LfsObject::MATCH_FROM_POINTER_REGEX}/)
|
||||
if oid && oid[1]
|
||||
lfs_object = LfsObject.find_by_oid(oid[1])
|
||||
return nil unless lfs_object && lfs_object.file.exists?
|
||||
|
||||
if lfs_object.projects.exists?(lfs_object.storage_project(@project).id)
|
||||
send_file lfs_object.file.path, filename: @blob.name, disposition: 'attachment'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,15 +10,13 @@ class Projects::RawController < Projects::ApplicationController
|
||||
@blob = @repository.blob_at(@commit.id, @path)
|
||||
|
||||
if @blob
|
||||
type = get_blob_type
|
||||
|
||||
headers['X-Content-Type-Options'] = 'nosniff'
|
||||
|
||||
send_data(
|
||||
@blob.data,
|
||||
type: type,
|
||||
disposition: 'inline'
|
||||
)
|
||||
if @blob.lfs_pointer?
|
||||
send_lfs_object
|
||||
else
|
||||
stream_data
|
||||
end
|
||||
else
|
||||
render_404
|
||||
end
|
||||
@@ -35,4 +33,23 @@ class Projects::RawController < Projects::ApplicationController
|
||||
'application/octet-stream'
|
||||
end
|
||||
end
|
||||
|
||||
def stream_data
|
||||
type = get_blob_type
|
||||
|
||||
send_data(
|
||||
@blob.data,
|
||||
type: type,
|
||||
disposition: 'inline'
|
||||
)
|
||||
end
|
||||
|
||||
def send_lfs_object
|
||||
lfs_object = LfsObject.find_by_oid(@blob.lfs_oid)
|
||||
return nil unless lfs_object && lfs_object.file.exists?
|
||||
|
||||
if lfs_object.projects.exists?(lfs_object.storage_project(@project).id)
|
||||
send_file lfs_object.file.path, filename: @blob.name, disposition: 'attachment'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
.btn-group.tree-btn-group
|
||||
= edit_blob_link(@project, @ref, @path)
|
||||
= edit_blob_link(@project, @ref, @path) unless @blob.lfs_pointer?
|
||||
= link_to 'Raw', namespace_project_raw_path(@project.namespace, @project, @id),
|
||||
class: 'btn btn-sm', target: '_blank'
|
||||
-# only show normal/blame view links for text files
|
||||
- if @blob.text?
|
||||
- if @blob.text? && !@blob.lfs_pointer?
|
||||
- if current_page? namespace_project_blame_path(@project.namespace, @project, @id)
|
||||
= link_to 'Normal View', namespace_project_blob_path(@project.namespace, @project, @id),
|
||||
class: 'btn btn-sm'
|
||||
@@ -16,7 +16,7 @@
|
||||
= link_to 'Permalink', namespace_project_blob_path(@project.namespace, @project,
|
||||
tree_join(@commit.sha, @path)), class: 'btn btn-sm'
|
||||
|
||||
- if allowed_tree_edit?
|
||||
- if allowed_tree_edit? && !@blob.lfs_pointer?
|
||||
.btn-group{ role: "group" }
|
||||
%button.btn.btn-default{ 'data-target' => '#modal-upload-blob', 'data-toggle' => 'modal' } Replace
|
||||
%button.btn.btn-remove{ 'data-target' => '#modal-remove-blob', 'data-toggle' => 'modal' } Delete
|
||||
|
||||
@@ -29,10 +29,12 @@
|
||||
%strong
|
||||
= blob.name
|
||||
%small
|
||||
= number_to_human_size(blob.size)
|
||||
= number_to_human_size(blob.size) unless blob.lfs_pointer?
|
||||
.file-actions.hidden-xs
|
||||
= render "actions"
|
||||
- if blob.text?
|
||||
- if blob.lfs_pointer?
|
||||
= render "download", blob: blob
|
||||
- elsif blob.text?
|
||||
= render "text", blob: blob
|
||||
- elsif blob.image?
|
||||
= render "image", blob: blob
|
||||
|
||||
@@ -4,4 +4,8 @@
|
||||
%h1.light
|
||||
%i.fa.fa-download
|
||||
%h4
|
||||
Download (#{number_to_human_size blob.size})
|
||||
- if blob.lfs_pointer?
|
||||
- size = blob.lfs_size
|
||||
- else
|
||||
- size = blob.size
|
||||
Download (#{number_to_human_size size})
|
||||
|
||||
Reference in New Issue
Block a user