Skip to content

Commit ebbf14c

Browse files
committed
refactor:优化下载模块方法的参数接受方式
1 parent fd9277f commit ebbf14c

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

app/admin/controller/Module.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ public function initialize(): void
2222
public function index(): void
2323
{
2424
$this->success('', [
25-
'sysVersion' => Config::get('buildadmin.version'),
26-
'installed' => Server::installedList(root_path() . 'modules' . DIRECTORY_SEPARATOR),
25+
'installed' => Server::installedList(root_path() . 'modules' . DIRECTORY_SEPARATOR),
26+
'sysVersion' => Config::get('buildadmin.version'),
27+
'nuxtVersion' => Server::getNuxtVersion(),
2728
]);
2829
}
2930

@@ -41,15 +42,13 @@ public function state(): void
4142
public function install(): void
4243
{
4344
AdminLog::instance()->setTitle(__('Install module'));
44-
$uid = $this->request->get("uid/s", '');
45-
$token = $this->request->get("token/s", '');
46-
$orderId = $this->request->get("orderId/d", 0);
45+
$uid = $this->request->param("uid/s", '');
4746
if (!$uid) {
4847
$this->error(__('Parameter error'));
4948
}
5049
$res = [];
5150
try {
52-
$res = Manage::instance($uid)->install($token, $orderId);
51+
$res = Manage::instance($uid)->install();
5352
} catch (Exception $e) {
5453
$this->error(__($e->getMessage()), $e->getData(), $e->getCode());
5554
} catch (Throwable $e) {
@@ -117,14 +116,13 @@ public function uninstall(): void
117116
public function update(): void
118117
{
119118
AdminLog::instance()->setTitle(__('Update module'));
120-
$uid = $this->request->get("uid/s", '');
121-
$token = $this->request->get("token/s", '');
122-
$orderId = $this->request->get("orderId/d", 0);
119+
$uid = $this->request->param("uid/s", '');
120+
$token = $this->request->param("token/s", '');
123121
if (!$token || !$uid) {
124122
$this->error(__('Parameter error'));
125123
}
126124
try {
127-
Manage::instance($uid)->update($token, $orderId);
125+
Manage::instance($uid)->update();
128126
} catch (Exception $e) {
129127
$this->error(__($e->getMessage()), $e->getData(), $e->getCode());
130128
} catch (Throwable $e) {

app/admin/library/module/Manage.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,27 @@ public function getInstallState()
9797

9898
/**
9999
* 下载模块文件
100-
* @param string $token 官网会员token
101-
* @param int $orderId 订单号
102-
* @return string 下载文件路径
100+
* @return string 已下载文件路径
103101
* @throws Throwable
104102
*/
105-
public function download(string $token, int $orderId): string
103+
public function download(): string
106104
{
105+
$token = request()->param("token/s");
106+
$version = request()->param('version/s');
107+
$orderId = request()->param("orderId/d");
108+
107109
if (!$orderId) {
108110
throw new Exception('Order not found');
109111
}
112+
110113
// 下载 - 系统版本号要求、已安装模块的互斥和依赖检测
111114
$zipFile = Server::download($this->uid, $this->installDir, [
112-
'sysVersion' => Config::get('buildadmin.version'),
115+
'version' => $version,
116+
'orderId' => $orderId,
113117
'nuxtVersion' => Server::getNuxtVersion(),
114-
'ba-user-token' => $token,
115-
'order_id' => $orderId,
118+
'sysVersion' => Config::get('buildadmin.version'),
116119
'installed' => Server::getInstalledIds($this->installDir),
120+
'ba-user-token' => $token,
117121
]);
118122

119123
// 删除旧版本代码
@@ -236,14 +240,14 @@ public function upload(string $token, string $file): array
236240
* 更新
237241
* @throws Throwable
238242
*/
239-
public function update(string $token, int $orderId): void
243+
public function update(): void
240244
{
241245
$state = $this->getInstallState();
242246
if ($state != self::DISABLE) {
243247
throw new Exception('Please disable the module before updating');
244248
}
245249

246-
$this->download($token, $orderId);
250+
$this->download();
247251

248252
// 标记需要执行更新脚本,并在安装请求执行(当前请求未自动加载到新文件不方便执行)
249253
$info = $this->getInfo();
@@ -253,20 +257,18 @@ public function update(string $token, int $orderId): void
253257

254258
/**
255259
* 安装模块
256-
* @param string $token 用户token
257-
* @param int $orderId 订单号
258260
* @return array 模块基本信息
259261
* @throws Throwable
260262
*/
261-
public function install(string $token, int $orderId): array
263+
public function install(): array
262264
{
263265
$state = $this->getInstallState();
264266
if ($state == self::INSTALLED || $state == self::DIRECTORY_OCCUPIED || $state == self::DISABLE) {
265267
throw new Exception('Module already exists');
266268
}
267269

268270
if ($state == self::UNINSTALLED) {
269-
$this->download($token, $orderId);
271+
$this->download();
270272
}
271273

272274
// 导入sql

0 commit comments

Comments
 (0)