为authorize_download_url()添加:fop参数,以便生成含FOP指令的授权下载URL。

This commit is contained in:
Liang Tao
2014-06-04 14:40:23 +08:00
parent a424c79dd6
commit 1f6e9ba47b
2 changed files with 24 additions and 7 deletions
+17 -6
View File
@@ -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
### 生成数字签名
+7 -1
View File
@@ -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)