carrierwave-qiniu 0.2.1 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c31fa44d0fdafba5f24aba143952d5c5c33810d0
4
- data.tar.gz: e7ad971651fedef17c05a662e90916ecb7c4cdb8
3
+ metadata.gz: fd2c088b63699b4a104b7d9e9b727218909c0f00
4
+ data.tar.gz: f26b4ff276ef9ce1302f8a6defffb153c765e603
5
5
  SHA512:
6
- metadata.gz: 742f03dc1b02fa9d4400175f6e3885fd4a21cb486d6d4dbe64c08f9bb6049ed7eb8e67f269fb4924b0318483f64ddd68df4011e7f539e732fc8acb41718048e2
7
- data.tar.gz: e97243f33b257c4b754a9e881b9995fab0dccd26cd8ff4b340a494aa4c3084ce25e98edde0d097deed49c78b0b5e69a8151ff7755fe5c185d713cecff6b8a1f9
6
+ metadata.gz: b791a994c6807846af2d5840df21f232e8a29bab92d064633c19e0af7be5bf979fcab45d2bf3c61e42704982e6268d075ab9b2b2cb45e9366124828e031aa21e
7
+ data.tar.gz: 459eb0bbcf617d18b62f17bd1995bd7040392cd2a9f1af4bbd99d31e87f3bab39a05d7fcd2e50ddd90bb12eb01be2d6725ccc5506ece5aa0bb70d9f4326096c7
data/CHANGELOG.md CHANGED
@@ -1,7 +1,16 @@
1
1
 
2
2
  ## CHANGE LOG
3
3
 
4
+ ### v0.2.2
5
+ 增加对七牛SDK中复制图片功能的支持
6
+ https://github.com/huobazi/carrierwave-qiniu/pull/49
7
+
4
8
  ### v0.2.1
9
+ 增加
10
+
11
+ qiniu_callback_url
12
+ qiniu_callback_body
13
+ qiniu_can_overwrite
5
14
 
6
15
  https://github.com/huobazi/carrierwave-qiniu/pull/47
7
16
 
@@ -2,9 +2,10 @@
2
2
  require "carrierwave-qiniu/version"
3
3
  require "carrierwave/storage/qiniu"
4
4
  require "carrierwave/qiniu/configuration"
5
+ require "carrierwave/uploader/base"
5
6
 
6
7
  ::CarrierWave.configure do |config|
7
8
  config.storage_engines[:qiniu] = "::CarrierWave::Storage::Qiniu".freeze
8
9
  end
9
10
 
10
- ::CarrierWave::Uploader::Base.send(:include, ::CarrierWave::Qiniu::Configuration)
11
+ ::CarrierWave::Uploader::Base.send(:include, ::CarrierWave::Qiniu::Configuration)
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Carrierwave
3
3
  module Qiniu
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.2"
5
5
  end
6
6
  end
@@ -9,20 +9,20 @@ module CarrierWave
9
9
 
10
10
  class Connection
11
11
  def initialize(options={})
12
- @qiniu_bucket_domain = options[:qiniu_bucket_domain]
13
- @qiniu_bucket = options[:qiniu_bucket]
14
- @qiniu_bucket_private= options[:qiniu_bucket_private] || false
15
- @qiniu_access_key = options[:qiniu_access_key]
16
- @qiniu_secret_key = options[:qiniu_secret_key]
17
- @qiniu_block_size = options[:qiniu_block_size] || 1024*1024*4
18
- @qiniu_protocol = options[:qiniu_protocol] || "http"
19
- @qiniu_async_ops = options[:qiniu_async_ops] || ''
20
- @qiniu_can_overwrite = options[:qiniu_can_overwrite] || false
21
- @qiniu_expires_in = options[:qiniu_expires_in] || options[:expires_in] || 3600
22
- @qiniu_up_host = options[:qiniu_up_host]
12
+ @qiniu_bucket_domain = options[:qiniu_bucket_domain]
13
+ @qiniu_bucket = options[:qiniu_bucket]
14
+ @qiniu_bucket_private = options[:qiniu_bucket_private] || false
15
+ @qiniu_access_key = options[:qiniu_access_key]
16
+ @qiniu_secret_key = options[:qiniu_secret_key]
17
+ @qiniu_block_size = options[:qiniu_block_size] || 1024*1024*4
18
+ @qiniu_protocol = options[:qiniu_protocol] || "http"
19
+ @qiniu_async_ops = options[:qiniu_async_ops] || ''
20
+ @qiniu_can_overwrite = options[:qiniu_can_overwrite] || false
21
+ @qiniu_expires_in = options[:qiniu_expires_in] || options[:expires_in] || 3600
22
+ @qiniu_up_host = options[:qiniu_up_host]
23
23
  @qiniu_private_url_expires_in = options[:qiniu_private_url_expires_in] || 3600
24
- @qiniu_callback_url = options[:qiniu_callback_url] || ''
25
- @qiniu_callback_body = options[:qiniu_callback_body] || ''
24
+ @qiniu_callback_url = options[:qiniu_callback_url] || ''
25
+ @qiniu_callback_body = options[:qiniu_callback_body] || ''
26
26
  @qiniu_persistent_notify_url = options[:qiniu_persistent_notify_url] || ''
27
27
  init
28
28
  end
@@ -37,9 +37,9 @@ module CarrierWave
37
37
  @qiniu_expires_in,
