carrierwave-qiniu 0.1.8 → 0.1.8.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 -1
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/lib/carrierwave/storage/qiniu.rb +21 -36
- data/lib/carrierwave-qiniu/version.rb +1 -1
- data/lib/carrierwave-qiniu.rb +1 -1
- data/spec/spec_helper.rb +9 -5
- data/spec/upload_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce0788a33edf4b269a2f351ee329b23ff8447f10
|
4
|
+
data.tar.gz: 78414ebcc9b2bfee47ba3a92a8e33118b561f81c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf2a596f92ffca378a6f60ef023dbc358775c35f6cb4695fc1df66706159d7ec6e8c265bcb849e289517a8217c30073bf37fb9bfe0c93a5b27b88ec894269ee5
|
7
|
+
data.tar.gz: d8372b8f85ba30d4c650492e3e4ec2d425b0e3dd9c8f50f3f01e6970e5a634e74d2356bc583cb7ae98f2083c5a08f70f59bdf11038055f0f92b74e9bae6575b8
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
|
2
2
|
## CHANGE LOG
|
3
3
|
|
4
|
+
### v0.1.8.1
|
5
|
+
|
6
|
+
https://github.com/huobazi/carrierwave-qiniu/pull/36
|
7
|
+
|
8
|
+
https://github.com/huobazi/carrierwave-qiniu/pull/38
|
9
|
+
|
4
10
|
### v0.1.7
|
5
11
|
|
6
12
|
- 添加从云端读取(下载)文件 。 [https://github.com/huobazi/carrierwave-qiniu/pull/27](https://github.com/huobazi/carrierwave-qiniu/pull/27)
|
7
13
|
|
8
14
|
- 增加获取有时效性url链接地址的方法 。 [https://github.com/huobazi/carrierwave-qiniu/issues/25](https://github.com/huobazi/carrierwave-qiniu/issues/25)
|
15
|
+
|
16
|
+
- 升级七牛 SDK 至 6.4.2
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Carrierwave::Qiniu
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/carrierwave-qiniu)
|
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
|
example: https://github.com/huobazi/carrierwave-qiniu-example
|
@@ -36,7 +36,7 @@ module CarrierWave
|
|
36
36
|
)
|
37
37
|
put_policy.persistent_ops = @qiniu_async_ops
|
38
38
|
|
39
|
-
|
39
|
+
::Qiniu::Storage.upload_with_put_policy(
|
40
40
|
put_policy,
|
41
41
|
file.path,
|
42
42
|
key
|
@@ -45,29 +45,27 @@ module CarrierWave
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def delete(key)
|
48
|
-
|
49
|
-
::Qiniu::Storage.delete(@qiniu_bucket, key)
|
50
|
-
rescue Exception
|
51
|
-
nil
|
52
|
-
end
|
48
|
+
::Qiniu::Storage.delete(@qiniu_bucket, key) rescue nil
|
53
49
|
end
|
54
50
|
|
55
51
|
def stat(key)
|
56
|
-
code, result,
|
52
|
+
code, result, _ = ::Qiniu::Storage.stat(@qiniu_bucket, key)
|
57
53
|
code == 200 ? result : {}
|
58
54
|
end
|
59
55
|
|
60
56
|
def get(path)
|
61
|
-
code, result,
|
57
|
+
code, result, _ = ::Qiniu::HTTP.get( download_url(path) )
|
62
58
|
code == 200 ? result : nil
|
63
59
|
end
|
64
60
|
|
65
61
|
def download_url(path)
|
66
|
-
|
67
|
-
encode_path = URI.escape(path, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) #fix chinese file name, same as encodeURIComponent in js
|
62
|
+
encode_path = URI.escape(path) #fix chinese file name, same as encodeURIComponent in js but preserve slash '/'
|
68
63
|
primitive_url = "#{@qiniu_protocol}://#{@qiniu_bucket_domain}/#{encode_path}"
|
69
|
-
|
70
|
-
|
64
|
+
@qiniu_bucket_private ? \
|
65
|
+
::Qiniu::Auth.authorize_download_url(primitive_url, :expires_in => @qiniu_private_url_expires_in) \
|
66
|
+
: \
|
67
|
+
primitive_url
|
68
|
+
|
71
69
|
end
|
72
70
|
|
73
71
|
private
|
@@ -76,14 +74,16 @@ module CarrierWave
|
|
76
74
|
init_qiniu_rs_connection
|
77
75
|
end
|
78
76
|
|
77
|
+
UserAgent = "CarrierWave-Qiniu/#{Carrierwave::Qiniu::VERSION} (#{RUBY_PLATFORM}) Ruby/#{RUBY_VERSION}".freeze
|
78
|
+
|
79
79
|
def init_qiniu_rs_connection
|
80
80
|
options = {
|
81
81
|
:access_key => @qiniu_access_key,
|
82
82
|
:secret_key => @qiniu_secret_key,
|
83
|
-
:user_agent =>
|
83
|
+
:user_agent => UserAgent
|
84
84
|
}
|
85
|
-
options
|
86
|
-
options
|
85
|
+
options[:block_size] = @qiniu_block_size if @qiniu_block_size
|
86
|
+
options[:up_host] = @qiniu_up_host if @qiniu_up_host
|
87
87
|
|
88
88
|
::Qiniu.establish_connection! options
|
89
89
|
|
@@ -125,7 +125,7 @@ module CarrierWave
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def content_type
|
128
|
-
file_info['mimeType'] || 'application/octet-stream'
|
128
|
+
file_info['mimeType'] || 'application/octet-stream'.freeze
|
129
129
|
end
|
130
130
|
|
131
131
|
def size
|
@@ -135,9 +135,7 @@ module CarrierWave
|
|
135
135
|
private
|
136
136
|
|
137
137
|
def qiniu_connection
|
138
|
-
|
139
|
-
@qiniu_connection
|
140
|
-
else
|
138
|
+
@qiniu_connection ||= begin
|
141
139
|
config = {
|
142
140
|
:qiniu_access_key => @uploader.qiniu_access_key,
|
143
141
|
:qiniu_secret_key => @uploader.qiniu_secret_key,
|
@@ -151,23 +149,10 @@ module CarrierWave
|
|
151
149
|
:qiniu_private_url_expires_in => @uploader.qiniu_private_url_expires_in
|
152
150
|
}
|
153
151
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
config.merge!(:qiniu_async_ops => @uploader.qiniu_async_ops)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
if @uploader.respond_to?(:qiniu_can_overwrite) and !@uploader.qiniu_can_overwrite.nil?
|
163
|
-
if @uploader.qiniu_can_overwrite.is_a?(TrueClass) or @uploader.is_a?(FalseClass)
|
164
|
-
config.merge!(:qiniu_can_overwrite => @uploader.qiniu_can_overwrite)
|
165
|
-
else
|
166
|
-
config.merge!(:qiniu_can_overwrite => false)
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
@qiniu_connection ||= Connection.new config
|
152
|
+
config[:qiniu_async_ops] = Array(@uploader.qiniu_async_ops).join(';') rescue ''
|
153
|
+
config[:qiniu_can_overwrite] = @uploader.try :qiniu_can_overwrite rescue false
|
154
|
+
|
155
|
+
Connection.new config
|
171
156
|
end
|
172
157
|
end
|
173
158
|
|
data/lib/carrierwave-qiniu.rb
CHANGED
@@ -4,7 +4,7 @@ require "carrierwave/qiniu/configuration"
|
|
4
4
|
require "carrierwave-qiniu/version"
|
5
5
|
|
6
6
|
::CarrierWave.configure do |config|
|
7
|
-
config.storage_engines
|
7
|
+
config.storage_engines[:qiniu] = "::CarrierWave::Storage::Qiniu".freeze
|
8
8
|
end
|
9
9
|
|
10
10
|
::CarrierWave::Uploader::Base.send(:include, ::CarrierWave::Qiniu::Configuration)
|
data/spec/spec_helper.rb
CHANGED
@@ -6,6 +6,7 @@ require "rails"
|
|
6
6
|
require "active_record"
|
7
7
|
require "carrierwave"
|
8
8
|
require "carrierwave/orm/activerecord"
|
9
|
+
require 'dotenv'
|
9
10
|
|
10
11
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
11
12
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"..","lib"))
|
@@ -20,16 +21,19 @@ module Rails
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
24
|
+
Dotenv.load
|
25
|
+
|
23
26
|
ActiveRecord::Migration.verbose = false
|
24
27
|
|
25
|
-
#
|
28
|
+
# 测试的时候载入环境变量
|
29
|
+
# 或者在根目录下新建 `.env` 文件,包含 <key>=<value>
|
26
30
|
::CarrierWave.configure do |config|
|
27
31
|
config.storage = :qiniu
|
28
|
-
config.qiniu_access_key =
|
29
|
-
config.qiniu_secret_key =
|
32
|
+
config.qiniu_access_key = ENV['qiniu_access_key']
|
33
|
+
config.qiniu_secret_key = ENV['qiniu_secret_key']
|
30
34
|
|
31
|
-
config.qiniu_bucket =
|
32
|
-
config.qiniu_bucket_domain =
|
35
|
+
config.qiniu_bucket = ENV['qiniu_bucket']
|
36
|
+
config.qiniu_bucket_domain = ENV['qiniu_bucket_domain']
|
33
37
|
|
34
38
|
config.qiniu_block_size = 4*1024*1024
|
35
39
|
config.qiniu_protocol = "http"
|
data/spec/upload_spec.rb
CHANGED
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.1.8
|
4
|
+
version: 0.1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marble Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|