You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
529 B
27 lines
529 B
2 years ago
|
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
|