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)