66use Qiniu \Http \Error ;
77use Qiniu \Http \Client ;
88use Qiniu \Http \Proxy ;
9+ use Qiniu \Zone ;
910
1011/**
1112 * 持久化处理类,该类用于主动触发异步持久化操作.
@@ -45,25 +46,34 @@ public function __construct($auth, $config = null, $proxy = null, $proxy_auth =
4546 * 对资源文件进行异步持久化处理
4647 * @param string $bucket 资源所在空间
4748 * @param string $key 待处理的源文件
48- * @param string $fops string |array 待处理的pfop操作,多个pfop操作以array的形式传入。
49+ * @param string|array $fops 待处理的pfop操作,多个pfop操作以array的形式传入。
4950 * eg. avthumb/mp3/ab/192k, vframe/jpg/offset/7/w/480/h/360
5051 * @param string $pipeline 资源处理队列
5152 * @param string $notify_url 处理结果通知地址
5253 * @param bool $force 是否强制执行一次新的指令
54+ * @param int $type 为 `1` 时开启闲时任务
5355 *
5456 *
55- * @return array 返回持久化处理的persistentId, 和返回的错误 。
57+ * @return array 返回持久化处理的 persistentId 与可能出现的错误 。
5658 *
5759 * @link http://developer.qiniu.com/docs/v6/api/reference/fop/
5860 */
59- public function execute ($ bucket , $ key , $ fops , $ pipeline = null , $ notify_url = null , $ force = false )
60- {
61+ public function execute (
62+ $ bucket ,
63+ $ key ,
64+ $ fops ,
65+ $ pipeline = null ,
66+ $ notify_url = null ,
67+ $ force = false ,
68+ $ type = null
69+ ) {
6170 if (is_array ($ fops )) {
6271 $ fops = implode ('; ' , $ fops );
6372 }
6473 $ params = array ('bucket ' => $ bucket , 'key ' => $ key , 'fops ' => $ fops );
6574 \Qiniu \setWithoutEmpty ($ params , 'pipeline ' , $ pipeline );
6675 \Qiniu \setWithoutEmpty ($ params , 'notifyURL ' , $ notify_url );
76+ \Qiniu \setWithoutEmpty ($ params , 'type ' , $ type );
6777 if ($ force ) {
6878 $ params ['force ' ] = 1 ;
6979 }
@@ -72,7 +82,8 @@ public function execute($bucket, $key, $fops, $pipeline = null, $notify_url = nu
7282 if ($ this ->config ->useHTTPS === true ) {
7383 $ scheme = "https:// " ;
7484 }
75- $ url = $ scheme . Config::API_HOST . '/pfop/ ' ;
85+ $ apiHost = $ this ->getApiHost ();
86+ $ url = $ scheme . $ apiHost . '/pfop/ ' ;
7687 $ headers = $ this ->auth ->authorization ($ url , $ data , 'application/x-www-form-urlencoded ' );
7788 $ headers ['Content-Type ' ] = 'application/x-www-form-urlencoded ' ;
7889 $ response = Client::post ($ url , $ data , $ headers , $ this ->proxy ->makeReqOpt ());
@@ -84,18 +95,33 @@ public function execute($bucket, $key, $fops, $pipeline = null, $notify_url = nu
8495 return array ($ id , null );
8596 }
8697
98+ /**
99+ * @param string $id
100+ * @return array 返回任务状态与可能出现的错误
101+ */
87102 public function status ($ id )
88103 {
89104 $ scheme = "http:// " ;
90105
91106 if ($ this ->config ->useHTTPS === true ) {
92107 $ scheme = "https:// " ;
93108 }
94- $ url = $ scheme . Config::API_HOST . "/status/get/prefop?id= $ id " ;
109+ $ apiHost = $ this ->getApiHost ();
110+ $ url = $ scheme . $ apiHost . "/status/get/prefop?id= $ id " ;
95111 $ response = Client::get ($ url , array (), $ this ->proxy ->makeReqOpt ());
96112 if (!$ response ->ok ()) {
97113 return array (null , new Error ($ url , $ response ));
98114 }
99115 return array ($ response ->json (), null );
100116 }
117+
118+ private function getApiHost ()
119+ {
120+ if (!empty ($ this ->config ->zone ) && !empty ($ this ->config ->zone ->apiHost )) {
121+ $ apiHost = $ this ->config ->zone ->apiHost ;
122+ } else {
123+ $ apiHost = Config::API_HOST ;
124+ }
125+ return $ apiHost ;
126+ }
101127}
0 commit comments