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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a1a49cc2be589a8801185a27f87bfcab3fbf97299f1075d48d9bbba213ee68b
4
- data.tar.gz: f19761541aef40916fab6b03cce9fdde46d9e56eceefb0a581421432fd16ecf5
3
+ metadata.gz: 73c80de02ef4e126bb4978f584f6be1cae119ea3b94607038e60bda1f7dbad88
4
+ data.tar.gz: 816fe2ceb51be81919920ae6926f7507ebb5c70976ba5ff5dd4f3d481590cf4f
5
5
  SHA512:
6
- metadata.gz: 34bcc7fb8348dac77d6efb4e0b8b7197725efa56594f518bd0bdb43e44178497c6d166b04c1df5983276b96c0cb529bfe81dbb8d4db7175c155fdf533ff61083
7
- data.tar.gz: 330afc7754b0a809e3f1c1bb32aa4a9b2a2ed8d56fa57c3f078e2e92faf32ce20c02ea3c67f48b80a281420fe2ea11af522eccfb75e5fdbde079fbef6102c029
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['UPYUUN_BUCKET'] %>
17
- operator: <%= ENV['UPYUUN_OPERATOR'] %>
18
- password: <%= ENV['UPYUUN_PASSWORD'] %>
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['UPYUUN_BUCKET'] %>
47
- operator: <%= ENV['UPYUUN_OPERATOR'] %>
48
- password: <%= ENV['UPYUUN_PASSWORD'] %>
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['UPYUUN_BUCKET'] %>
11
- # operator: <%= ENV['UPYUUN_OPERATOR'] %>
12
- # password: <%= ENV['UPYUUN_PASSWORD'] %>
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 = 'http://v0.api.upyun.com'
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:, content_length:, **)
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
- {"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}" }
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
- unless items[:error]
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.delete(:process)
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 = URI::encode(URI::decode(path.to_s.force_encoding('utf-8')))
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
@@ -1,3 +1,3 @@
1
1
  module ActivestorageUpyun
2
- VERSION = '0.4.0'
2
+ VERSION = '0.7.0'
3
3
  end
@@ -1,6 +1,4 @@
1
- require "upyun"
2
1
  require "activestorage_upyun/version"
3
2
  require 'active_storage/service/upyun_service'
4
3
  module ActivestorageUpyun
5
- # Your code goes here...
6
4
  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.4.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-05-29 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: []