activestorage-aliyun 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -0
- data/README.md +11 -11
- data/lib/active_storage/service/aliyun_service.rb +32 -11
- data/lib/active_storage_aliyun/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e1d0cce28e49848d648e656a281dd9a0848b2e3f601fcce2813977501e9f321
|
4
|
+
data.tar.gz: ce8902fe4003bc87ebe1ae6a7f7f1b55af136a05fbabc44856eaaf0e9116d0c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d55c0ac4bfbe3dcf9ad29a37990cc843e3d3352a3b978c8ec2ca702e30d2207be7d3edad2e6f2b44f56c87bf330a79a00f5eb0a40b291fe24fa940d2d976b61
|
7
|
+
data.tar.gz: 11e6a67d777d4c07f2cd9edcfef2886d47ccc6f5561cebc43e9df95722bee051a7e19ee8986dec9ae05d3010756a06964be9a0aa7d40908c7ff518823f741c67
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -28,12 +28,12 @@ config/storage.yml
|
|
28
28
|
```yml
|
29
29
|
aliyun:
|
30
30
|
service: Aliyun
|
31
|
-
access_key_id:
|
32
|
-
access_key_secret:
|
33
|
-
bucket:
|
34
|
-
endpoint:
|
31
|
+
access_key_id: 'your-oss-access-key-id'
|
32
|
+
access_key_secret: 'your-oss-access-key-secret'
|
33
|
+
bucket: 'bucket-name'
|
34
|
+
endpoint: 'https://oss-cn-beijing.aliyuncs.com'
|
35
35
|
# path prefix, default: /
|
36
|
-
path:
|
36
|
+
path: 'my-app-files'
|
37
37
|
# Bucket public: true/false, default: true, for generate public/private URL.
|
38
38
|
public: true
|
39
39
|
```
|
@@ -43,13 +43,13 @@ aliyun:
|
|
43
43
|
```yml
|
44
44
|
aliyun:
|
45
45
|
service: Aliyun
|
46
|
-
access_key_id:
|
47
|
-
access_key_secret:
|
48
|
-
bucket:
|
49
|
-
endpoint:
|
46
|
+
access_key_id: 'your-oss-access-key-id'
|
47
|
+
access_key_secret: 'your-oss-access-key-secret'
|
48
|
+
bucket: 'bucket-name'
|
49
|
+
endpoint: 'https://oss-cn-beijing.aliyuncs.com'
|
50
50
|
public: false
|
51
|
-
#
|
52
|
-
|
51
|
+
# Custom host for get file url, if this present, upload still use `endpoint`, but download url will use this.
|
52
|
+
host: 'https://file.myhost.com'
|
53
53
|
```
|
54
54
|
|
55
55
|
### Use for image url
|
@@ -29,7 +29,7 @@ module ActiveStorage
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def download(key, &block)
|
32
|
-
if
|
32
|
+
if block
|
33
33
|
instrument :streaming_download, key: key do
|
34
34
|
bucket.get_object(path_for(key), &block)
|
35
35
|
end
|
@@ -156,25 +156,25 @@ module ActiveStorage
|
|
156
156
|
def path_for(key)
|
157
157
|
root_path = config.fetch(:path, nil)
|
158
158
|
full_path = if root_path.blank? || root_path == "/"
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
159
|
+
key
|
160
|
+
else
|
161
|
+
File.join(root_path, key)
|
162
|
+
end
|
163
163
|
|
164
|
-
full_path.gsub(%r{^/}, "").
|
164
|
+
full_path.gsub(%r{^/}, "").squeeze("/")
|
165
165
|
end
|
166
166
|
|
167
167
|
def object_url(key, sign: false, expires_in: 60, params: {})
|
168
|
-
url =
|
168
|
+
url = host_bucket.object_url(key, false)
|
169
169
|
unless sign
|
170
170
|
return url if params.blank?
|
171
171
|
|
172
172
|
return "#{url}?#{params.to_query}"
|
173
173
|
end
|
174
174
|
|
175
|
-
resource = "/#{
|
176
|
-
expires
|
177
|
-
query
|
175
|
+
resource = "/#{host_bucket.name}/#{key}"
|
176
|
+
expires = Time.now.to_i + expires_in
|
177
|
+
query = {
|
178
178
|
"Expires" => expires,
|
179
179
|
"OSSAccessKeyId" => config.fetch(:access_key_id)
|
180
180
|
}
|
@@ -183,7 +183,7 @@ module ActiveStorage
|
|
183
183
|
resource += "?" + params.map { |k, v| "#{k}=#{v}" }.sort.join("&") if params.present?
|
184
184
|
|
185
185
|
string_to_sign = ["GET", "", "", expires, resource].join("\n")
|
186
|
-
query["Signature"] =
|
186
|
+
query["Signature"] = host_bucket.sign(string_to_sign)
|
187
187
|
|
188
188
|
[url, query.to_query].join("?")
|
189
189
|
end
|
@@ -195,6 +195,14 @@ module ActiveStorage
|
|
195
195
|
@bucket
|
196
196
|
end
|
197
197
|
|
198
|
+
def host_bucket
|
199
|
+
return @host_bucket if defined? @host_bucket
|
200
|
+
|
201
|
+
host_bucket_client = host ? host_client : client
|
202
|
+
@host_bucket = host_bucket_client.get_bucket(config.fetch(:bucket))
|
203
|
+
@host_bucket
|
204
|
+
end
|
205
|
+
|
198
206
|
def authorization(key, content_type, checksum, date)
|
199
207
|
filename = File.expand_path("/#{bucket.name}/#{path_for(key)}")
|
200
208
|
addition_headers = "x-oss-date:#{date}"
|
@@ -207,6 +215,10 @@ module ActiveStorage
|
|
207
215
|
config.fetch(:endpoint, "https://oss-cn-hangzhou.aliyuncs.com")
|
208
216
|
end
|
209
217
|
|
218
|
+
def host
|
219
|
+
config.fetch(:host, nil)
|
220
|
+
end
|
221
|
+
|
210
222
|
def client
|
211
223
|
@client ||= Aliyun::OSS::Client.new(
|
212
224
|
endpoint: endpoint,
|
@@ -215,5 +227,14 @@ module ActiveStorage
|
|
215
227
|
cname: config.fetch(:cname, false)
|
216
228
|
)
|
217
229
|
end
|
230
|
+
|
231
|
+
def host_client
|
232
|
+
@host_client ||= Aliyun::OSS::Client.new(
|
233
|
+
endpoint: host,
|
234
|
+
access_key_id: config.fetch(:access_key_id),
|
235
|
+
access_key_secret: config.fetch(:access_key_secret),
|
236
|
+
cname: config.fetch(:cname, false)
|
237
|
+
)
|
238
|
+
end
|
218
239
|
end
|
219
240
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activestorage-aliyun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aliyun-sdk
|
@@ -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.
|
72
|
+
rubygems_version: 3.4.19
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Wraps the Aliyun OSS as an Active Storage service
|