From 1f6e9ba47ba085e3c943a1e595817e9998df51c0 Mon Sep 17 00:00:00 2001 From: Liang Tao Date: Wed, 4 Jun 2014 14:40:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BAauthorize=5Fdownload=5Furl()=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0:fop=E5=8F=82=E6=95=B0=EF=BC=8C=E4=BB=A5=E4=BE=BF?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=90=ABFOP=E6=8C=87=E4=BB=A4=E7=9A=84?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E4=B8=8B=E8=BD=BDURL=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/qiniu/auth.rb | 23 +++++++++++++++++------ spec/qiniu/auth_spec.rb | 8 +++++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/qiniu/auth.rb b/lib/qiniu/auth.rb index 7df31b6..cf379f3 100755 --- a/lib/qiniu/auth.rb +++ b/lib/qiniu/auth.rb @@ -51,15 +51,13 @@ module Qiniu :callback_body => "callbackBody" , :persistent_ops => "persistentOps" , :persistent_notify_url => "persistentNotifyUrl" , - :transform => "transform" , # 数值类型参数 :deadline => "deadline" , :insert_only => "insertOnly" , :fsize_limit => "fsizeLimit" , :detect_mime => "detectMime" , - :mime_limit => "mimeLimit" , - :fop_timeout => "fopTimeout" + :mime_limit => "mimeLimit" } # PARAMS public @@ -140,16 +138,29 @@ module Qiniu access_key = Config.settings[:access_key] secret_key = Config.settings[:secret_key] + download_url = url + + ### URL变换:追加FOP指令 + if args[:fop].is_a?(String) && args[:fop] != '' then + if download_url.index('?').is_a?(Fixnum) then + # 已有参数 + download_url = "#{download_url}&#{args[:fop]}" + else + # 尚无参数 + download_url = "#{download_url}?#{args[:fop]}" + end + end + ### 授权期计算 e = Auth.calculate_deadline(args[:expires_in], args[:deadline]) ### URL变换:追加授权期参数 - if url.index('?').is_a?(Fixnum) then + if download_url.index('?').is_a?(Fixnum) then # 已有参数 - download_url = "#{url}&e=#{e}" + download_url = "#{download_url}&e=#{e}" else # 尚无参数 - download_url = "#{url}?e=#{e}" + download_url = "#{download_url}?e=#{e}" end ### 生成数字签名 diff --git a/spec/qiniu/auth_spec.rb b/spec/qiniu/auth_spec.rb index afb54bc..c8a7a81 100755 --- a/spec/qiniu/auth_spec.rb +++ b/spec/qiniu/auth_spec.rb @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- +# vim: sw=2 ts=2 require 'spec_helper' require 'qiniu/auth' @@ -56,7 +57,12 @@ module Qiniu result.body.should_not be_empty ### 授权下载地址(带参数) - download_url = Qiniu::Auth.authorize_download_url(url + '?download/a.m3u8') + download_url = Qiniu::Auth.authorize_download_url( + url, + { + :fop => 'download/a.m3u8' + } + ) puts "download_url=#{download_url}" result = RestClient.get(download_url)