SubmissionsController: Send Content-Length if possible
This commit is contained in:
@ -54,7 +54,9 @@ class SubmissionsController < ApplicationController
|
|||||||
zio.write(File.read(File.join(scripts_path, file)))
|
zio.write(File.read(File.join(scripts_path, file)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
send_data(stringio.string, filename: "#{@submission.exercise.title.tr(' ', '_')}.zip")
|
zip_data = stringio.string
|
||||||
|
response.set_header('Content-Length', zip_data.size)
|
||||||
|
send_data(zip_data, filename: "#{@submission.exercise.title.tr(' ', '_')}.zip")
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_file
|
def download_file
|
||||||
@ -63,6 +65,7 @@ class SubmissionsController < ApplicationController
|
|||||||
if @file.native_file?
|
if @file.native_file?
|
||||||
redirect_to protected_upload_path(id: @file.id, filename: @file.filepath)
|
redirect_to protected_upload_path(id: @file.id, filename: @file.filepath)
|
||||||
else
|
else
|
||||||
|
response.set_header('Content-Length', @file.size)
|
||||||
send_data(@file.content, filename: @file.name_with_extension, disposition: 'attachment')
|
send_data(@file.content, filename: @file.name_with_extension, disposition: 'attachment')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -93,6 +96,7 @@ class SubmissionsController < ApplicationController
|
|||||||
url = render_protected_upload_url(id: @file.id, filename: @file.filepath)
|
url = render_protected_upload_url(id: @file.id, filename: @file.filepath)
|
||||||
redirect_to AuthenticatedUrlHelper.sign(url, @file)
|
redirect_to AuthenticatedUrlHelper.sign(url, @file)
|
||||||
else
|
else
|
||||||
|
response.set_header('Content-Length', @file.size)
|
||||||
send_data(@file.content, filename: @file.name_with_extension, disposition: 'inline')
|
send_data(@file.content, filename: @file.name_with_extension, disposition: 'inline')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -17,6 +17,8 @@ module CodeOcean
|
|||||||
before_validation :hash_content, if: :content_present?
|
before_validation :hash_content, if: :content_present?
|
||||||
before_validation :set_ancestor_values, if: :incomplete_descendent?
|
before_validation :set_ancestor_values, if: :incomplete_descendent?
|
||||||
|
|
||||||
|
attr_writer :size
|
||||||
|
|
||||||
belongs_to :context, polymorphic: true
|
belongs_to :context, polymorphic: true
|
||||||
belongs_to :file, class_name: 'CodeOcean::File', optional: true # This is only required for submissions and is validated below
|
belongs_to :file, class_name: 'CodeOcean::File', optional: true # This is only required for submissions and is validated below
|
||||||
alias ancestor file
|
alias ancestor file
|
||||||
@ -128,5 +130,13 @@ module CodeOcean
|
|||||||
def visible
|
def visible
|
||||||
!hidden
|
!hidden
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def size
|
||||||
|
@size ||= if native_file?
|
||||||
|
native_file.size
|
||||||
|
else
|
||||||
|
content.size
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user