activestorage_upyun 0.4.0 → 0.7.0
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/README.md +7 -7
- data/lib/active_storage/service/upyun_service.rb +23 -12
- data/lib/activestorage_upyun/version.rb +1 -1
- data/lib/activestorage_upyun.rb +0 -2
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73c80de02ef4e126bb4978f584f6be1cae119ea3b94607038e60bda1f7dbad88
|
4
|
+
data.tar.gz: 816fe2ceb51be81919920ae6926f7507ebb5c70976ba5ff5dd4f3d481590cf4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aead81d0973f6f46576ad8320face4cfc9e873eaed9c37db440b4c36da670d3b05cd4f1aba1b8adb2b1ed27e7a36c2dff606b800bb21c65d540bf54bc4ef54d4
|
7
|
+
data.tar.gz: 9e2cbd7adeef15f92ffed4d6f8086a44003572487525ab0b406aed781b9ae9fa70c5e985e0854fd76f0155322d20c948df981549d33f54a70d550361623c1105
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ Upyun service for activestorage.
|
|
5
5
|
Add this line to your application's Gemfile:
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
gem 'activestorage_upyun'
|
8
|
+
gem 'activestorage_upyun', require: false
|
9
9
|
```
|
10
10
|
|
11
11
|
Set up upyun storage service in config/storage.yml:
|
@@ -13,9 +13,9 @@ Set up upyun storage service in config/storage.yml:
|
|
13
13
|
```yml
|
14
14
|
upyun:
|
15
15
|
service: Upyun
|
16
|
-
bucket: <%= ENV['
|
17
|
-
operator: <%= ENV['
|
18
|
-
password: <%= ENV['
|
16
|
+
bucket: <%= ENV['UPYUN_BUCKET'] %>
|
17
|
+
operator: <%= ENV['UPYUN_OPERATOR'] %>
|
18
|
+
password: <%= ENV['UPYUN_PASSWORD'] %>
|
19
19
|
host: <%= ENV['UPYUN_HOST'] %>
|
20
20
|
folder: <%= ENV['UPYUN_FOLDER'] %>
|
21
21
|
```
|
@@ -43,9 +43,9 @@ thumb version use `!` as default identifier, if you want to use `_` as identifie
|
|
43
43
|
```yml
|
44
44
|
upyun:
|
45
45
|
service: Upyun
|
46
|
-
bucket: <%= ENV['
|
47
|
-
operator: <%= ENV['
|
48
|
-
password: <%= ENV['
|
46
|
+
bucket: <%= ENV['UPYUN_BUCKET'] %>
|
47
|
+
operator: <%= ENV['UPYUN_OPERATOR'] %>
|
48
|
+
password: <%= ENV['UPYUN_PASSWORD'] %>
|
49
49
|
host: <%= ENV['UPYUN_HOST'] %>
|
50
50
|
folder: <%= ENV['UPYUN_FOLDER'] %>
|
51
51
|
identifier: _
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "upyun"
|
2
|
+
|
1
3
|
module ActiveStorage
|
2
4
|
# Wraps the upyun Storage Service as an Active Storage service.
|
3
5
|
# See ActiveStorage::Service for the generic API documentation that applies to all services.
|
@@ -7,9 +9,9 @@ module ActiveStorage
|
|
7
9
|
#
|
8
10
|
# upyun:
|
9
11
|
# service: Upyun
|
10
|
-
# bucket: <%= ENV['
|
11
|
-
# operator: <%= ENV['
|
12
|
-
# password: <%= ENV['
|
12
|
+
# bucket: <%= ENV['UPYUN_BUCKET'] %>
|
13
|
+
# operator: <%= ENV['UPYUN_OPERATOR'] %>
|
14
|
+
# password: <%= ENV['UPYUN_PASSWORD'] %>
|
13
15
|
# host: <%= ENV['UPYUN_HOST'] %>
|
14
16
|
# folder: <%= ENV['UPYUN_FOLDER'] %>
|
15
17
|
#
|
@@ -20,7 +22,7 @@ module ActiveStorage
|
|
20
22
|
#
|
21
23
|
#
|
22
24
|
class Service::UpyunService < Service
|
23
|
-
ENDPOINT = '
|
25
|
+
ENDPOINT = 'https://v0.api.upyun.com'
|
24
26
|
IDENTIFIER = '!'
|
25
27
|
|
26
28
|
attr_reader :upyun, :bucket, :operator, :password, :host, :folder, :upload_options
|
@@ -35,7 +37,7 @@ module ActiveStorage
|
|
35
37
|
@upyun = Upyun::Rest.new(bucket, operator, password, options)
|
36
38
|
end
|
37
39
|
|
38
|
-
def upload(key, io, checksum: nil)
|
40
|
+
def upload(key, io, checksum: nil, content_type: nil, disposition: nil, filename: nil, custom_metadata: {}, **)
|
39
41
|
instrument :upload, key: key, checksum: checksum do
|
40
42
|
begin
|
41
43
|
result = @upyun.put(path_for(key), io)
|
@@ -87,7 +89,7 @@ module ActiveStorage
|
|
87
89
|
end
|
88
90
|
end
|
89
91
|
|
90
|
-
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
|
92
|
+
def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:, custom_metadata: {})
|
91
93
|
instrument :url, key: key do |payload|
|
92
94
|
url = [ENDPOINT, @bucket , @folder, key].join('/')
|
93
95
|
payload[:url] = url
|
@@ -95,7 +97,7 @@ module ActiveStorage
|
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
98
|
-
def headers_for_direct_upload(key, content_type:, checksum:,
|
100
|
+
def headers_for_direct_upload(key, content_type:, checksum:, custom_metadata: {}, **)
|
99
101
|
user = @operator
|
100
102
|
pwd = md5(@password)
|
101
103
|
method = 'PUT'
|
@@ -107,13 +109,22 @@ module ActiveStorage
|
|
107
109
|
OpenSSL::HMAC.digest('sha1', pwd, str)
|
108
110
|
)
|
109
111
|
auth = "UPYUN #{@operator}:#{signature}"
|
110
|
-
{
|
112
|
+
{
|
113
|
+
"Content-Type" => content_type,
|
114
|
+
"Authorization" => auth,
|
115
|
+
"X-Date" => date,
|
116
|
+
**custom_metadata_headers(custom_metadata)
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
def custom_metadata_headers(metadata)
|
121
|
+
metadata.transform_keys { |key| "x-upyun-meta-#{key}" }
|
111
122
|
end
|
112
123
|
|
113
124
|
def delete_prefixed(prefix)
|
114
125
|
instrument :delete_prefixed, prefix: prefix do
|
115
126
|
items = @upyun.getlist "/#{@folder}/#{prefix}"
|
116
|
-
|
127
|
+
if items.is_a?(Array)
|
117
128
|
items.each do |file|
|
118
129
|
@upyun.delete("/#{@folder}/#{prefix}#{file[:name]}")
|
119
130
|
end
|
@@ -127,7 +138,7 @@ module ActiveStorage
|
|
127
138
|
def url_for(key, params: {})
|
128
139
|
url = [@host, @folder, key].join('/')
|
129
140
|
return url if params.blank?
|
130
|
-
process = params.
|
141
|
+
process = params.dig(:process)
|
131
142
|
identifier = @upload_options[:identifier] || IDENTIFIER
|
132
143
|
url = [url, process].join(identifier) if process
|
133
144
|
url
|
@@ -138,7 +149,7 @@ module ActiveStorage
|
|
138
149
|
end
|
139
150
|
|
140
151
|
def fullpath(path)
|
141
|
-
decoded =
|
152
|
+
decoded = CGI.escape(CGI.unescape(path.to_s.force_encoding('utf-8')))
|
142
153
|
decoded = decoded.gsub('[', '%5B').gsub(']', '%5D')
|
143
154
|
"/#{@bucket}#{decoded.start_with?('/') ? decoded : '/' + decoded}"
|
144
155
|
end
|
@@ -151,4 +162,4 @@ module ActiveStorage
|
|
151
162
|
Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
152
163
|
end
|
153
164
|
end
|
154
|
-
end
|
165
|
+
end
|
data/lib/activestorage_upyun.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activestorage_upyun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- doabit
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activestorage
|
@@ -98,7 +98,7 @@ homepage: https://github.com/doabit/activestorage_upyun
|
|
98
98
|
licenses:
|
99
99
|
- MIT
|
100
100
|
metadata: {}
|
101
|
-
post_install_message:
|
101
|
+
post_install_message:
|
102
102
|
rdoc_options: []
|
103
103
|
require_paths:
|
104
104
|
- lib
|
@@ -113,9 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
|
-
|
117
|
-
|
118
|
-
signing_key:
|
116
|
+
rubygems_version: 3.5.22
|
117
|
+
signing_key:
|
119
118
|
specification_version: 4
|
120
119
|
summary: Upyun service for activestorage
|
121
120
|
test_files: []
|