carrierwave-qiniu 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/LICENSE +2 -2
- data/README.md +3 -1
- data/carrierwave-qiniu.gemspec +2 -1
- data/lib/carrierwave/qiniu/configuration.rb +17 -18
- data/lib/carrierwave/storage/qiniu.rb +16 -5
- data/lib/carrierwave-qiniu/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b044a1ac28aea84db7adb5190619a2de43ee8cc0
|
4
|
+
data.tar.gz: 6b4edd18e16dc3f09123bf534c6f30378c6b7160
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52fcfbbdfd26eb4faf7f6f0be932503d1c61c59b208be441e7b96b4e0032ffb379816f170d01ec474a53c64da09fc91b10da2c2fc7c93f141be62051cfa1aa2a
|
7
|
+
data.tar.gz: 2171171a2c871055ba0276d706f90473d5c071230c93a98dd3f757f8844837123f3e5c070bd4e9b75f1228780f73747cc9895f567dd42270a2643fa88592ad6d
|
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012
|
1
|
+
Copyright (c) 2012 Marble Wu
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ You'll need to configure it in config/initializes/carrierwave.rb
|
|
30
30
|
config.qiniu_bucket = "carrierwave-qiniu-example"
|
31
31
|
config.qiniu_bucket_domain = "carrierwave-qiniu-example.aspxboy.com"
|
32
32
|
config.qiniu_block_size = 4*1024*1024
|
33
|
-
config.
|
33
|
+
config.qiniu_protocol = "http"
|
34
34
|
end
|
35
35
|
```
|
36
36
|
|
@@ -52,6 +52,8 @@ class AvatarUploader < CarrierWave::Uploader::Base
|
|
52
52
|
|
53
53
|
self.qiniu_bucket = "avatars"
|
54
54
|
self.qiniu_bucket_domain = "avatars.files.example.com"
|
55
|
+
self.qiniu_protocal = 'http'
|
56
|
+
self.qiniu_can_overwrite = true
|
55
57
|
|
56
58
|
# See also:
|
57
59
|
# https://github.com/qiniu/ruby-sdk/issues/48
|
data/carrierwave-qiniu.gemspec
CHANGED
@@ -2,11 +2,12 @@
|
|
2
2
|
require File.expand_path('../lib/carrierwave-qiniu/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["
|
5
|
+
gem.authors = ["Marble Wu"]
|
6
6
|
gem.email = ["huobazi@gmail.com"]
|
7
7
|
gem.description = %q{Qiniu Storage support for CarrierWave}
|
8
8
|
gem.summary = %q{Qiniu Storage support for CarrierWave}
|
9
9
|
gem.homepage = "https://github.com/huobazi/carrierwave-qiniu"
|
10
|
+
gem.license = "MIT"
|
10
11
|
|
11
12
|
gem.files = `git ls-files`.split($\)
|
12
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -10,31 +10,30 @@ module CarrierWave
|
|
10
10
|
add_config :qiniu_access_key
|
11
11
|
add_config :qiniu_secret_key
|
12
12
|
add_config :qiniu_block_size
|
13
|
-
add_config :
|
13
|
+
add_config :qiniu_protocol
|
14
|
+
add_config :qiniu_async_ops
|
15
|
+
add_config :qiniu_can_overwrite
|
16
|
+
|
17
|
+
alias_config :qiniu_protocal, :qiniu_protocol
|
14
18
|
end
|
15
|
-
end
|
16
19
|
|
17
|
-
|
18
|
-
|
20
|
+
module ClassMethods
|
21
|
+
def alias_config(new_name, old_name)
|
19
22
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
name = superclass.#{name}
|
24
|
-
return nil if name.nil? && !instance_variable_defined?("@#{name}")
|
25
|
-
@#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name
|
26
|
-
end
|
23
|
+
def self.#{new_name}(value=nil)
|
24
|
+
self.#{old_name}(value)
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def self.#{new_name}=(value)
|
28
|
+
self.#{old_name}=(value)
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
31
|
+
def #{new_name}
|
32
|
+
#{old_name}
|
33
|
+
end
|
36
34
|
RUBY
|
37
35
|
end
|
36
|
+
end
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
@@ -13,14 +13,17 @@ module CarrierWave
|
|
13
13
|
@qiniu_access_key = options[:qiniu_access_key]
|
14
14
|
@qiniu_secret_key = options[:qiniu_secret_key]
|
15
15
|
@qiniu_block_size = options[:qiniu_block_size] || 1024*1024*4
|
16
|
-
@
|
16
|
+
@qiniu_protocol = options[:qiniu_protocol] || options[:qiniu_protocal] || "http"
|
17
17
|
@qiniu_async_ops = options[:qiniu_async_ops] || ''
|
18
|
+
@qiniu_can_overwrite = options[:qiniu_can_overwrite] || false
|
18
19
|
init
|
19
20
|
end
|
20
21
|
|
21
22
|
def store(file, key)
|
23
|
+
qiniu_upload_scope = @qiniu_bucket
|
24
|
+
qiniu_upload_scope = @qiniu_bucket + ':' + key if @qiniu_can_overwrite
|
22
25
|
token_opts = {
|
23
|
-
:scope =>
|
26
|
+
:scope => qiniu_upload_scope, :expires_in => 3600 # https://github.com/qiniu/ruby-sdk/pull/15
|
24
27
|
}
|
25
28
|
token_opts.merge!(:async_options => @qiniu_async_ops) if @qiniu_async_ops.size > 0
|
26
29
|
|
@@ -49,7 +52,7 @@ module CarrierWave
|
|
49
52
|
|
50
53
|
def get_public_url(key)
|
51
54
|
if @qiniu_bucket_domain and @qiniu_bucket_domain.size > 0
|
52
|
-
"#{@
|
55
|
+
"#{@qiniu_protocol}://#{@qiniu_bucket_domain}/#{key}"
|
53
56
|
else
|
54
57
|
res = ::Qiniu::RS.get(@qiniu_bucket, key)
|
55
58
|
if res
|
@@ -93,7 +96,7 @@ module CarrierWave
|
|
93
96
|
|
94
97
|
def url
|
95
98
|
if @uploader.qiniu_bucket_domain and @uploader.qiniu_bucket_domain.size > 0
|
96
|
-
"#{@uploader.
|
99
|
+
"#{@uploader.qiniu_protocol || 'http'}://#{@uploader.qiniu_bucket_domain}/#{@path}"
|
97
100
|
else
|
98
101
|
qiniu_connection.get_public_url(@path)
|
99
102
|
end
|
@@ -119,7 +122,7 @@ module CarrierWave
|
|
119
122
|
:qiniu_bucket => @uploader.qiniu_bucket,
|
120
123
|
:qiniu_bucket_domain => @uploader.qiniu_bucket_domain,
|
121
124
|
:qiniu_block_size => @uploader.qiniu_block_size,
|
122
|
-
:
|
125
|
+
:qiniu_protocol => @uploader.qiniu_protocol
|
123
126
|
}
|
124
127
|
|
125
128
|
if @uploader.respond_to?(:qiniu_async_ops) and !@uploader.qiniu_async_ops.nil? and @uploader.qiniu_async_ops.size > 0
|
@@ -130,6 +133,14 @@ module CarrierWave
|
|
130
133
|
end
|
131
134
|
end
|
132
135
|
|
136
|
+
if @uploader.respond_to?(:qiniu_can_overwrite) and !@uploader.qiniu_can_overwrite.nil?
|
137
|
+
if @uploader.qiniu_can_overwrite.is_a?(TrueClass) or @uploader.is_a?(FalseClass)
|
138
|
+
config.merge!(:qiniu_can_overwrite => @uploader.qiniu_can_overwrite)
|
139
|
+
else
|
140
|
+
config.merge!(:qiniu_can_overwrite => false)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
133
144
|
@qiniu_connection ||= Connection.new config
|
134
145
|
end
|
135
146
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -30,7 +30,7 @@ ActiveRecord::Migration.verbose = false
|
|
30
30
|
config.qiniu_bucket = "spec-test"
|
31
31
|
config.qiniu_bucket_domain = "spec-test.qiniudn.com"
|
32
32
|
config.qiniu_block_size = 4*1024*1024
|
33
|
-
config.
|
33
|
+
config.qiniu_protocol = "http"
|
34
34
|
end
|
35
35
|
|
36
36
|
def load_file(fname)
|
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.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Marble Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -59,7 +59,8 @@ files:
|
|
59
59
|
- spec/spec_helper.rb
|
60
60
|
- spec/upload_spec.rb
|
61
61
|
homepage: https://github.com/huobazi/carrierwave-qiniu
|
62
|
-
licenses:
|
62
|
+
licenses:
|
63
|
+
- MIT
|
63
64
|
metadata: {}
|
64
65
|
post_install_message:
|
65
66
|
rdoc_options: []
|
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
version: '0'
|
78
79
|
requirements: []
|
79
80
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.2.2
|
81
82
|
signing_key:
|
82
83
|
specification_version: 4
|
83
84
|
summary: Qiniu Storage support for CarrierWave
|