carrierwave-aliyun 1.1.3 → 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 +5 -0
- data/lib/carrierwave/aliyun/bucket.rb +37 -42
- data/lib/carrierwave/aliyun/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54c88d264e49631dd46a637080fc79b10cb73d487910a1608afd4ac67cf65561
|
4
|
+
data.tar.gz: 7362e2b9d48547d369994443b105af5f4d57f7a34b64a7c78b51b9ecf940aa8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6589f76ad4cc466e3bd1acb690a0759786cb7ec2517fe2e51c2aeb0ad044053ff1b6d373bc04b51c75db6cb34551f0fe1a9d22c688bb66579a1d8f8303af37c7
|
7
|
+
data.tar.gz: '00487944ad9d21be007c4f1148ce676e376c621f9d1de6207347d1f621351fda81c48b2f8100801cb6cff18965923447ae1034a396406da93b012280bb34590e'
|
data/CHANGELOG.md
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
module CarrierWave
|
4
4
|
module Aliyun
|
5
5
|
class Bucket
|
6
|
-
PATH_PREFIX = %r{^/}
|
6
|
+
PATH_PREFIX = %r{^/}.freeze
|
7
7
|
CHUNK_SIZE = 1024 * 1024
|
8
8
|
|
9
9
|
attr_reader :access_key_id, :access_key_secret, :bucket, :region, :mode, :host
|
10
10
|
|
11
|
-
attr_reader :endpoint, :
|
11
|
+
attr_reader :endpoint, :upload_endpoint, :get_endpoint
|
12
12
|
|
13
13
|
def initialize(uploader)
|
14
14
|
if uploader.aliyun_area.present?
|
@@ -16,7 +16,7 @@ module CarrierWave
|
|
16
16
|
uploader.aliyun_region ||= uploader.aliyun_area
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
unless uploader.aliyun_private_read.nil?
|
20
20
|
ActiveSupport::Deprecation.warn(%(config.aliyun_private_read will deprecation in carrierwave-aliyun 1.1.0, please use `aliyun_mode = :private` instead.))
|
21
21
|
uploader.aliyun_mode ||= uploader.aliyun_private_read ? :private : :public
|
22
22
|
end
|
@@ -38,15 +38,15 @@ module CarrierWave
|
|
38
38
|
@mode = (uploader.aliyun_mode || :public).to_sym
|
39
39
|
|
40
40
|
# Host for get request
|
41
|
-
@
|
41
|
+
@endpoint = "https://#{bucket}.oss-#{region}.aliyuncs.com"
|
42
|
+
@host = uploader.aliyun_host || @endpoint
|
42
43
|
|
43
44
|
unless @host.include?("//")
|
44
|
-
raise "config.aliyun_host requirement include // http:// or https://, but you give: #{
|
45
|
+
raise "config.aliyun_host requirement include // http:// or https://, but you give: #{host}"
|
45
46
|
end
|
46
47
|
|
47
|
-
@
|
48
|
-
@upload_endpoint = uploader.aliyun_internal == true ? "https://oss-#{
|
49
|
-
@img_endpoint = "https://img-#{self.region}.aliyuncs.com"
|
48
|
+
@get_endpoint = "https://oss-#{region}.aliyuncs.com"
|
49
|
+
@upload_endpoint = uploader.aliyun_internal == true ? "https://oss-#{region}-internal.aliyuncs.com" : "https://oss-#{region}.aliyuncs.com"
|
50
50
|
end
|
51
51
|
|
52
52
|
# 上传文件
|
@@ -70,7 +70,7 @@ module CarrierWave
|
|
70
70
|
stream << file.read(CHUNK_SIZE) until file.eof?
|
71
71
|
end
|
72
72
|
path_to_url(path)
|
73
|
-
rescue => e
|
73
|
+
rescue StandardError => e
|
74
74
|
raise "Put file failed: #{e}"
|
75
75
|
end
|
76
76
|
end
|
@@ -95,7 +95,7 @@ module CarrierWave
|
|
95
95
|
end
|
96
96
|
|
97
97
|
[obj, chunk_buff.join("")]
|
98
|
-
rescue => e
|
98
|
+
rescue StandardError => e
|
99
99
|
raise "Get content faild: #{e}"
|
100
100
|
end
|
101
101
|
|
@@ -110,36 +110,38 @@ module CarrierWave
|
|
110
110
|
path = path.sub(PATH_PREFIX, "")
|
111
111
|
oss_upload_client.delete_object(path)
|
112
112
|
path_to_url(path)
|
113
|
-
rescue => e
|
113
|
+
rescue StandardError => e
|
114
114
|
raise "Delete failed: #{e}"
|
115
115
|
end
|
116
116
|
|
117
117
|
##
|
118
118
|
# 根据配置返回完整的上传文件的访问地址
|
119
119
|
def path_to_url(path, thumb: nil)
|
120
|
-
path
|
121
|
-
|
122
|
-
if thumb
|
123
|
-
[self.host, [path, thumb].join("")].join("/")
|
124
|
-
else
|
125
|
-
[self.host, path].join("/")
|
126
|
-
end
|
120
|
+
get_url(path, thumb: thumb)
|
127
121
|
end
|
128
122
|
|
129
123
|
# 私有空间访问地址,会带上实时算出的 token 信息
|
130
124
|
# 有效期 15 minutes
|
131
125
|
def private_get_url(path, thumb: nil)
|
126
|
+
get_url(path, private: true, thumb: thumb)
|
127
|
+
end
|
128
|
+
|
129
|
+
def get_url(path, private: false, thumb: nil)
|
132
130
|
path = path.sub(PATH_PREFIX, "")
|
133
131
|
|
134
|
-
url = if thumb
|
135
|
-
|
136
|
-
parameters =
|
137
|
-
|
132
|
+
url = if thumb&.start_with?("?")
|
133
|
+
# foo.jpg?x-oss-process=image/resize,h_100
|
134
|
+
parameters = { "x-oss-process" => thumb.split("=").last }
|
135
|
+
oss_client.object_url(path, private, 15.minutes, parameters)
|
138
136
|
else
|
139
|
-
oss_client.object_url(path,
|
137
|
+
oss_client.object_url(path, private, 15.minutes)
|
140
138
|
end
|
141
139
|
|
142
|
-
|
140
|
+
unless private
|
141
|
+
url = [url, thumb].join("") unless thumb&.start_with?("?")
|
142
|
+
end
|
143
|
+
|
144
|
+
url.sub(endpoint, host)
|
143
145
|
end
|
144
146
|
|
145
147
|
def head(path)
|
@@ -149,26 +151,19 @@ module CarrierWave
|
|
149
151
|
|
150
152
|
private
|
151
153
|
|
152
|
-
|
153
|
-
|
154
|
-
client = ::Aliyun::OSS::Client.new(endpoint: self.endpoint,
|
155
|
-
access_key_id: self.access_key_id, access_key_secret: self.access_key_secret)
|
156
|
-
@oss_client = client.get_bucket(self.bucket)
|
157
|
-
end
|
154
|
+
def oss_client
|
155
|
+
return @oss_client if defined?(@oss_client)
|
158
156
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
access_key_id: self.access_key_id, access_key_secret: self.access_key_secret)
|
163
|
-
@img_client = client.get_bucket(self.bucket)
|
164
|
-
end
|
157
|
+
client = ::Aliyun::OSS::Client.new(endpoint: get_endpoint, access_key_id: access_key_id, access_key_secret: access_key_secret)
|
158
|
+
@oss_client = client.get_bucket(bucket)
|
159
|
+
end
|
165
160
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
161
|
+
def oss_upload_client
|
162
|
+
return @oss_upload_client if defined?(@oss_upload_client)
|
163
|
+
|
164
|
+
client = ::Aliyun::OSS::Client.new(endpoint: upload_endpoint, access_key_id: access_key_id, access_key_secret: access_key_secret)
|
165
|
+
@oss_upload_client = client.get_bucket(bucket)
|
166
|
+
end
|
172
167
|
end
|
173
168
|
end
|
174
169
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-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: 2020-
|
11
|
+
date: 2020-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|