carrierwave-qiniu 1.2.0 → 1.2.1
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/.gitignore +2 -0
- data/CHANGELOG.md +4 -0
- data/README.md +3 -3
- data/lib/carrierwave-qiniu/version.rb +1 -1
- data/lib/carrierwave/qiniu/configuration.rb +1 -0
- data/lib/carrierwave/storage/qiniu.rb +30 -0
- data/lib/carrierwave/uploader/base.rb +1 -12
- data/spec/spec_helper.rb +0 -1
- data/spec/upload_spec.rb +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f8f66a9de516d766326b6b71a4458118c1c7a65efb8d658db6a1d3461211afa
|
4
|
+
data.tar.gz: 287a017867010ed5c08e090716b5b42c22d46e74f90deb0365d523c982f0cd0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08df3bb2b5aaeecc01e642da1626d43b915850403550573af8e0a5f9c722ad93da768e77a011c260fe84b7f5d79f6d1e1ef6554ba4b5db22434d3114452acdd2'
|
7
|
+
data.tar.gz: b9231fd84b073877b26deffc7fe495386510af8aac24e945153f481831aa90c6aeae571215e5bd6e6f6470c842fde2d3b4535745fb6cf541337431508e54c239
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Carrierwave::Qiniu
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/carrierwave-qiniu)
|
4
4
|
|
5
5
|
This gem adds storage support for [Qiniu](http://qiniutek.com) to [Carrierwave](https://github.com/jnicklas/carrierwave)
|
6
6
|
|
@@ -10,7 +10,7 @@ example: https://github.com/huobazi/carrierwave-qiniu-example
|
|
10
10
|
|
11
11
|
Add the following to your application's Gemfile:
|
12
12
|
|
13
|
-
gem 'carrierwave-qiniu', '~> 1.1
|
13
|
+
gem 'carrierwave-qiniu', '~> 1.2.1'
|
14
14
|
gem 'carrierwave-i18n' # If you need to use locales other than English
|
15
15
|
|
16
16
|
And then execute:
|
@@ -19,7 +19,7 @@ And then execute:
|
|
19
19
|
|
20
20
|
Or install it yourself as:
|
21
21
|
|
22
|
-
$ gem install carrierwave-qiniu -v 1.1
|
22
|
+
$ gem install carrierwave-qiniu -v 1.2.1
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
@@ -93,6 +93,20 @@ module CarrierWave
|
|
93
93
|
@qiniu_bucket_private ? ::Qiniu::Auth.authorize_download_url(primitive_url, :expires_in => @qiniu_private_url_expires_in) : primitive_url
|
94
94
|
end
|
95
95
|
|
96
|
+
def clean_cache!(seconds)
|
97
|
+
code, result, response_headers, s, d = Qiniu::Storage.list(Qiniu::Storage::ListPolicy.new(
|
98
|
+
@qiniu_bucket,# 存储空间
|
99
|
+
1000,# 列举的条目数
|
100
|
+
'', # 指定前缀
|
101
|
+
''# 指定目录分隔符
|
102
|
+
)).items.each do |file|
|
103
|
+
# generate_cache_id returns key formated TIMEINT-PID(-COUNTER)-RND
|
104
|
+
time = file.key.scan(/(\d+)-\d+-\d+(?:-\d+)?/).first.map { |t| t.to_i }
|
105
|
+
time = Time.at(*time)
|
106
|
+
delete(file.key) if time < (Time.now.utc - seconds)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
96
110
|
private
|
97
111
|
|
98
112
|
def init
|
@@ -196,6 +210,10 @@ module CarrierWave
|
|
196
210
|
::File.basename(path)
|
197
211
|
end
|
198
212
|
|
213
|
+
def clean_cache!(seconds)
|
214
|
+
qiniu_connection.clean_cache!(seconds)
|
215
|
+
end
|
216
|
+
|
199
217
|
private
|
200
218
|
|
201
219
|
def qiniu_connection
|
@@ -266,6 +284,18 @@ module CarrierWave
|
|
266
284
|
def retrieve_from_cache!(identifier)
|
267
285
|
::CarrierWave::Storage::Qiniu::File.new(uploader, uploader.cache_path(identifier))
|
268
286
|
end
|
287
|
+
|
288
|
+
##
|
289
|
+
# Deletes a cache dir
|
290
|
+
#
|
291
|
+
def delete_dir!(path)
|
292
|
+
# do nothing, because there's no such things as 'empty directory'
|
293
|
+
end
|
294
|
+
|
295
|
+
def clean_cache!(seconds)
|
296
|
+
::CarrierWave::Storage::Qiniu::File.new(uploader, nil).clean_cache!(seconds)
|
297
|
+
end
|
298
|
+
|
269
299
|
end
|
270
300
|
end
|
271
301
|
end
|
@@ -1,32 +1,21 @@
|
|
1
1
|
#encoding: utf-8
|
2
2
|
module CarrierWave
|
3
|
-
|
4
3
|
class SanitizedFile
|
5
|
-
|
6
4
|
attr_accessor :copy_from_path
|
7
|
-
|
8
5
|
end
|
9
6
|
|
10
7
|
module Uploader
|
11
8
|
module Cache
|
12
|
-
|
13
9
|
alias_method :old_cache!, :cache!
|
14
|
-
|
15
10
|
def cache!(new_file = sanitized_file)
|
16
|
-
|
17
11
|
old_cache! new_file
|
18
|
-
|
19
12
|
if new_file.kind_of? CarrierWave::Storage::Qiniu::File
|
20
13
|
@file.copy_from_path = new_file.path
|
21
14
|
elsif new_file.kind_of? CarrierWave::Uploader::Base
|
22
15
|
return unless new_file.file.present?
|
23
|
-
@file.copy_from_path = new_file.file.path
|
16
|
+
@file.copy_from_path = new_file.file.path if @file.respond_to?(:copy_from_path)
|
24
17
|
end
|
25
|
-
|
26
18
|
end
|
27
19
|
end
|
28
|
-
|
29
20
|
end
|
30
|
-
|
31
|
-
|
32
21
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/upload_spec.rb
CHANGED