activestorage-aliyun 0.6.4 → 1.0.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: bed55a80edfa6cea56565fecdbfc7c3bad58d2516981dd352c4f944e3fc4f79c
4
- data.tar.gz: 9be8033111a8ac4292ba371bdf56858d15344dee07b522c09ddcdfa7da834700
3
+ metadata.gz: 49de212acae6a9c8e99b3ca01602eca84414955eafc1f965b6e1a35fcdbc3241
4
+ data.tar.gz: 8923a8b87a36f28d34ccac03369a13d1cb18c9db9da94843437c1ef8d281cb46
5
5
  SHA512:
6
- metadata.gz: f4c286312be492b34b44cf66d81f283a9f207b8c35c1c15754c7375a9bfc1aeeb03bcc5f03f04e6fbcf93f1807ef18cc4266c8e4611ed2075fa1722f062adfd8
7
- data.tar.gz: f54e749f298d269c9106a899ff911fdf51785433f239f534232a259cb7eb3dce1edfe0a4d056bea65f1a852fa686693236f4472bf02d6b2c66f203578d9365ff
6
+ metadata.gz: cf61f0de45f6c8e7ea1e8b495beeab96ef523cb3984075b1b4727adb6dfc3fd8f3b97e8712825640482f8f34f2dc3b5142a9d384bba4d4fec7940f10bf623c98
7
+ data.tar.gz: c35ecb00a20b765844b241fd8eda14a9eafab64de1894ba7ec5d4a885b1a188cb985590c5b7460ebe8794dca7ecd4b9df802fa0616f401d4afa3133b51bcad62
@@ -1,3 +1,8 @@
1
+ ## 1.0.0
2
+
3
+ - Update for support Rals 6.1 permanent URL, and compatiable with Rails 6.0.
4
+ - `mode` config has deprecated, use `public: true` instead.
5
+
1
6
  ## 0.6.4
2
7
 
3
8
  - Fix public url generate issue. #37
data/README.md CHANGED
@@ -25,7 +25,7 @@ $ bundle
25
25
  config/storage.yml
26
26
 
27
27
  ```yml
28
- production:
28
+ aliyun:
29
29
  service: Aliyun
30
30
  access_key_id: "your-oss-access-key-id"
31
31
  access_key_secret: "your-oss-access-key-secret"
@@ -33,19 +33,20 @@ production:
33
33
  endpoint: "https://oss-cn-beijing.aliyuncs.com"
34
34
  # path prefix, default: /
35
35
  path: "my-app-files"
36
- # Bucket mode: [public, private], default: public
37
- mode: "public"
36
+ # Bucket public: true/false, default: true, for generate public/private URL.
37
+ public: true
38
38
  ```
39
39
 
40
40
  ### Custom Domain
41
41
 
42
42
  ```yml
43
- production:
43
+ aliyun:
44
44
  service: Aliyun
45
45
  access_key_id: "your-oss-access-key-id"
46
46
  access_key_secret: "your-oss-access-key-secret"
47
47
  bucket: "bucket-name"
48
48
  endpoint: "https://file.myhost.com"
49
+ public: false
49
50
  # Enable cname to use custom domain
50
51
  cname: true
51
52
  ```
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "aliyun/oss"
3
4
 
4
5
  module ActiveStorage
@@ -6,6 +7,14 @@ module ActiveStorage
6
7
  def initialize(**config)
7
8
  Aliyun::Common::Logging.set_log_file("/dev/null")
8
9
  @config = config
10
+
11
+ @public = @config.fetch(:public, false)
12
+
13
+ # Compatible with mode config
14
+ if @config.fetch(:mode, nil) == "public"
15
+ ActiveSupport::Deprecation.warn("mode has deprecated, and will remove in 1.1.0, use public: true instead.")
16
+ @public = true
17
+ end
9
18
  end
10
19
 
11
20
  CHUNK_SIZE = 1024 * 1024
@@ -68,26 +77,6 @@ module ActiveStorage
68
77
  end
69
78
  end
70
79
 
