diff --git a/app-api/controllers/UpgradeController.php b/app-api/controllers/UpgradeController.php index cc89fd8..2a89652 100644 --- a/app-api/controllers/UpgradeController.php +++ b/app-api/controllers/UpgradeController.php @@ -178,7 +178,7 @@ class UpgradeController extends BaseController $e->update_flag = $upgradeRecord->focuse; $e->version = $upgradeRecord->version; // 根据配置文件切换读取更新文件的路径 - if (isset(Yii::$app->params['UPGRADE_FILE_FROM']) && 'FROM_ECS' == Yii::$app->params['UPGRADE_FILE_FROM']) { + if (isset(Yii::$app->params['UPGRADE_FILE_FROM']) && 'FROM_OSS' == Yii::$app->params['UPGRADE_FILE_FROM']) { $ossConfig = Yii::$app->params['ossOptions']; $domainURL = $ossConfig['url']; $filePath = $domainURL.'/'.$upgradeRecord->path; @@ -368,7 +368,7 @@ class UpgradeController extends BaseController $e->version_message = ''; } else { - if (isset(Yii::$app->params['UPGRADE_FILE_FROM']) && 'FROM_ECS' == Yii::$app->params['UPGRADE_FILE_FROM']) { + if (isset(Yii::$app->params['UPGRADE_FILE_FROM']) && 'FROM_OSS' == Yii::$app->params['UPGRADE_FILE_FROM']) { $ossConfig = Yii::$app->params['ossOptions']; $domainURL = $ossConfig['url']; $filePath = $domainURL.'/'.$upgradeRecord->path; diff --git a/app-ht/modules/upgrade/controllers/UpgradeController.php b/app-ht/modules/upgrade/controllers/UpgradeController.php index 4f312fe..dd909ab 100644 --- a/app-ht/modules/upgrade/controllers/UpgradeController.php +++ b/app-ht/modules/upgrade/controllers/UpgradeController.php @@ -554,8 +554,9 @@ class UpgradeController extends BaseController // 上传OSS - $fileService = new FileService(); - $fileService->add($uploadPath, $savePath); + /* 分两步上传 + $fileService = new FileService(); + $fileService->add($uploadPath, $savePath);*/ // 删除服务器传成功的文件 //@unlink($uploadPath); @@ -572,6 +573,46 @@ class UpgradeController extends BaseController } /** + * 同步文件到OSS + * @return array + */ + public function actionPushOss() + { + $e = new stdClass(); + try { + $request = Yii::$app->request; + $upgradeId = $request->post('upgrade_id'); + $e->success = false; + $e->message = ""; + if (empty($upgradeId)) { + $e->message = "缺少版本编号"; + return $this->renderJson($e); + } + $upgradeModel = UpgradeRepository::findOne($upgradeId); + if (empty($upgradeModel)) { + $e->message = "该版本不存在"; + return $this->renderJson($e); + } + $uploadPath = dirname(dirname(dirname(__DIR__))) . "/" . $upgradeModel->upload_path; + if (!file_exists($uploadPath)) { + $e->message = "该版本ECS文件不存在"; + return $this->renderJson($e); + } + $savePath = $upgradeModel->path; + $fileService = new FileService(); + $fileService->add($uploadPath, $savePath); + $upgradeModel->oss_upload_status = UpgradeStatus::OSS_UPLOAD_SUCCESS; + $upgradeModel->save(); + $e->success = true; + $e->message = "同步OSS成功"; + return $this->renderJson($e); + } catch (\Exception $ex) { + $e->message = "同步OSS异常:" . $ex->getMessage(); + return $this->renderJson($e); + } + } + + /** * 发布APP版本 * @return string */ diff --git a/app-ht/modules/upgrade/views/upgrade/index.php b/app-ht/modules/upgrade/views/upgrade/index.php index 3bef4c7..79f7a97 100644 --- a/app-ht/modules/upgrade/views/upgrade/index.php +++ b/app-ht/modules/upgrade/views/upgrade/index.php @@ -115,18 +115,31 @@ $this->params['breadcrumbs'][] = $this->title;  |  - $item['id']])?>" aid="">编辑 |  + $item['id']])?>" aid="">编辑 - $item['id']])?>" aid="">发布 + params['UPGRADE_FILE_FROM']) && + 'FROM_OSS' == Yii::$app->params['UPGRADE_FILE_FROM']) { + if ( UpgradeStatus::OSS_UPLOAD_SUCCESS == $item["oss_upload_status"]) { ?> +  |  $item['id']])?>" aid="">发布 + +  |  $item['id']])?>" aid="">发布 + - $item['id']])?>" aid="">发布 + params['UPGRADE_FILE_FROM']) && + 'FROM_OSS' == Yii::$app->params['UPGRADE_FILE_FROM']) { + if ( UpgradeStatus::OSS_UPLOAD_SUCCESS == $item["oss_upload_status"]) { ?> +  |  $item['id']])?>" aid="">发布 + +  |  $item['id']])?>" aid="">发布 + - - 取消发布 + +  |  取消发布 + +  | 同步OSS + @@ -207,5 +220,40 @@ $this->params['breadcrumbs'][] = $this->title; }); } }); + + $(".btn_upload_oss").bind("click",function () { + if (confirm("确定要同步该版本文件到OSS吗?")){ + var data_id = $.trim($(this).attr("aid")); + if (data_id == null || data_id == ""){ + alert("丢失参数,暂时无法取消,请刷新后再试"); + return false; + } + var thiz = $(this); + thiz.text("同步中…"); + var loding = $.loading(); + loding.show(); + $.ajax({ + type: "post", + url: "", + dataType:"json", + data: $.csrf({upgrade_id:data_id}), + success:function(res){ + loding.hide(); + loding = null; + if(!res.success) { + alert(res.message); + } else { + var versionType = $('#versionType').val(); + window.location.href = 'index?type='+versionType; + } + }, + error:function(msg){ + loding.hide(); + loding = null; + //提示确认失败 + } + }); + } + }); }); \ No newline at end of file diff --git a/common/config/params.php b/common/config/params.php index 50bccf9..04a3db3 100644 --- a/common/config/params.php +++ b/common/config/params.php @@ -11,7 +11,7 @@ return [ 'url' => 'https://kingboard-prod.oss-cn-shenzhen.aliyuncs.com', 'styleUrl' => 'https://kingboard-prod.oss-cn-shenzhen.aliyuncs.com' ], - 'UPGRADE_FILE_FROM' => 'FROM_ECS', + 'UPGRADE_FILE_FROM' => 'FROM_OSS', 'AUTH_DEVICE_RSA_PKCS_1' => [ 'PRIVATE' => require(__DIR__ . '/rsa/privateKey.php'), 'PUBLIC' => require(__DIR__ . '/rsa/publicKey.php') diff --git a/domain/upgrade/UpgradeStatus.php b/domain/upgrade/UpgradeStatus.php index e1caf51..ef9af73 100644 --- a/domain/upgrade/UpgradeStatus.php +++ b/domain/upgrade/UpgradeStatus.php @@ -34,6 +34,12 @@ class UpgradeStatus const PACKAGE_TYPE_PART = 2; // 增量升级 /** + * 同步OSS状态 + */ + const OSS_UPLOAD_WAIT = 1; // 等待同步OSS + const OSS_UPLOAD_SUCCESS = 2; // 同步OSS成功 + + /** * @return array */ public static function statusLabels() -- libgit2 0.21.0