From a7dbcbcee83b91dbb20b2713b3ab6c58651b17a5 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Mon, 10 Mar 2014 11:09:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=8E=88=E6=9D=83=E5=87=AD?= =?UTF-8?q?=E8=AF=81=E7=94=9F=E6=88=90=E7=AE=97=E6=B3=95=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/qiniu/rs.rb | 4 ++-- lib/qiniu/rs/auth.rb | 2 +- lib/qiniu/rs/config.rb | 4 ++-- lib/qiniu/rs/rs.rb | 4 ++-- lib/qiniu/rs/utils.rb | 5 ++++- spec/qiniu/rs/rs_spec.rb | 11 ++++++++--- spec/qiniu/rs_spec.rb | 9 ++++++--- 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/qiniu/rs.rb b/lib/qiniu/rs.rb index d248d15..d11b0bc 100755 --- a/lib/qiniu/rs.rb +++ b/lib/qiniu/rs.rb @@ -182,12 +182,12 @@ module Qiniu end def batch_copy(*args) - code, data = RS.batch_copy(args) + code, data = RS.batch_copy(*args) code == StatusOK end def batch_move(*args) - code, data = RS.batch_move(args) + code, data = RS.batch_move(*args) code == StatusOK end diff --git a/lib/qiniu/rs/auth.rb b/lib/qiniu/rs/auth.rb index bd93a79..9955edb 100755 --- a/lib/qiniu/rs/auth.rb +++ b/lib/qiniu/rs/auth.rb @@ -59,7 +59,7 @@ module Qiniu end def call_with_signature(url, data, retry_times = 0, options = {}) - code, data = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data)}) + code, data = http_request url, data, options.merge({:qbox_signature_token => generate_qbox_signature(url, data, options[:mime])}) [code, data] end diff --git a/lib/qiniu/rs/config.rb b/lib/qiniu/rs/config.rb index 159447c..d7f65df 100755 --- a/lib/qiniu/rs/config.rb +++ b/lib/qiniu/rs/config.rb @@ -20,9 +20,9 @@ module Qiniu :method => :post, :content_type => 'application/x-www-form-urlencoded', :auth_url => "https://acc.qbox.me/oauth2/token", - :rs_host => "http://rs.qbox.me", + :rs_host => "http://rs.qiniu.com", :io_host => "http://iovip.qbox.me", - :up_host => "http://up.qbox.me", + :up_host => "http://up.qiniu.com", :pub_host => "http://pu.qbox.me:10200", :eu_host => "http://eu.qbox.me", :client_id => "a75604760c4da4caaa456c0c5895c061c3065c5a", diff --git a/lib/qiniu/rs/rs.rb b/lib/qiniu/rs/rs.rb index 79bbd1e..932b231 100755 --- a/lib/qiniu/rs/rs.rb +++ b/lib/qiniu/rs/rs.rb @@ -60,7 +60,7 @@ module Qiniu encoded_uri = encode_entry_uri(bucket, key) execs << "op=/#{command}/#{encoded_uri}" end - Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&") + Auth.request Config.settings[:rs_host] + "/batch", execs.join("&"), {:mime => "application/x-www-form-urlencoded" } end def batch_get(bucket, keys) @@ -108,7 +108,7 @@ module Qiniu op_args.each do |e| execs << 'op=' + _generate_cp_or_mv_opstr(command, e[0], e[1], e[2], e[3]) if e.size == 4 end - Auth.request Config.settings[:rs_host] + "/batch?" + execs.join("&") + Auth.request Config.settings[:rs_host] + "/batch", execs.join("&"), {:mime => "application/x-www-form-urlencoded" } end end diff --git a/lib/qiniu/rs/utils.rb b/lib/qiniu/rs/utils.rb index 3c0d169..6eb2931 100755 --- a/lib/qiniu/rs/utils.rb +++ b/lib/qiniu/rs/utils.rb @@ -127,7 +127,7 @@ module Qiniu File.open(filepath, "rb") { |f| Zlib.crc32 f.read } end - def generate_qbox_signature(url, params) + def generate_qbox_signature(url, params, mime = nil) access_key = Config.settings[:access_key] secret_key = Config.settings[:secret_key] uri = URI.parse(url) @@ -139,6 +139,9 @@ module Qiniu params_string = generate_query_string(params) signature += params_string end + if mime.is_a?(String) && mime == "application/x-www-form-urlencoded" && params.is_a?(String) + signature += params + end hmac = HMAC::SHA1.new(secret_key) hmac.update(signature) encoded_digest = urlsafe_base64_encode(hmac.digest) diff --git a/spec/qiniu/rs/rs_spec.rb b/spec/qiniu/rs/rs_spec.rb index 3e3a785..41cd19d 100755 --- a/spec/qiniu/rs/rs_spec.rb +++ b/spec/qiniu/rs/rs_spec.rb @@ -92,19 +92,24 @@ module Qiniu context ".batch_copy" do it "should works" do - code, data = Qiniu::RS::RS.batch_copy [@bucket, @key, @bucket, @key2] + code, data = Qiniu::RS::RS.batch_copy @bucket, @key, @bucket, @key2 code.should == 200 puts data.inspect #code2, data2 = Qiniu::RS::RS.stat(@bucket, @key2) #code2.should == 200 #puts data2.inspect + # + code, data = Qiniu::RS::RS.delete(@bucket, @key2) + code.should == 200 + puts data.inspect + end end context ".batch_move" do it "should works" do - code, data = Qiniu::RS::RS.batch_move [@bucket, @key, @bucket, @key2] + code, data = Qiniu::RS::RS.batch_move @bucket, @key, @bucket, @key2 code.should == 200 puts data.inspect @@ -112,7 +117,7 @@ module Qiniu #code2.should == 200 #puts data2.inspect - code3, data3 = Qiniu::RS::RS.batch_move [@bucket, @key2, @bucket, @key] + code3, data3 = Qiniu::RS::RS.batch_move @bucket, @key2, @bucket, @key code3.should == 200 puts data3.inspect end diff --git a/spec/qiniu/rs_spec.rb b/spec/qiniu/rs_spec.rb index fa2cdb3..83ba74c 100755 --- a/spec/qiniu/rs_spec.rb +++ b/spec/qiniu/rs_spec.rb @@ -298,23 +298,26 @@ module Qiniu context ".batch_copy" do it "should works" do - result = Qiniu::RS.batch_copy [@bucket, @key, @bucket, @key2] + result = Qiniu::RS.batch_copy @bucket, @key, @bucket, @key2 result.should_not be_false #result2 = Qiniu::RS.stat(@bucket, @key2) #result2.should_not be_false + + result = Qiniu::RS.delete @bucket, @key2 + result.should_not be_false end end context ".batch_move" do it "should works" do - result = Qiniu::RS::RS.batch_move [@bucket, @key, @bucket, @key2] + result = Qiniu::RS.batch_move @bucket, @key, @bucket, @key2 result.should_not be_false #result2 = Qiniu::RS.stat(@bucket, @key2) #result2.should_not be_false - result3 = Qiniu::RS.batch_move [@bucket, @key2, @bucket, @key] + result3 = Qiniu::RS.batch_move @bucket, @key2, @bucket, @key result3.should_not be_false end end