Websites/app/logical/storage_manager/local.rb
2024-05-02 22:04:43 -05:00

39 lines
726 B
Ruby

# 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