carrierwave-aliyun 1.2.1 → 1.2.2
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/carrierwave/aliyun/bucket.rb +12 -8
- data/lib/carrierwave/aliyun/version.rb +1 -1
- data/lib/carrierwave/storage/aliyun.rb +3 -14
- data/lib/carrierwave/storage/aliyun_file.rb +14 -13
- 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: '09185a0291f96fed424df86a4be3815f13171b74f4b6d891b945de90bdc3924d'
|
4
|
+
data.tar.gz: ff50669bd39b9da0ff3b9c5c00c9e646fc0f3f46e7f0b1b45643c9d76abe66fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd28e434c5bd6d43ccfff8f5b98dff4343d1440c3ded461397b95bde45e280bfde4481e0c06d0af3da8d38009620546c36cd777fd5c6bae893038e94533cc8ba
|
7
|
+
data.tar.gz: 88a37bc5bbf656be44cb50232943faac2ba26698fdee306f3441f0365e853066fdfb97297b9c7c0012d256ba80f02b69f78af8e585938de7917926dfa473f4a1
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
This gem adds support for [Aliyun OSS](http://oss.aliyun.com) to [CarrierWave](https://github.com/jnicklas/carrierwave/)
|
4
4
|
|
5
|
-
[](https://rubygems.org/gems/carrierwave-aliyun) [](https://rubygems.org/gems/carrierwave-aliyun) [](https://github.com/huacnlee/carrierwave-aliyun/actions?query=workflow%3Abuild)
|
6
6
|
|
7
7
|
> NOTE: 此 Gem 是一个 CarrierWave 的组件,你需要配合 CarrierWave 一起使用,如果你需要直接用 Aliyun OSS,可以尝试用 [aliyun-sdk](https://github.com/aliyun/aliyun-oss-ruby-sdk) 这个 Gem。
|
8
8
|
|
@@ -6,9 +6,8 @@ module CarrierWave
|
|
6
6
|
PATH_PREFIX = %r{^/}.freeze
|
7
7
|
CHUNK_SIZE = 1024 * 1024
|
8
8
|
|
9
|
-
attr_reader :access_key_id, :access_key_secret, :bucket, :region, :mode, :host
|
10
|
-
|
11
|
-
attr_reader :endpoint, :upload_endpoint, :get_endpoint
|
9
|
+
attr_reader :access_key_id, :access_key_secret, :bucket, :region, :mode, :host, :endpoint, :upload_endpoint,
|
10
|
+
:get_endpoint
|
12
11
|
|
13
12
|
def initialize(uploader)
|
14
13
|
if uploader.aliyun_area.present?
|
@@ -137,9 +136,7 @@ module CarrierWave
|
|
137
136
|
oss_client.object_url(path, private, 15.minutes)
|
138
137
|
end
|
139
138
|
|
140
|
-
|
141
|
-
url = [url, thumb].join("") unless thumb&.start_with?("?")
|
142
|
-
end
|
139
|
+
url = [url, thumb].join("") if !private && !thumb&.start_with?("?")
|
143
140
|
|
144
141
|
url.sub(endpoint, host)
|
145
142
|
end
|
@@ -149,19 +146,26 @@ module CarrierWave
|
|
149
146
|
oss_upload_client.get_object(path)
|
150
147
|
end
|
151
148
|
|
149
|
+
# list_objects for test
|
150
|
+
def list_objects(opts = {})
|
151
|
+
oss_client.list_objects(opts)
|
152
|
+
end
|
153
|
+
|
152
154
|
private
|
153
155
|
|
154
156
|
def oss_client
|
155
157
|
return @oss_client if defined?(@oss_client)
|
156
158
|
|
157
|
-
client = ::Aliyun::OSS::Client.new(endpoint: get_endpoint, access_key_id: access_key_id,
|
159
|
+
client = ::Aliyun::OSS::Client.new(endpoint: get_endpoint, access_key_id: access_key_id,
|
160
|
+
access_key_secret: access_key_secret)
|
158
161
|
@oss_client = client.get_bucket(bucket)
|
159
162
|
end
|
160
163
|
|
161
164
|
def oss_upload_client
|
162
165
|
return @oss_upload_client if defined?(@oss_upload_client)
|
163
166
|
|
164
|
-
client = ::Aliyun::OSS::Client.new(endpoint: upload_endpoint, access_key_id: access_key_id,
|
167
|
+
client = ::Aliyun::OSS::Client.new(endpoint: upload_endpoint, access_key_id: access_key_id,
|
168
|
+
access_key_secret: access_key_secret)
|
165
169
|
@oss_upload_client = client.get_bucket(bucket)
|
166
170
|
end
|
167
171
|
end
|
@@ -37,22 +37,11 @@ module CarrierWave
|
|
37
37
|
# do nothing, because there's no such things as 'empty directory'
|
38
38
|
end
|
39
39
|
|
40
|
-
def clean_cache!(_seconds)
|
41
|
-
will_remove_keys = []
|
42
|
-
bucket.list_objects(prefix: uploader.cache_path).each do |file|
|
43
|
-
next unless file.is_a?(Object)
|
44
|
-
time = file.key.scan(/(\d+)-\d+-\d+(?:-\d+)?/).first.map { |t| t.to_i }
|
45
|
-
time = Time.at(*time)
|
46
|
-
will_remove_keys << item.key if time < (Time.now.utc - seconds)
|
47
|
-
end
|
48
|
-
bucket.batch_delete_objects(will_remove_keys)
|
49
|
-
end
|
50
|
-
|
51
40
|
private
|
52
41
|
|
53
|
-
|
54
|
-
|
55
|
-
|
42
|
+
def bucket
|
43
|
+
@bucket ||= CarrierWave::Aliyun::Bucket.new(uploader)
|
44
|
+
end
|
56
45
|
end
|
57
46
|
end
|
58
47
|
end
|
@@ -6,11 +6,13 @@ module CarrierWave
|
|
6
6
|
attr_writer :file
|
7
7
|
attr_reader :uploader, :path
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
alias filename path
|
10
|
+
alias identifier filename
|
11
11
|
|
12
12
|
def initialize(uploader, base, path)
|
13
|
-
@uploader
|
13
|
+
@uploader = uploader
|
14
|
+
@path = path
|
15
|
+
@base = base
|
14
16
|
end
|
15
17
|
|
16
18
|
def file
|
@@ -18,11 +20,9 @@ module CarrierWave
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def size
|
21
|
-
file.headers[:content_length].to_i
|
22
|
-
|
23
|
-
|
24
|
-
def escape(path)
|
25
|
-
CGI.escape(path).gsub("%2F", "/")
|
23
|
+
file.headers[:content_length].to_i
|
24
|
+
rescue StandardError
|
25
|
+
nil
|
26
26
|
end
|
27
27
|
|
28
28
|
def read
|
@@ -34,7 +34,7 @@ module CarrierWave
|
|
34
34
|
def delete
|
35
35
|
bucket.delete(path)
|
36
36
|
true
|
37
|
-
rescue => e
|
37
|
+
rescue StandardError => e
|
38
38
|
# If the file's not there, don't panic
|
39
39
|
puts "carrierwave-aliyun delete file failed: #{e}"
|
40
40
|
nil
|
@@ -95,7 +95,8 @@ module CarrierWave
|
|
95
95
|
|
96
96
|
def original_filename
|
97
97
|
return @original_filename if @original_filename
|
98
|
-
|
98
|
+
|
99
|
+
if @file&.respond_to?(:original_filename)
|
99
100
|
@file.original_filename
|
100
101
|
elsif path
|
101
102
|
::File.basename(path)
|
@@ -104,9 +105,9 @@ module CarrierWave
|
|
104
105
|
|
105
106
|
private
|
106
107
|
|
107
|
-
|
108
|
-
|
109
|
-
|
108
|
+
def bucket
|
109
|
+
@bucket ||= CarrierWave::Aliyun::Bucket.new(uploader)
|
110
|
+
end
|
110
111
|
end
|
111
112
|
end
|
112
113
|
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.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
72
|
- !ruby/object:Gem::Version
|
73
73
|
version: '0'
|
74
74
|
requirements: []
|
75
|
-
rubygems_version: 3.
|
75
|
+
rubygems_version: 3.2.3
|
76
76
|
signing_key:
|
77
77
|
specification_version: 4
|
78
78
|
summary: Aliyun OSS support for Carrierwave
|