Websites/app/logical/storage_manager/local.rb

39 lines
726 B
Ruby
Raw Normal View History

2024-05-03 03:04:43 +00:00
# frozen_string_literal: true
module StorageManager
class Local
attr_reader :base_url, :base_path
def initialize(base_url:, base_path:)
@base_url = base_url
@base_path = base_path
end
def delete(path)
return unless exists?(path)
File.delete("#{base_path}/#{path}")
end
def exists?(path)
File.exist?("#{base_path}/#{path}")
end
def get(path)
File.read("#{base_path}/#{path}")
end
def put(path, body)
File.write("#{base_path}/#{path}", body)
end
def upload(path, body)
put(path, body)
"#{base_url}/#{path}"
end
def url_for(entry)
"#{base_url}/#{entry.stripped_md5}.#{entry.filetype}"
end
end
end