storage manager: add backblaze b2 backend.
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -46,6 +46,8 @@ gem 'builder'
|
|||||||
gem 'puma'
|
gem 'puma'
|
||||||
gem 'scenic'
|
gem 'scenic'
|
||||||
gem 'ipaddress'
|
gem 'ipaddress'
|
||||||
|
gem 'fog-core'
|
||||||
|
gem 'fog-backblaze', require: 'fog/backblaze'
|
||||||
|
|
||||||
# needed for looser jpeg header compat
|
# needed for looser jpeg header compat
|
||||||
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
||||||
|
|||||||
11
Gemfile.lock
11
Gemfile.lock
@@ -153,6 +153,7 @@ GEM
|
|||||||
railties (>= 3.2, < 6.1)
|
railties (>= 3.2, < 6.1)
|
||||||
equalizer (0.0.11)
|
equalizer (0.0.11)
|
||||||
erubi (1.9.0)
|
erubi (1.9.0)
|
||||||
|
excon (0.70.0)
|
||||||
factory_bot (5.1.1)
|
factory_bot (5.1.1)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
faraday (0.17.1)
|
faraday (0.17.1)
|
||||||
@@ -161,6 +162,14 @@ GEM
|
|||||||
ffi (1.11.3)
|
ffi (1.11.3)
|
||||||
ffi (1.11.3-x64-mingw32)
|
ffi (1.11.3-x64-mingw32)
|
||||||
flamegraph (0.9.5)
|
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)
|
get_process_mem (0.2.5)
|
||||||
ffi (~> 1.0)
|
ffi (~> 1.0)
|
||||||
globalid (0.4.2)
|
globalid (0.4.2)
|
||||||
@@ -444,6 +453,8 @@ DEPENDENCIES
|
|||||||
factory_bot
|
factory_bot
|
||||||
ffaker
|
ffaker
|
||||||
flamegraph
|
flamegraph
|
||||||
|
fog-backblaze
|
||||||
|
fog-core
|
||||||
httparty
|
httparty
|
||||||
ipaddress
|
ipaddress
|
||||||
jquery-rails
|
jquery-rails
|
||||||
|
|||||||
27
app/logical/storage_manager/cloud.rb
Normal file
27
app/logical/storage_manager/cloud.rb
Normal 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
|
||||||
Reference in New Issue
Block a user