71
- def url(key, expires_in:, filename: nil, content_type:, disposition:, params: {})
72
- instrument :url, key: key do |payload|
73
- sign = private_mode? || disposition == :attachment
74
- filekey = path_for(key)
75
-
76
- if sign
77
- params["response-content-type"] = content_type unless content_type.blank?
78
-
79
- if filename
80
- filename = ActiveStorage::Filename.wrap(filename)
81
- params["response-content-disposition"] = content_disposition_with(type: disposition, filename: filename)
82
- end
83
- end
84
-
85
- generated_url = object_url(filekey, sign: sign, expires_in: expires_in, params: params)
86
- payload[:url] = generated_url
87
- generated_url
88
- end
89
- end
90
-
91
80
  # You must setup CORS on OSS control panel to allow JavaScript request from your site domain.
92
81
  # https://www.alibabacloud.com/help/zh/doc-detail/31988.htm
93
82
  # https://help.aliyun.com/document_detail/31925.html
@@ -115,9 +104,47 @@ module ActiveStorage
115
104
  }
116
105
  end
117
106
 
107
+ # Remove this in Rails 6.1, compatiable with Rails 6.0.0
108
+ def url(key, **options)
109
+ instrument :url, key: key do |payload|
110
+ generated_url =
111
+ if public?
112
+ public_url(key, **options)
113
+ else
114
+ private_url(key, **options)
115
+ end
116
+
117
+ payload[:url] = generated_url
118
+
119
+ generated_url
120
+ end
121
+ end
122
+
118
123
  private
119
124
  attr_reader :config
120
125
 
126
+ def private_url(key, expires_in: 60, filename: nil, content_type: nil, disposition: nil, params: {}, **)
127
+ filekey = path_for(key)
128
+
129
+ params["response-content-type"] = content_type unless content_type.blank?
130
+
131
+ if filename
132
+ filename = ActiveStorage::Filename.wrap(filename)
133
+ params["response-content-disposition"] = content_disposition_with(type: disposition, filename: filename)
134
+ end
135
+
136
+ object_url(filekey, sign: true, expires_in: expires_in, params: params)
137
+ end
138
+
139
+ def public_url(key, params: {}, **)
140
+ object_url(path_for(key), sign: false, params: params)
141
+ end
142
+
143
+ # Remove this in Rails 6.1, compatiable with Rails 6.0.0
144
+ def public?
145
+ @public == true
146
+ end
147
+
121
148
  def path_for(key)
122
149
  root_path = config.fetch(:path, nil)
123
150
  if root_path.blank? || root_path == "/"
@@ -129,7 +156,7 @@ module ActiveStorage
129
156
  full_path.gsub(/^\//, "").gsub(/[\/]+/, "/")
130
157
  end
131
158
 
132
- def object_url(key, sign:, expires_in: 60, params: {})
159
+ def object_url(key, sign: false, expires_in: 60, params: {})
133
160
  url = bucket.object_url(key, false)
134
161
  unless sign
135
162
  return url if params.blank?
@@ -151,7 +178,7 @@ module ActiveStorage
151
178
  string_to_sign = ["GET", "", "", expires, resource].join("\n")
152
179
  query["Signature"] = bucket.sign(string_to_sign)
153
180
 
154
- [url, query.to_query].join('?')
181
+ [url, query.to_query].join("?")
155
182
  end
156
183
 
157
184
  def bucket
@@ -160,11 +187,6 @@ module ActiveStorage
160
187
  @bucket
161
188
  end
162
189
 
163
- # Bucket mode :public | :private
164
- def private_mode?
165
- @private_mode ||= config.fetch(:mode, "public").to_s == "private"
166
- end
167
-
168
190
  def authorization(key, content_type, checksum, date)
169
191
  filename = File.expand_path("/#{bucket.name}/#{path_for(key)}")
170
192
  addition_headers = "x-oss-date:#{date}"
@@ -185,6 +207,5 @@ module ActiveStorage
185
207
  cname: config.fetch(:cname, false)
186
208
  )
187
209
  end
188
-
189
210
  end
190
211
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveStorageAliyun
2
- VERSION = '0.6.4'
4
+ VERSION = "1.0.0"
3
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activestorage-aliyun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Lee
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.0
19
+ version: 6.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.2.0
26
+ version: 6.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: aliyun-sdk
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.0.1
72
+ rubygems_version: 3.0.3
73
73
  signing_key:
74
74
  specification_version: 4
75
75
  summary: Wraps the Aliyun OSS as an Active Storage service