Browse Source

use local disk for bulk upload for dev env

- this saves the need to connect to S3 to play with bulk upload in dev
  environment
pull/1091/head
Phil Lee 3 years ago
parent
commit
fb930d952e
  1. 13
      app/models/forms/bulk_upload_lettings/upload_your_file.rb
  2. 14
      app/services/bulk_upload/downloader.rb
  3. 26
      app/services/storage/local_disk_service.rb

13
app/models/forms/bulk_upload_lettings/upload_your_file.rb

@ -41,9 +41,7 @@ module Forms
filename: file.original_filename,
)
if upload_enabled?
storage_service.write_file(bulk_upload.identifier, File.read(file.path))
end
storage_service.write_file(bulk_upload.identifier, File.read(file.path))
true
end
@ -55,7 +53,14 @@ module Forms
end
def storage_service
@storage_service ||= Storage::S3Service.new(Configuration::PaasConfigurationService.new, ENV["CSV_DOWNLOAD_PAAS_INSTANCE"])
@storage_service ||= if upload_enabled?
Storage::S3Service.new(
Configuration::PaasConfigurationService.new,
ENV["CSV_DOWNLOAD_PAAS_INSTANCE"],
)
else
Storage::LocalDiskService.new
end
end
def validate_file_is_csv

14
app/services/bulk_upload/downloader.rb

@ -25,9 +25,21 @@ private
end
def storage_service
@storage_service ||= Storage::S3Service.new(
@storage_service ||= if FeatureToggle.upload_enabled?
s3_storage_service
else
local_disk_storage_service
end
end
def s3_storage_service
Storage::S3Service.new(
Configuration::PaasConfigurationService.new,
ENV["CSV_DOWNLOAD_PAAS_INSTANCE"],
)
end
def local_disk_storage_service
Storage::LocalDiskService.new
end
end

26
app/services/storage/local_disk_service.rb

@ -0,0 +1,26 @@
require "fileutils"
module Storage
class LocalDiskService < StorageService
def list_files(folder = "/")
path = Rails.root.join("tmp/storage", folder)
Dir.entries(path)
end
def get_file_io(filename)
path = Rails.root.join("tmp/storage", filename)
File.open(path, "r")
end
def write_file(filename, data)
path = Rails.root.join("tmp/storage", filename)
FileUtils.mkdir_p(path.dirname)
File.open(path, "w") do |f|
f.write data
end
end
end
end
Loading…
Cancel
Save