carrierwave-aliyun 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/carrierwave/aliyun/bucket.rb +9 -1
- data/lib/carrierwave/aliyun/version.rb +1 -1
- data/lib/carrierwave/storage/aliyun.rb +22 -9
- data/lib/carrierwave/storage/aliyun_file.rb +43 -15
- 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: 876c53c7233505f4afc350bbf46e91c8a488d1842a74f4ee5802259d96468846
|
4
|
+
data.tar.gz: b32c6cc04411c9f5c3115e78b91a7902f3d2a4068cbb325316631363c709de34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b5211cab35612c46cb22c50816bc9846682cac9aaf14ce293229201550df03c773fde7b843c3fcf6ab0eb1500a14cf7cd0866183be525c10d12dbb26ae4c08b
|
7
|
+
data.tar.gz: a3c1233546856b1fcc834810753bf4390f49dce8c8d9301b77e6096bc77a932280b83c386cf107c981053fefcefb5c1c103e069e1993362cd3937a18d33ef505
|
data/CHANGELOG.md
CHANGED
@@ -75,6 +75,13 @@ module CarrierWave
|
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
|
+
def copy_object(source, dest)
|
79
|
+
source = source.sub(PATH_PREFIX, "")
|
80
|
+
dest = dest.sub(PATH_PREFIX, "")
|
81
|
+
|
82
|
+
oss_upload_client.copy_object(source, dest)
|
83
|
+
end
|
84
|
+
|
78
85
|
# 读取文件
|
79
86
|
# params:
|
80
87
|
# - path - remote 存储路径
|
@@ -134,7 +141,8 @@ module CarrierWave
|
|
134
141
|
end
|
135
142
|
|
136
143
|
def head(path)
|
137
|
-
|
144
|
+
path = path.sub(PATH_PREFIX, "")
|
145
|
+
oss_upload_client.get_object(path)
|
138
146
|
end
|
139
147
|
|
140
148
|
private
|
@@ -3,14 +3,14 @@
|
|
3
3
|
module CarrierWave
|
4
4
|
module Storage
|
5
5
|
class Aliyun < Abstract
|
6
|
-
def store!(
|
6
|
+
def store!(new_file)
|
7
7
|
f = AliyunFile.new(uploader, self, uploader.store_path)
|
8
8
|
headers = {
|
9
|
-
content_type:
|
9
|
+
content_type: new_file.content_type,
|
10
10
|
content_disposition: uploader.try(:content_disposition)
|
11
11
|
}
|
12
12
|
|
13
|
-
f.store(
|
13
|
+
f.store(new_file, headers)
|
14
14
|
f
|
15
15
|
end
|
16
16
|
|
@@ -18,19 +18,19 @@ module CarrierWave
|
|
18
18
|
AliyunFile.new(uploader, self, uploader.store_path(identifier))
|
19
19
|
end
|
20
20
|
|
21
|
-
def cache!(
|
22
|
-
f = AliyunFile.new(uploader, self, uploader.
|
21
|
+
def cache!(new_file)
|
22
|
+
f = AliyunFile.new(uploader, self, uploader.cache_path)
|
23
23
|
headers = {
|
24
|
-
content_type:
|
24
|
+
content_type: new_file.content_type,
|
25
25
|
content_disposition: uploader.try(:content_disposition)
|
26
26
|
}
|
27
27
|
|
28
|
-
f.store(
|
28
|
+
f.store(new_file, headers)
|
29
29
|
f
|
30
30
|
end
|
31
31
|
|
32
32
|
def retrieve_from_cache!(identifier)
|
33
|
-
AliyunFile.new(uploader, self, uploader.
|
33
|
+
AliyunFile.new(uploader, self, uploader.cache_path(identifier))
|
34
34
|
end
|
35
35
|
|
36
36
|
def delete_dir!(path)
|
@@ -38,8 +38,21 @@ module CarrierWave
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def clean_cache!(_seconds)
|
41
|
-
|
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)
|
42
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def bucket
|
54
|
+
@bucket ||= CarrierWave::Aliyun::Bucket.new(uploader)
|
55
|
+
end
|
43
56
|
end
|
44
57
|
end
|
45
58
|
end
|
@@ -2,23 +2,24 @@
|
|
2
2
|
|
3
3
|
module CarrierWave
|
4
4
|
module Storage
|
5
|
-
class AliyunFile
|
6
|
-
attr_reader :path
|
5
|
+
class AliyunFile
|
6
|
+
attr_reader :uploader, :path
|
7
|
+
|
8
|
+
alias_method :filename, :path
|
9
|
+
alias_method :identifier, :filename
|
7
10
|
|
8
11
|
def initialize(uploader, base, path)
|
9
|
-
@uploader = uploader
|
10
|
-
@path = URI.encode(path)
|
11
|
-
@base = base
|
12
|
+
@uploader, @path, @base = uploader, URI.encode(path), base
|
12
13
|
end
|
13
14
|
|
14
15
|
def read
|
15
|
-
object, body = bucket.get(
|
16
|
+
object, body = bucket.get(path)
|
16
17
|
@headers = object.headers
|
17
18
|
body
|
18
19
|
end
|
19
20
|
|
20
21
|
def delete
|
21
|
-
bucket.delete(
|
22
|
+
bucket.delete(path)
|
22
23
|
true
|
23
24
|
rescue => e
|
24
25
|
# If the file's not there, don't panic
|
@@ -33,9 +34,9 @@ module CarrierWave
|
|
33
34
|
#
|
34
35
|
def url(opts = {})
|
35
36
|
if bucket.mode == :private
|
36
|
-
bucket.private_get_url(
|
37
|
+
bucket.private_get_url(path, opts)
|
37
38
|
else
|
38
|
-
bucket.path_to_url(
|
39
|
+
bucket.path_to_url(path, opts)
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
@@ -49,22 +50,49 @@ module CarrierWave
|
|
49
50
|
|
50
51
|
def store(new_file, headers = {})
|
51
52
|
if new_file.is_a?(self.class)
|
52
|
-
new_file.
|
53
|
+
new_file.copy_to(path)
|
53
54
|
else
|
54
|
-
|
55
|
+
fog_file = new_file.to_file
|
56
|
+
bucket.put(path, fog_file, headers)
|
57
|
+
fog_file.close if fog_file && !fog_file.closed?
|
55
58
|
end
|
59
|
+
true
|
56
60
|
end
|
57
61
|
|
58
62
|
def headers
|
59
|
-
@headers ||=
|
63
|
+
@headers ||= begin
|
64
|
+
obj = bucket.head(path)
|
65
|
+
obj.headers
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def exists?
|
70
|
+
!!headers
|
71
|
+
end
|
72
|
+
|
73
|
+
def copy_to(new_path)
|
74
|
+
bucket.copy_object(path, new_path)
|
75
|
+
self.class.new(uploader, @base, new_path)
|
76
|
+
end
|
77
|
+
|
78
|
+
def extension
|
79
|
+
path_elements = path.split(".")
|
80
|
+
path_elements.last if path_elements.size > 1
|
81
|
+
end
|
82
|
+
|
83
|
+
def original_filename
|
84
|
+
return @original_filename if @original_filename
|
85
|
+
if @file && @file.respond_to?(:original_filename)
|
86
|
+
@file.original_filename
|
87
|
+
elsif path
|
88
|
+
::File.basename(path)
|
89
|
+
end
|
60
90
|
end
|
61
91
|
|
62
92
|
private
|
63
93
|
|
64
94
|
def bucket
|
65
|
-
|
66
|
-
|
67
|
-
@bucket = CarrierWave::Aliyun::Bucket.new(@uploader)
|
95
|
+
@bucket ||= CarrierWave::Aliyun::Bucket.new(uploader)
|
68
96
|
end
|
69
97
|
end
|
70
98
|
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.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|