active_storage_bunny 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/active_storage/service/bunny_service.rb +100 -0
- data/lib/active_storage_bunny/version.rb +3 -0
- data/lib/active_storage_bunny.rb +7 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 74d8ca0414380a8f138a9eb2f3f5d7cb4c4f9aac29c6e2aae5dace40532bd689
|
4
|
+
data.tar.gz: 45e0cb4b9be82b4bb3228792481dd5a8734bcde61e3941841d88bcadb6e808fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1362ce11eb5dc5022c037547724b6f230fc5b9fab0857ba258ff1a5dbf52a6a11625d12df5dfe2956326b7d77340737bffd969cfb55f5902be5b981929fd1133
|
7
|
+
data.tar.gz: 007041caf3ab0f9b3e42787df1be4344acb2ee045631295fe8a9b3c8129e6d45b61d80d4f910528bf0befce53e16db4232ccc2056722febde6dd1992a553c800
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/numeric/bytes'
|
4
|
+
require 'bunny_storage_client'
|
5
|
+
|
6
|
+
module ActiveStorage
|
7
|
+
# Wraps the Amazon Simple Storage Service (S3) as an Active Storage service.
|
8
|
+
# See ActiveStorage::Service for the generic API documentation that applies to all services.
|
9
|
+
class Service::BunnyService < Service
|
10
|
+
|
11
|
+
CDN_BASE_URL = "https://#{ENV['BUNNY_STORAGE_ZONE']}.b-cdn.net"
|
12
|
+
|
13
|
+
attr_reader :client
|
14
|
+
|
15
|
+
def initialize(access_key:, api_key:, storage_zone:, **options)
|
16
|
+
@client = BunnyStorageClient.new(access_key, api_key, storage_zone)
|
17
|
+
super(**options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def upload(key, io, checksum: nil, filename: nil, content_type: nil, disposition: nil, custom_metadata: {}, **)
|
21
|
+
instrument :upload, key: key, checksum: checksum do
|
22
|
+
content_disposition = content_disposition_with(filename: filename, type: disposition) if disposition && filename
|
23
|
+
upload_with_single_part key, io, checksum: checksum, content_type: content_type, content_disposition: content_disposition, custom_metadata: custom_metadata
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def download(key, &block)
|
28
|
+
instrument :download, key: key do
|
29
|
+
object_for(key).get_file.to_s.force_encoding(Encoding::BINARY)
|
30
|
+
rescue StandardError
|
31
|
+
raise ActiveStorage::FileNotFoundError
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(key)
|
36
|
+
instrument :delete, key: key do
|
37
|
+
object_for(key).delete_file
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_prefixed(prefix)
|
42
|
+
instrument :delete_prefixed, prefix: prefix do
|
43
|
+
# BunnyStorageClient does not natively support this operation yet.
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def exist?(key)
|
49
|
+
instrument :exist, key: key do |payload|
|
50
|
+
answer = object_for(key).exists?
|
51
|
+
payload[:exist] = answer
|
52
|
+
answer
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:, custom_metadata: {})
|
57
|
+
instrument :url, key: key do |payload|
|
58
|
+
generated_url = object_for(key).presigned_url :put, expires_in: expires_in.to_i,
|
59
|
+
content_type: content_type, content_length: content_length, content_md5: checksum,
|
60
|
+
metadata: custom_metadata, whitelist_headers: ['content-length'], **upload_options
|
61
|
+
|
62
|
+
payload[:url] = generated_url
|
63
|
+
|
64
|
+
generated_url
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def headers_for_direct_upload(key, content_type:, checksum:, filename: nil, disposition: nil, custom_metadata: {}, **)
|
69
|
+
content_disposition = content_disposition_with(type: disposition, filename: filename) if filename
|
70
|
+
|
71
|
+
{ 'Content-Type' => content_type, 'Content-MD5' => checksum, 'Content-Disposition' => content_disposition, **custom_metadata_headers(custom_metadata) }
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def private_url(key, expires_in:, filename:, disposition:, content_type:, **)
|
77
|
+
# BunnyStorageClient does not natively support this operation yet.
|
78
|
+
public_url(key)
|
79
|
+
end
|
80
|
+
|
81
|
+
def public_url(key)
|
82
|
+
File.join(CDN_BASE_URL, key)
|
83
|
+
end
|
84
|
+
|
85
|
+
def upload_with_single_part(key, io, checksum: nil, content_type: nil, content_disposition: nil, custom_metadata: {})
|
86
|
+
object_for(key).upload_file(body: io)
|
87
|
+
object_for(key).purge_cache
|
88
|
+
rescue StandardError
|
89
|
+
raise ActiveStorage::IntegrityError
|
90
|
+
end
|
91
|
+
|
92
|
+
def stream_file(key)
|
93
|
+
# BunnyStorageClient does not natively support this operation yet.
|
94
|
+
end
|
95
|
+
|
96
|
+
def object_for(key)
|
97
|
+
client.object(key)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_storage_bunny
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ramit Koul
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bunny_storage_client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '6.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '8.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '6.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '8.0'
|
47
|
+
description: ActiveStorageBunny is a gem that integrates BunnyCDN storage services
|
48
|
+
with Active Storage.
|
49
|
+
email:
|
50
|
+
- ramitkaul@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- lib/active_storage/service/bunny_service.rb
|
56
|
+
- lib/active_storage_bunny.rb
|
57
|
+
- lib/active_storage_bunny/version.rb
|
58
|
+
homepage: https://github.com/rkwap/active_storage_bunny
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata:
|
62
|
+
homepage_uri: https://github.com/rkwap/active_storage_bunny
|
63
|
+
source_code_uri: https://github.com/rkwap/active_storage_bunny
|
64
|
+
changelog_uri: https://github.com/rkwap/active_storage_bunny/CHANGELOG.md
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '2.5'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubygems_version: 3.2.33
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: An Active Storage service for BunnyCDN storage services.
|
84
|
+
test_files: []
|