Skip to content

Commit

Permalink
Remove clean? ambiguity from FileUploader
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-l-brockwell committed Nov 20, 2024
1 parent 4e10c15 commit a1c590c
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions app/uploaders/file_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ class FileUploader < CarrierWave::Uploader::Base
storage :custom

def store_dir
base_dir = (model.respond_to?(:clean?) && model.clean?) ? "permanent" : "tmp"
"uploads/#{base_dir}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

def read
if model.respond_to?(:clean?) && model.clean?
read_from_permanent_storage
else
super
end
clean? ? read_from_permanent_storage : super
end

def extension_allowlist
Expand All @@ -26,19 +21,11 @@ def filename
end

def fog_credentials
if fog_directory.include?("clean")
clean_bucket_credentials
else
tmp_bucket_credentials
end
clean? ? clean_bucket_credentials : tmp_bucket_credentials
end

def fog_directory
if model.respond_to?(:clean?) && model.clean?
ENV["AWS_S3_PERMANENT_BUCKET"]
else
ENV["AWS_S3_TMP_BUCKET"]
end
clean? ? ENV["AWS_S3_PERMANENT_BUCKET"] : ENV["AWS_S3_TMP_BUCKET"]
end

def permanent_path
Expand All @@ -47,6 +34,14 @@ def permanent_path

private

def base_dir
clean? ? "permanent" : "tmp"
end

def clean?
model.respond_to?(:clean?) && model.clean?
end

def read_from_permanent_storage
if Rails.env.production? || ENV["ENABLE_VIRUS_SCANNER_BUCKETS"] == "true"
permanent_file = CarrierWave::Storage::Fog::File.new(self, permanent_storage, store_path)
Expand Down

0 comments on commit a1c590c

Please sign in to comment.