cartodb-4.42/lib/carto/storage_options/local.rb

27 lines
656 B
Ruby
Raw Normal View History

2024-04-06 13:25:13 +08:00
class Carto::StorageOptions::Local
include Carto::Configuration
def initialize(location)
@location = location
end
def upload(path, file)
filename = Pathname.new(file.path).basename
target_directory = File.join(public_uploaded_assets_path,
@location,
path)
FileUtils.mkdir_p(target_directory)
FileUtils.mv(file.path, target_directory)
identifier = File.join(target_directory, filename)
url = File.join('/uploads', @location, path, filename)
[identifier, url]
end
def remove(path)
File.delete(path) if path && File.exist?(path)
end
end