Skip to content

Commit

Permalink
Re-add download? method to files_controller.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
euler-room committed Feb 27, 2025
1 parent c32ea88 commit 0f35e4d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apps/dashboard/app/controllers/files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ class FilesController < ApplicationController

def fs
request.format = 'json' if request.headers['HTTP_ACCEPT'].split(',').include?('application/json')
@is_download = fs_params[:download]
parse_path(fs_params[:filepath], fs_params[:fs])
validate_path!

if @path.directory?
@path.raise_if_cant_access_directory_contents

request.format = 'zip' if @is_download
request.format = 'zip' if download?

respond_to do |format|
format.html do
Expand Down Expand Up @@ -248,6 +247,10 @@ def posix_file?
@path.is_a?(PosixFile)
end

def download?
fs_params[:download]
end

def uppy_upload_path
# careful:
#
Expand Down Expand Up @@ -278,7 +281,7 @@ def send_posix_file
response.set_header 'Content-Length', @path.stat.size

# svgs aren't safe to view until we update our CSP
if @is_download || type.to_s == 'image/svg+xml'
if download? || type.to_s == 'image/svg+xml'
type = 'text/plain; charset=utf-8' if type.to_s == 'image/svg+xml'
send_file @path, type: type
else
Expand All @@ -287,7 +290,7 @@ def send_posix_file
rescue StandardError => e
logger.warn("failed to determine mime type for file: #{@path} due to error #{e.message}")

if @is_download
if download?
send_file @path
else
send_file @path, disposition: 'inline'
Expand All @@ -302,7 +305,7 @@ def send_remote_file
end

# svgs aren't safe to view until we update our CSP
download = @is_download || type.to_s == 'image/svg+xml'
download = download? || type.to_s == 'image/svg+xml'
type = 'text/plain; charset=utf-8' if type.to_s == 'image/svg+xml'

response.set_header('X-Accel-Buffering', 'no')
Expand Down

0 comments on commit 0f35e4d

Please sign in to comment.