active_storage_bunny 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/active_storage/service/bunny_service.rb +43 -18
- data/lib/active_storage_bunny/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3a4228b63965eea285975f7afabeeac6e9bb2f3bde3f24638c2d6e662ace50b
|
4
|
+
data.tar.gz: eee8cd70a77ef6b5eb1d6cdc12f294d45f54f051ca3b344cb48148cf8e03fac0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46100469320d9f53dfff19edcee376fdede6fbffe42a6662df4913133fea5ebd232af76b670c92910f402fc474addecc27a24dcca3e6ce347f0501ce1a7eb9eb
|
7
|
+
data.tar.gz: 5b38882608dfc9636ea0ad89dd5345ca1cc6f9c0b06ee581e146cf295e0a4041ea8d1d30f0f4411b845fba782ce3e239c06a037bb45dc7430f3cf3362ef79dd0
|
@@ -4,17 +4,20 @@ require 'active_support/core_ext/numeric/bytes'
|
|
4
4
|
require 'bunny_storage_client'
|
5
5
|
|
6
6
|
module ActiveStorage
|
7
|
-
# Wraps the
|
7
|
+
# Wraps the BunnyCDN Storage as an Active Storage service.
|
8
8
|
# See ActiveStorage::Service for the generic API documentation that applies to all services.
|
9
9
|
class Service::BunnyService < Service
|
10
10
|
|
11
|
-
|
11
|
+
attr_reader :client, :base_url
|
12
12
|
|
13
|
-
|
13
|
+
def initialize(access_key:, api_key:, storage_zone:, region:, cdn: false)
|
14
|
+
@client = BunnyStorageClient.new(access_key, api_key, storage_zone, region)
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
if cdn
|
17
|
+
@base_url = cdn
|
18
|
+
else
|
19
|
+
@base_url = "https://#{storage_zone}.b-cdn.net"
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
23
|
def upload(key, io, checksum: nil, filename: nil, content_type: nil, disposition: nil, custom_metadata: {}, **)
|
@@ -25,10 +28,16 @@ module ActiveStorage
|
|
25
28
|
end
|
26
29
|
|
27
30
|
def download(key, &block)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
if block_given?
|
32
|
+
instrument :streaming_download, { key: key } do
|
33
|
+
stream(key, &block)
|
34
|
+
end
|
35
|
+
else
|
36
|
+
instrument :download, key: key do
|
37
|
+
io = StringIO.new object_for(key).get_file
|
38
|
+
|
39
|
+
io.set_encoding(Encoding::BINARY)
|
40
|
+
end
|
32
41
|
end
|
33
42
|
end
|
34
43
|
|
@@ -39,20 +48,29 @@ module ActiveStorage
|
|
39
48
|
end
|
40
49
|
|
41
50
|
def delete_prefixed(prefix)
|
42
|
-
|
43
|
-
|
44
|
-
|
51
|
+
delete prefix
|
52
|
+
# instrument :delete_prefixed, prefix: prefix do
|
53
|
+
# # BunnyStorageClient does not natively support this operation yet.
|
54
|
+
# end
|
45
55
|
end
|
46
56
|
|
47
|
-
|
48
57
|
def exist?(key)
|
49
58
|
instrument :exist, key: key do |payload|
|
50
|
-
answer = object_for(key).
|
59
|
+
answer = object_for(key).exist?
|
51
60
|
payload[:exist] = answer
|
52
61
|
answer
|
53
62
|
end
|
54
63
|
end
|
55
64
|
|
65
|
+
def url(key, expires_in:, disposition:, filename:, **options)
|
66
|
+
instrument :url, {key: key} do |payload|
|
67
|
+
url = public_url key
|
68
|
+
payload[:url] = url
|
69
|
+
|
70
|
+
url
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
56
74
|
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:, custom_metadata: {})
|
57
75
|
instrument :url, key: key do |payload|
|
58
76
|
generated_url = object_for(key).presigned_url :put, expires_in: expires_in.to_i,
|
@@ -79,7 +97,7 @@ module ActiveStorage
|
|
79
97
|
end
|
80
98
|
|
81
99
|
def public_url(key)
|
82
|
-
File.join(
|
100
|
+
File.join(base_url, key)
|
83
101
|
end
|
84
102
|
|
85
103
|
def upload_with_single_part(key, io, checksum: nil, content_type: nil, content_disposition: nil, custom_metadata: {})
|
@@ -89,8 +107,15 @@ module ActiveStorage
|
|
89
107
|
raise ActiveStorage::IntegrityError
|
90
108
|
end
|
91
109
|
|
92
|
-
def
|
93
|
-
|
110
|
+
def stream(key, options = {}, &block)
|
111
|
+
io = StringIO.new object_for(key).get_file
|
112
|
+
io.set_encoding(Encoding::BINARY)
|
113
|
+
|
114
|
+
chunk_size = 5.megabytes
|
115
|
+
|
116
|
+
while chunk = io.read(chunk_size)
|
117
|
+
yield chunk
|
118
|
+
end
|
94
119
|
end
|
95
120
|
|
96
121
|
def object_for(key)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_storage_bunny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ramit Koul
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny_storage_client
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '6.0'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '9.0'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '6.0'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '9.0'
|
47
47
|
description: ActiveStorageBunny is a gem that integrates BunnyCDN storage services
|
48
48
|
with Active Storage.
|
49
49
|
email:
|