activestorage_upyun 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed799a10214b73035941a3cd3ce0df53715424118f5f92631f971da783776b14
4
- data.tar.gz: 3ed031623b3be001835849dd329db0833fa996f73e110b47a10f55ee85c54372
3
+ metadata.gz: 73c80de02ef4e126bb4978f584f6be1cae119ea3b94607038e60bda1f7dbad88
4
+ data.tar.gz: 816fe2ceb51be81919920ae6926f7507ebb5c70976ba5ff5dd4f3d481590cf4f
5
5
  SHA512:
6
- metadata.gz: ca715bd2e7f87244f2e537c4a732cafd0c802cc0cb5690ebab6853956ffefc213ae7600c21e9361b677b6a1f214bcafb7674ef28f0774c414bdfd31e803fd3e5
7
- data.tar.gz: b74928ab2c6d61b7b0e6e14150189f4d71fcaa7fb821d1cb9b3e94353b98d59a7d51c19988eaa732f9c1a3bea020beb0f33f432144a974bc64a5f6a3a13c8585
6
+ metadata.gz: aead81d0973f6f46576ad8320face4cfc9e873eaed9c37db440b4c36da670d3b05cd4f1aba1b8adb2b1ed27e7a36c2dff606b800bb21c65d540bf54bc4ef54d4
7
+ data.tar.gz: 9e2cbd7adeef15f92ffed4d6f8086a44003572487525ab0b406aed781b9ae9fa70c5e985e0854fd76f0155322d20c948df981549d33f54a70d550361623c1105
@@ -37,7 +37,7 @@ module ActiveStorage
37
37
  @upyun = Upyun::Rest.new(bucket, operator, password, options)
38
38
  end
39
39
 
40
- def upload(key, io, checksum: nil, content_type: nil, disposition: nil, filename: nil)
40
+ def upload(key, io, checksum: nil, content_type: nil, disposition: nil, filename: nil, custom_metadata: {}, **)
41
41
  instrument :upload, key: key, checksum: checksum do
42
42
  begin
43
43
  result = @upyun.put(path_for(key), io)
@@ -89,7 +89,7 @@ module ActiveStorage
89
89
  end
90
90
  end
91
91
 
92
- 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: {})
93
93
  instrument :url, key: key do |payload|
94
94
  url = [ENDPOINT, @bucket , @folder, key].join('/')
95
95
  payload[:url] = url
@@ -97,7 +97,7 @@ module ActiveStorage
97
97
  end
98
98
  end
99
99
 
100
- def headers_for_direct_upload(key, content_type:, checksum:, content_length:, **)
100
+ def headers_for_direct_upload(key, content_type:, checksum:, custom_metadata: {}, **)
101
101
  user = @operator
102
102
  pwd = md5(@password)
103
103
  method = 'PUT'
@@ -109,13 +109,22 @@ module ActiveStorage
109
109
  OpenSSL::HMAC.digest('sha1', pwd, str)
110
110
  )
111
111
  auth = "UPYUN #{@operator}:#{signature}"
112
- {"Content-Type" => content_type, "Authorization" => auth, "X-Date" => date}
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}" }
113
122
  end
114
123
 
115
124
  def delete_prefixed(prefix)
116
125
  instrument :delete_prefixed, prefix: prefix do
117
126
  items = @upyun.getlist "/#{@folder}/#{prefix}"
118
- unless items[:error]
127
+ if items.is_a?(Array)
119
128
  items.each do |file|
120
129
  @upyun.delete("/#{@folder}/#{prefix}#{file[:name]}")
121
130
  end
@@ -129,7 +138,7 @@ module ActiveStorage
129
138
  def url_for(key, params: {})
130
139
  url = [@host, @folder, key].join('/')
131
140
  return url if params.blank?
132
- process = params.delete(:process)
141
+ process = params.dig(:process)
133
142
  identifier = @upload_options[:identifier] || IDENTIFIER
134
143
  url = [url, process].join(identifier) if process
135
144
  url
@@ -140,7 +149,7 @@ module ActiveStorage
140
149
  end
141
150
 
142
151
  def fullpath(path)
143
- decoded = URI::encode(URI::decode(path.to_s.force_encoding('utf-8')))
152
+ decoded = CGI.escape(CGI.unescape(path.to_s.force_encoding('utf-8')))
144
153
  decoded = decoded.gsub('[', '%5B').gsub(']', '%5D')
145
154
  "/#{@bucket}#{decoded.start_with?('/') ? decoded : '/' + decoded}"
146
155
  end
@@ -1,3 +1,3 @@
1
1
  module ActivestorageUpyun
2
- VERSION = '0.5.0'
2
+ VERSION = '0.7.0'
3
3
  end
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.5.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: 2018-12-14 00:00:00.000000000 Z
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
- rubyforge_project:
117
- rubygems_version: 2.7.4
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: []