Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-enable ActionController::Live #3441

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/dashboard/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ gem 'mocha', '~> 2.1', group: :test
gem 'autoprefixer-rails', '~> 10.2.5'
gem 'dotiw'
gem 'local_time', '~> 1.0.3'
gem 'zip_tricks', '~> 5.5'
gem 'zip_kit', '~> 6.2'
gem 'rss', '~> 0.2'

gem 'jsbundling-rails', '~> 1.0'
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ GEM
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.13)
zip_tricks (5.6.0)
zip_kit (6.2.0)

PLATFORMS
ruby
Expand Down Expand Up @@ -315,7 +315,7 @@ DEPENDENCIES
sprockets-rails (>= 2.0.0)
timecop (~> 0.9)
webrick
zip_tricks (~> 5.5)
zip_kit (~> 6.2)

BUNDLED WITH
2.3.6
33 changes: 18 additions & 15 deletions apps/dashboard/app/controllers/files_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The controller for all the files pages /dashboard/files
class FilesController < ApplicationController
include ZipTricks::RailsStreaming
include ActionController::Live

before_action :strip_sendfile_headers, only: [:fs]

Expand Down Expand Up @@ -58,22 +58,25 @@ def fs
response.sending_file = true
response.cache_control[:public] ||= false

# FIXME: strategy 1: is below, use zip_tricks
# strategy 2: use actual zip command (likely much faster) and ActionController::Live
zip_tricks_stream do |zip|
@path.files_to_zip.each do |file|
begin
next unless File.readable?(file.realpath)

if File.file?(file.realpath)
zip.write_deflated_file(file.relative_path.to_s) do |zip_file|
IO.copy_stream(file.realpath, zip_file)
zip_headers = ZipKit::OutputEnumerator.new.streaming_http_headers
response.headers.merge!(zip_headers)

send_stream(filename: zipname) do |stream|
ZipKit::Streamer.open(stream) do |zip|
@path.files_to_zip.each do |file|
begin
next unless File.readable?(file.realpath)

if File.file?(file.realpath)
zip.write_deflated_file(file.relative_path.to_s) do |zip_file|
IO.copy_stream(file.realpath, zip_file)
end
else
zip.add_empty_directory(dirname: file.relative_path.to_s)
end
else
zip.add_empty_directory(dirname: file.relative_path.to_s)
rescue => e
logger.warn("error writing file #{file.path} to zip: #{e.message}")
end
rescue => e
logger.warn("error writing file #{file.path} to zip: #{e.message}")
end
end
end
Expand Down
Loading