diff options
author | Marin Jankovski <maxlazio@gmail.com> | 2015-12-03 19:08:09 +0300 |
---|---|---|
committer | Marin Jankovski <maxlazio@gmail.com> | 2015-12-03 19:08:09 +0300 |
commit | ea52a81da4888af232e9868d722cc91d5e442723 (patch) | |
tree | 65630bc426524d8ee876199e99535695cce248e9 /app/controllers/projects/raw_controller.rb | |
parent | 0a081e7eff9730beebd4bea1eb40873d907b6293 (diff) |
Move the file serving to Raw controller, add a few ifs to view.
Diffstat (limited to 'app/controllers/projects/raw_controller.rb')
-rw-r--r-- | app/controllers/projects/raw_controller.rb | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/app/controllers/projects/raw_controller.rb b/app/controllers/projects/raw_controller.rb index d5ee6ac8663..c56f432a1f1 100644 --- a/app/controllers/projects/raw_controller.rb +++ b/app/controllers/projects/raw_controller.rb @@ -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 |