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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88ad15a88d231142af19a674cb9b98a3d59fa043983627e8e05019f9437c4edf
4
- data.tar.gz: 920e9ce74941e1fea40653adc4dd6e206563da0685ea603d12dd17a62919baeb
3
+ metadata.gz: 1f8f66a9de516d766326b6b71a4458118c1c7a65efb8d658db6a1d3461211afa
4
+ data.tar.gz: 287a017867010ed5c08e090716b5b42c22d46e74f90deb0365d523c982f0cd0a
5
5
  SHA512:
6
- metadata.gz: df7664665d316e856e66222267d81539cde36b2c926fd4bb3be9e3a9eb96dbfa0752c78829e353657ee665529fa7c36d19f4cb805115dfed2c3a168201b08b64
7
- data.tar.gz: 378869166a509fc117a2134fb565e4eca59d81dd9e7dc579fdf9c30598b9d155acfb094401b73b25f8afd93a5bcdf08dfd510c1aa71525553046d4b9e4789bd4
6
+ metadata.gz: '08df3bb2b5aaeecc01e642da1626d43b915850403550573af8e0a5f9c722ad93da768e77a011c260fe84b7f5d79f6d1e1ef6554ba4b5db22434d3114452acdd2'
7
+ data.tar.gz: b9231fd84b073877b26deffc7fe495386510af8aac24e945153f481831aa90c6aeae571215e5bd6e6f6470c842fde2d3b4535745fb6cf541337431508e54c239
data/.gitignore CHANGED
@@ -17,3 +17,5 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  uploads/
20
+ .idea/
21
+ .rakeTasks
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
 
2
2
  ## CHANGE LOG
3
3
 
4
+ ### v1.2.1
5
+
6
+ - Implement of cache* method for carrierwave 2.0
7
+
4
8
  ### v1.2.0
5
9
 
6
10
  - Fit to carrierwave 2.0 (支持 CarrierWave 2.0)
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Carrierwave::Qiniu
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/carrierwave-qiniu@2x.png?1.1.8)](http://badge.fury.io/rb/carrierwave-qiniu)
3
+ [![Gem Version](https://badge.fury.io/rb/carrierwave-qiniu@2x.png?1.2.1)](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.8'
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.8
22
+ $ gem install carrierwave-qiniu -v 1.2.1
23
23
 
24
24
  ## Usage
25
25
 
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Carrierwave
3
3
  module Qiniu
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
  end
6
6
  end
@@ -50,6 +50,7 @@ module CarrierWave
50
50
  config.qiniu_style_separator = '-'
51
51
  config.qiniu_style_inline = false
52
52
  config.qiniu_delete_after_days = 0
53
+ config.cache_storage = :file
53
54
  end
54
55
  end
55
56
 
@@ -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
@@ -38,7 +38,6 @@ end
38
38
  # 或者在根目录下新建 `.env` 文件,包含 <key>=<value>
39
39
  ::CarrierWave.configure do |config|
40
40
  config.storage = :qiniu
41
- config.cache_storage = :file
42
41
  config.qiniu_access_key = ENV["qiniu_access_key"]
43
42
  config.qiniu_secret_key = ENV["qiniu_secret_key"]
44
43
 
data/spec/upload_spec.rb CHANGED
@@ -103,7 +103,6 @@ describe "CarrierWave Qiniu" do
103
103
 
104
104
  URI.open(photo.image.url).should_not be_nil
105
105
 
106
-
107
106
  puts "The thumb image:"
108
107
  puts photo.image.url(:thumb)
109
108
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marble Wu