39 lines
726 B
Ruby
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
|