38
38
  nil
39
39
  )
40
- put_policy.persistent_ops = @qiniu_async_ops
41
- put_policy.callback_url = @qiniu_callback_url if @qiniu_callback_url.present?
42
- put_policy.callback_body = @qiniu_callback_body if @qiniu_callback_body.present?
40
+ put_policy.persistent_ops = @qiniu_async_ops
41
+ put_policy.callback_url = @qiniu_callback_url if @qiniu_callback_url.present?
42
+ put_policy.callback_body = @qiniu_callback_body if @qiniu_callback_body.present?
43
43
  put_policy.persistent_notify_url = @qiniu_persistent_notify_url if @qiniu_persistent_notify_url.present?
44
44
 
45
45
  ::Qiniu::Storage.upload_with_put_policy(
@@ -50,6 +50,17 @@ module CarrierWave
50
50
 
51
51
  end
52
52
 
53
+ #
54
+ # @note 复制
55
+ # @param origin [String]
56
+ # @param target [String]
57
+ # @return [Boolean]
58
+ #
59
+ def copy(origin, target)
60
+ code, result, _ = ::Qiniu::Storage.copy(@qiniu_bucket, origin, @qiniu_bucket, target)
61
+ code == 200 ? result : nil
62
+ end
63
+
53
64
  def delete(key)
54
65
  ::Qiniu::Storage.delete(@qiniu_bucket, key) rescue nil
55
66
  end
@@ -89,7 +100,7 @@ module CarrierWave
89
100
  :user_agent => UserAgent
90
101
  }
91
102
  options[:block_size] = @qiniu_block_size if @qiniu_block_size
92
- options[:up_host] = @qiniu_up_host if @qiniu_up_host
103
+ options[:up_host] = @qiniu_up_host if @qiniu_up_host
93
104
 
94
105
  ::Qiniu.establish_connection! options
95
106
 
@@ -119,6 +130,22 @@ module CarrierWave
119
130
  qiniu_connection.delete(@path)
120
131
  end
121
132
 
133
+
134
+
135
+ #
136
+ # @note 从指定路径复制图片
137
+ # @param origin_path [String] 原图片路径
138
+ # @return [Boolean]
139
+ #
140
+ def copy_from(origin_path)
141
+
142
+ # 先删除目标图片,避免出现0字节文件,无法复制
143
+ qiniu_connection.delete(@path)
144
+
145
+ qiniu_connection.copy(origin_path, @path)
146
+
147
+ end
148
+
122
149
  ##
123
150
  # Reads the contents of the file from Cloud Files
124
151
  #
@@ -173,7 +200,11 @@ module CarrierWave
173
200
 
174
201
  def store!(file)
175
202
  f = ::CarrierWave::Storage::Qiniu::File.new(uploader, uploader.store_path(uploader.filename))
176
- f.store(file)
203
+ if file && file.copy_from_path
204
+ f.copy_from file.copy_from_path
205
+ else
206
+ f.store(file)
207
+ end
177
208
  f
178
209
  end
179
210
 
@@ -183,4 +214,4 @@ module CarrierWave
183
214
 
184
215
  end
185
216
  end
186
- end
217
+ end
@@ -0,0 +1,35 @@
1
+ #encoding: utf-8
2
+ module CarrierWave
3
+
4
+ class SanitizedFile
5
+
6
+ attr_accessor :copy_from_path
7
+
8
+ end
9
+
10
+ module Uploader
11
+ module Cache
12
+
13
+ alias_method :old_cache!, :cache!
14
+
15
+ def cache!(new_file = sanitized_file)
16
+
17
+ old_cache! new_file
18
+
19
+ if new_file.kind_of? CarrierWave::Storage::Qiniu::File
20
+
21
+ @file.copy_from_path = new_file.path
22
+
23
+ elsif new_file.kind_of? CarrierWave::Uploader::Base
24
+
25
+ @file.copy_from_path = new_file.file.path
26
+
27
+ end
28
+
29
+ end
30
+ end
31
+
32
+ end
33
+
34
+
35
+ end
data/spec/upload_spec.rb CHANGED
@@ -93,5 +93,25 @@ require 'carrierwave/processing/mini_magick'
93
93
  open(photo.image.thumb.url).should_not be_nil
94
94
 
95
95
  end
96
+
97
+ it 'does copy from image works' do
98
+ f = load_file("mm.jpg")
99
+
100
+ photo = Photo.new(image: f)
101
+
102
+ photo.save
103
+
104
+ photo2 = Photo.new
105
+
106
+ photo2.image = photo.image
107
+
108
+ photo2.save
109
+
110
+ puts "The image was copied from #{photo.image.url} to #{photo2.image.url}"
111
+
112
+ expect(photo2.image.url).not_to eq(photo.image.url)
113
+
114
+ open(photo2.image.url).should_not be_nil
115
+ end
96
116
  end
97
117
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-qiniu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marble Wu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-18 00:00:00.000000000 Z
11
+ date: 2016-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -57,6 +57,7 @@ files:
57
57
  - lib/carrierwave-qiniu/version.rb
58
58
  - lib/carrierwave/qiniu/configuration.rb
59
59
  - lib/carrierwave/storage/qiniu.rb
60
+ - lib/carrierwave/uploader/base.rb
60
61
  - spec/mm.jpg
61
62
  - spec/spec_helper.rb
62
63
  - spec/upload_spec.rb