@@ -137,10 +137,12 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public function existsFolder($namespace, $dir) |
| 139 | 139 | {
|
| 140 | - if (empty($namespace) || empty($dir)) |
|
| 141 | - return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
|
|
| 142 | - if (strpos($dir, '/') !== 0) |
|
| 143 | - $dir = '/' . $dir; |
|
| 140 | + if (empty($namespace) || empty($dir)) {
|
|
| 141 | + return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
|
|
| 142 | + } |
|
| 143 | + if (strpos($dir, '/') !== 0) {
|
|
| 144 | + $dir = '/' . $dir; |
|
| 145 | + } |
|
| 144 | 146 | $resourceInfo = new ResourceInfo($namespace, $dir); |
| 145 | 147 | $resourceId = $resourceInfo->buildResourceId(); //得到资源ID |
| 146 | 148 | $uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId . '/exist'; |
@@ -155,10 +157,12 @@ discard block |
||
| 155 | 157 | */ |
| 156 | 158 | public function createDir($namespace, $dir) |
| 157 | 159 | {
|
| 158 | - if (empty($namespace) || empty($dir)) |
|
| 159 | - return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
|
|
| 160 | - if (strpos($dir, '/') !== 0) |
|
| 161 | - $dir = '/' . $dir; |
|
| 160 | + if (empty($namespace) || empty($dir)) {
|
|
| 161 | + return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
|
|
| 162 | + } |
|
| 163 | + if (strpos($dir, '/') !== 0) {
|
|
| 164 | + $dir = '/' . $dir; |
|
| 165 | + } |
|
| 162 | 166 | $resourceInfo = new ResourceInfo($namespace, $dir); |
| 163 | 167 | $resourceId = $resourceInfo->buildResourceId(); //得到资源ID |
| 164 | 168 | $uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId; |
@@ -197,10 +201,12 @@ discard block |
||
| 197 | 201 | */ |
| 198 | 202 | public function deleteDir($namespace, $dir) |
| 199 | 203 | {
|
| 200 | - if (empty($namespace) || empty($dir)) |
|
| 201 | - return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
|
|
| 202 | - if (strpos($dir, '/') !== 0) |
|
| 203 | - $dir = '/' . $dir; |
|
| 204 | + if (empty($namespace) || empty($dir)) {
|
|
| 205 | + return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
|
|
| 206 | + } |
|
| 207 | + if (strpos($dir, '/') !== 0) {
|
|
| 208 | + $dir = '/' . $dir; |
|
| 209 | + } |
|
| 204 | 210 | $resourceInfo = new ResourceInfo($namespace, $dir); |
| 205 | 211 | $resourceId = $resourceInfo->buildResourceId(); //得到资源ID |
| 206 | 212 | $uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId; |
@@ -260,8 +266,9 @@ discard block |
||
| 260 | 266 | */ |
| 261 | 267 | public function mediaEncodeQuery($taskId) |
| 262 | 268 | {
|
| 263 | - if (empty($taskId)) |
|
| 264 | - return $this->_errorResponse("InvalidArgument", "taskId is empty");
|
|
| 269 | + if (empty($taskId)) {
|
|
| 270 | + return $this->_errorResponse("InvalidArgument", "taskId is empty");
|
|
| 271 | + } |
|
| 265 | 272 | $uri = '/' . Conf::MEDIA_ENCODE_VERSION . '/mediaEncodeResult/' . $taskId; |
| 266 | 273 | return $this->_send_request('GET', $uri);
|
| 267 | 274 | } |
@@ -287,8 +294,9 @@ discard block |
||
| 287 | 294 | */ |
| 288 | 295 | public function vSnapshotQuery($taskId) |
| 289 | 296 | {
|
| 290 | - if (empty($taskId)) |
|
| 291 | - return $this->_errorResponse("InvalidArgument", "taskId is empty");
|
|
| 297 | + if (empty($taskId)) {
|
|
| 298 | + return $this->_errorResponse("InvalidArgument", "taskId is empty");
|
|
| 299 | + } |
|
| 292 | 300 | $uri = '/' . Conf::MANAGE_API_VERSION . '/snapshotResult/' . $taskId; |
| 293 | 301 | return $this->_send_request('GET', $uri);
|
| 294 | 302 | } |
@@ -21,12 +21,17 @@ discard block |
||
| 21 | 21 | /**检测多媒体转码选项是否合法。如果合法,则返回http请求体<p> 返回格式{$isValid, $message, $httpBody}*/
|
| 22 | 22 | public function checkOptionParameters() {
|
| 23 | 23 | list ( $valid, $msg ) = parent::checkOptionParameters(); //检测输入输出资源是否合法 |
| 24 | - if ( !$valid ) |
|
| 25 | - return array ( $valid, $msg, null ); |
|
| 26 | - if ( empty($this->encodeTemplate) ) |
|
| 27 | - return array ( false, "encodeTemplate is empty.", null ); // 判断是否设置输入输出文件,或者转码模板 |
|
| 28 | - if( ($this->usePreset!=0 && $this->usePreset!=1) || ($this->force!=0 && $this->force!=1) ) |
|
| 29 | - return array ( false, "parameters 'usePreset' or 'force' is invalid.", null ); // 判断usePreset和force参数是否为0或1 |
|
| 24 | + if ( !$valid ) {
|
|
| 25 | + return array ( $valid, $msg, null ); |
|
| 26 | + } |
|
| 27 | + if ( empty($this->encodeTemplate) ) {
|
|
| 28 | + return array ( false, "encodeTemplate is empty.", null ); |
|
| 29 | + } |
|
| 30 | + // 判断是否设置输入输出文件,或者转码模板 |
|
| 31 | + if( ($this->usePreset!=0 && $this->usePreset!=1) || ($this->force!=0 && $this->force!=1) ) {
|
|
| 32 | + return array ( false, "parameters 'usePreset' or 'force' is invalid.", null ); |
|
| 33 | + } |
|
| 34 | + // 判断usePreset和force参数是否为0或1 |
|
| 30 | 35 | return $this->getOptionsHttpBody(); //返回http请求体 |
| 31 | 36 | } |
| 32 | 37 | /**构建多媒体转码所需的http请求体*/ |
@@ -38,16 +43,21 @@ discard block |
||
| 38 | 43 | $httpBody .= '&usePreset=' . $this->usePreset; |
| 39 | 44 | $httpBody .= '&force=' . $this->force; |
| 40 | 45 | // 可选的参数 |
| 41 | - if (isset ( $this->watermark )) |
|
| 42 | - $httpBody .= '&watermark=' . $this->watermark->buildResourceId (); |
|
| 43 | - if (isset ( $this->watermarkTemplate )) |
|
| 44 | - $httpBody .= '&watermarkTemplate=' . urlencode($this->watermarkTemplate); |
|
| 45 | - if (isset ( $this->notifyUrl )) |
|
| 46 | - $httpBody .= '¬ifyUrl=' . urlencode($this->notifyUrl); |
|
| 47 | - if (isset ( $this->seek )) |
|
| 48 | - $httpBody .= '&seek=' . $this->seek; |
|
| 49 | - if (isset ( $this->duration )) |
|
| 50 | - $httpBody .= '&duration=' . $this->duration; |
|
| 46 | + if (isset ( $this->watermark )) {
|
|
| 47 | + $httpBody .= '&watermark=' . $this->watermark->buildResourceId (); |
|
| 48 | + } |
|
| 49 | + if (isset ( $this->watermarkTemplate )) {
|
|
| 50 | + $httpBody .= '&watermarkTemplate=' . urlencode($this->watermarkTemplate); |
|
| 51 | + } |
|
| 52 | + if (isset ( $this->notifyUrl )) {
|
|
| 53 | + $httpBody .= '¬ifyUrl=' . urlencode($this->notifyUrl); |
|
| 54 | + } |
|
| 55 | + if (isset ( $this->seek )) {
|
|
| 56 | + $httpBody .= '&seek=' . $this->seek; |
|
| 57 | + } |
|
| 58 | + if (isset ( $this->duration )) {
|
|
| 59 | + $httpBody .= '&duration=' . $this->duration; |
|
| 60 | + } |
|
| 51 | 61 | return array ( true, "valid", $httpBody ); //视频转码参数合法,返回http请求体 |
| 52 | 62 | } |
| 53 | 63 | /*######################以下是可选的参数set方法#######################*/ |
@@ -81,10 +91,13 @@ discard block |
||
| 81 | 91 | /**检测视频截图参数是否合法。如果合法,则返回http请求体<p> 返回格式{$isValid, $message, $httpBody}*/
|
| 82 | 92 | public function checkOptionParameters() {
|
| 83 | 93 | list ( $valid, $msg ) = parent::checkOptionParameters(); //检测输入输出资源是否合法 |
| 84 | - if ( !$valid ) |
|
| 85 | - return array ( $valid, $msg, null ); |
|
| 86 | - if ( empty($this->time) || !is_int($this->time) || $this->time<0) |
|
| 87 | - return array ( false, "time is empty or invalid.", null ); // 是否设置时间,且时间是否合法 |
|
| 94 | + if ( !$valid ) {
|
|
| 95 | + return array ( $valid, $msg, null ); |
|
| 96 | + } |
|
| 97 | + if ( empty($this->time) || !is_int($this->time) || $this->time<0) {
|
|
| 98 | + return array ( false, "time is empty or invalid.", null ); |
|
| 99 | + } |
|
| 100 | + // 是否设置时间,且时间是否合法 |
|
| 88 | 101 | return $this->getOptionsHttpBody(); //返回http请求体 |
| 89 | 102 | } |
| 90 | 103 | /**构建多媒体转码所需的http请求体*/ |
@@ -94,8 +107,9 @@ discard block |
||
| 94 | 107 | $httpBody .= '&output=' . $this->getOutputResId(); |
| 95 | 108 | $httpBody .= '&time=' . $this->time; |
| 96 | 109 | // 可选的参数 |
| 97 | - if (isset ( $this->notifyUrl )) |
|
| 98 | - $httpBody .= '¬ifyUrl=' . urlencode($this->notifyUrl) ; |
|
| 110 | + if (isset ( $this->notifyUrl )) {
|
|
| 111 | + $httpBody .= '¬ifyUrl=' . urlencode($this->notifyUrl) ; |
|
| 112 | + } |
|
| 99 | 113 | return array ( true, "valid", $httpBody ); //视频转码参数合法,返回http请求体 |
| 100 | 114 | } |
| 101 | 115 | |
@@ -122,14 +136,18 @@ discard block |
||
| 122 | 136 | } |
| 123 | 137 | /**检测参数选项是否合法*/ |
| 124 | 138 | public function checkOptionParameters() {
|
| 125 | - if ( empty($this->input) || empty($this->output) ) |
|
| 126 | - return array ( false, "input or output resources is empty." ); // 判断是否设置输入输出文件,或者转码模板 |
|
| 139 | + if ( empty($this->input) || empty($this->output) ) {
|
|
| 140 | + return array ( false, "input or output resources is empty." ); |
|
| 141 | + } |
|
| 142 | + // 判断是否设置输入输出文件,或者转码模板 |
|
| 127 | 143 | list ( $valid, $msg ) = $this->input->checkResourceInfo(true,true);//检测输入的资源信息是否合法 |
| 128 | - if(!$valid) |
|
| 129 | - return array ( $valid, $msg ); |
|
| 144 | + if(!$valid) {
|
|
| 145 | + return array ( $valid, $msg ); |
|
| 146 | + } |
|
| 130 | 147 | list ( $valid, $msg ) = $this->output->checkResourceInfo(true,true);//检测输入的资源信息是否合法 |
| 131 | - if(!$valid) |
|
| 132 | - return array ( $valid, $msg ); |
|
| 148 | + if(!$valid) {
|
|
| 149 | + return array ( $valid, $msg ); |
|
| 150 | + } |
|
| 133 | 151 | return array( true, null); |
| 134 | 152 | } |
| 135 | 153 | public function getInputResId() {
|
@@ -60,10 +60,12 @@ |
||
| 60 | 60 | private function getParas_Common_BlockInit() |
| 61 | 61 | {
|
| 62 | 62 | $paraArray = array(); |
| 63 | - if (isset($this->dir)) |
|
| 64 | - $paraArray['dir'] = $this->dir; |
|
| 65 | - if (isset($this->name)) |
|
| 66 | - $paraArray['name'] = $this->name; |
|
| 63 | + if (isset($this->dir)) {
|
|
| 64 | + $paraArray['dir'] = $this->dir; |
|
| 65 | + } |
|
| 66 | + if (isset($this->name)) {
|
|
| 67 | + $paraArray['name'] = $this->name; |
|
| 68 | + } |
|
| 67 | 69 | $paraArray['md5'] = md5($this->content); // 计算文件md5 |
| 68 | 70 | $paraArray['size'] = strlen($this->content); // 计算文件大小 |
| 69 | 71 | $paraArray['content'] = $this->content; |
@@ -22,10 +22,14 @@ discard block |
||
| 22 | 22 | * 返回格式{$isValid, $message}*/
|
| 23 | 23 | public function checkResourceInfo($dirState = false, $nameState = false) |
| 24 | 24 | {
|
| 25 | - if (empty($this->namespace)) |
|
| 26 | - return array(false, "namespace is empty.[{$this->toString()}]"); // 判断是否设置空间名
|
|
| 27 | - else |
|
| 28 | - return $this->checkFileInfo($dirState, $nameState); // 判断dir和name的合法性 |
|
| 25 | + if (empty($this->namespace)) {
|
|
| 26 | + return array(false, "namespace is empty.[{$this->toString()}]");
|
|
| 27 | + } |
|
| 28 | + // 判断是否设置空间名 |
|
| 29 | + else {
|
|
| 30 | + return $this->checkFileInfo($dirState, $nameState); |
|
| 31 | + } |
|
| 32 | + // 判断dir和name的合法性 |
|
| 29 | 33 | } |
| 30 | 34 | /**检测文件信息是否合法。$dirState表示是否检测dir,$nameState表示是否检测filename<p> |
| 31 | 35 | * 返回格式{$isValid, $message}*/
|
@@ -35,10 +39,14 @@ discard block |
||
| 35 | 39 | return array(false, "file's name is empty.[{$this->toString()}]"); // 1:若需要进行文件名name检测,则判断文件名是否为空
|
| 36 | 40 | } |
| 37 | 41 | if ($dirState) {
|
| 38 | - if (empty($this->dir)) |
|
| 39 | - $this->dir = '/'; // 2:判断路径是否为空,若为空,则默认为根目录'/' |
|
| 40 | - else if (strpos($this->dir, '/') !== 0) |
|
| 41 | - $this->dir = '/' . $this->dir; // 3:判断路径是否以'/'开头,若不是,则添加'/' |
|
| 42 | + if (empty($this->dir)) {
|
|
| 43 | + $this->dir = '/'; |
|
| 44 | + } |
|
| 45 | + // 2:判断路径是否为空,若为空,则默认为根目录'/' |
|
| 46 | + else if (strpos($this->dir, '/') !== 0) {
|
|
| 47 | + $this->dir = '/' . $this->dir; |
|
| 48 | + } |
|
| 49 | + // 3:判断路径是否以'/'开头,若不是,则添加'/' |
|
| 42 | 50 | } |
| 43 | 51 | return array(true, null); |
| 44 | 52 | } |
@@ -46,12 +54,15 @@ discard block |
||
| 46 | 54 | public function buildResourceId() |
| 47 | 55 | {
|
| 48 | 56 | $jsonData = array(); |
| 49 | - if (!empty($this->namespace)) |
|
| 50 | - array_push($jsonData, urldecode($this->namespace)); |
|
| 51 | - if (!empty($this->dir)) |
|
| 52 | - array_push($jsonData, urldecode($this->dir)); |
|
| 53 | - if (!empty($this->name)) |
|
| 54 | - array_push($jsonData, urldecode($this->name)); |
|
| 57 | + if (!empty($this->namespace)) {
|
|
| 58 | + array_push($jsonData, urldecode($this->namespace)); |
|
| 59 | + } |
|
| 60 | + if (!empty($this->dir)) {
|
|
| 61 | + array_push($jsonData, urldecode($this->dir)); |
|
| 62 | + } |
|
| 63 | + if (!empty($this->name)) {
|
|
| 64 | + array_push($jsonData, urldecode($this->name)); |
|
| 65 | + } |
|
| 55 | 66 | return EncodeUtils::encodeWithURLSafeBase64(json_encode($jsonData, true)); |
| 56 | 67 | } |
| 57 | 68 | /**对URL中文进行编码*/ |