storage manager: add backblaze b2 backend.

This commit is contained in:
evazion
2019-12-10 02:04:32 -06:00
parent 6b165a90f8
commit e4f4326982
3 changed files with 40 additions and 0 deletions

View File

@@ -46,6 +46,8 @@ gem 'builder'
gem 'puma'
gem 'scenic'
gem 'ipaddress'
gem 'fog-core'
gem 'fog-backblaze', require: 'fog/backblaze'
# needed for looser jpeg header compat
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"

View File

@@ -153,6 +153,7 @@ GEM
railties (>= 3.2, < 6.1)
equalizer (0.0.11)
erubi (1.9.0)
excon (0.70.0)
factory_bot (5.1.1)
activesupport (>= 4.2.0)
faraday (0.17.1)
@@ -161,6 +162,14 @@ GEM
ffi (1.11.3)
ffi (1.11.3-x64-mingw32)
flamegraph (0.9.5)
fog-backblaze (0.3.0)
fog-core (>= 1.40, < 3)
fog-core (2.1.2)
builder
excon (~> 0.58)
formatador (~> 0.2)
mime-types
formatador (0.2.5)
get_process_mem (0.2.5)
ffi (~> 1.0)
globalid (0.4.2)
@@ -444,6 +453,8 @@ DEPENDENCIES
factory_bot
ffaker
flamegraph
fog-backblaze
fog-core
httparty
ipaddress
jquery-rails

View File

@@ -0,0 +1,27 @@
class StorageManager::Cloud < StorageManager
attr_reader :bucket, :client, :fog_options
def initialize(bucket, client: nil, fog_options: {}, **options)
@bucket = bucket
@fog_options = fog_options
@client = client || Fog::Storage.new(**fog_options)
super(**options)
end
def store(io, path)
data = io.read
client.put_object(bucket, path, data)
end
def delete(path)
client.delete_object(bucket, path)
end
def open(path)
file = Tempfile.new(binmode: true)
response = client.get_object(bucket, path)
file.write(response.body)
file.rewind
file
end
end