Skip to content

Commit 243956c

Browse files
authored
feat(app-store): 添加应用市场终端任务管理功能,增强校验安全性。 (#733)
1 parent f19444b commit 243956c

14 files changed

Lines changed: 1653 additions & 10 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

plugin/mine-admin/app-store/src/Controller/IndexController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,55 +37,64 @@ class IndexController extends AbstractController
3737
public Service $service;
3838

3939
#[GetMapping('index')]
40+
#[Permission(code: 'plugin:store:list')]
4041
public function index(): Result
4142
{
4243
return $this->success($this->serviceImpl->list($this->request->all()));
4344
}
4445

4546
#[GetMapping('getPayApp')]
47+
#[Permission(code: 'plugin:store:list')]
4648
public function getPayApp(): Result
4749
{
4850
return $this->success($this->serviceImpl->payApp());
4951
}
5052

5153
#[GetMapping('getLocalAppInstallList')]
54+
#[Permission(code: 'plugin:store:local-list')]
5255
public function getLocalAppInstallList(): Result
5356
{
5457
return $this->success($this->service->getLocalAppInstallList());
5558
}
5659

5760
#[GetMapping('detail')]
61+
#[Permission(code: 'plugin:store:detail')]
5862
public function detail(): Result
5963
{
6064
return $this->success($this->serviceImpl->view($this->request->input('identifier')));
6165
}
6266

6367
#[PostMapping('download')]
68+
#[Permission(code: 'plugin:store:download')]
6469
public function download(): Result
6570
{
6671
return $this->success(['result' => $this->service->download($this->request->all())]);
6772
}
6873

6974
#[PostMapping('install')]
75+
#[Permission(code: 'plugin:store:install')]
7076
public function install(): Result
7177
{
7278
return $this->success(['result' => $this->service->install($this->request->all())]);
7379
}
7480

7581
#[PostMapping('unInstall')]
82+
#[Permission(code: 'plugin:store:uninstall')]
7683
public function unInstall(): Result
7784
{
7885
return $this->success(['result' => $this->service->unInstall($this->request->all())]);
7986
}
8087

8188
#[PostMapping('uploadLocalApp')]
89+
#[Permission(code: 'plugin:store:upload')]
8290
public function uploadLocalApp(): Result
8391
{
8492
$this->service->uploadLocalApp($this->request->file('file'));
8593
return $this->success();
8694
}
8795

8896
#[GetMapping('hasAccessToken')]
97+
#[Permission(code: 'plugin:store:config')]
8998
public function hasAccessToken(): Result
9099
{
91100
return $this->success(['isHas' => env('MINE_ACCESS_TOKEN') !== null]);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Plugin\MineAdmin\AppStore\Controller;
6+
7+
use App\Http\Admin\Middleware\PermissionMiddleware;
8+
use App\Http\Common\Middleware\AccessTokenMiddleware;
9+
use App\Http\Common\Result;
10+
use Hyperf\HttpServer\Annotation\Controller;
11+
use Hyperf\HttpServer\Annotation\GetMapping;
12+
use Hyperf\HttpServer\Annotation\Middleware;
13+
use Hyperf\HttpServer\Annotation\PostMapping;
14+
use Mine\Access\Attribute\Permission;
15+
use Plugin\MineAdmin\AppStore\Request\TerminalTaskRequest;
16+
use Plugin\MineAdmin\AppStore\Service\TerminalTaskService;
17+
18+
#[Controller(prefix: 'admin/plugin/store/terminal')]
19+
#[Middleware(middleware: AccessTokenMiddleware::class, priority: 100)]
20+
#[Middleware(middleware: PermissionMiddleware::class, priority: 99)]
21+
#[Permission(code: 'plugin:store:terminal')]
22+
class TerminalController extends AbstractController
23+
{
24+
public function __construct(
25+
\Hyperf\HttpServer\Contract\RequestInterface $request,
26+
private readonly TerminalTaskService $service
27+
) {
28+
parent::__construct($request);
29+
}
30+
31+
#[PostMapping('tasks')]
32+
#[Permission(code: 'plugin:store:terminal')]
33+
public function create(TerminalTaskRequest $request): Result
34+
{
35+
return $this->success($this->service->create($request->validated()));
36+
}
37+
38+
#[GetMapping('tasks/{taskNo}')]
39+
#[Permission(code: 'plugin:store:terminal')]
40+
public function status(string $taskNo): Result
41+
{
42+
return $this->success($this->service->status($taskNo));
43+
}
44+
45+
#[GetMapping('tasks/{taskNo}/logs')]
46+
#[Permission(code: 'plugin:store:terminal')]
47+
public function logs(string $taskNo): Result
48+
{
49+
return $this->success($this->service->logs(
50+
$taskNo,
51+
(int) $this->request->input('after_seq', 0),
52+
(int) $this->request->input('limit', 200)
53+
));
54+
}
55+
56+
#[PostMapping('tasks/{taskNo}/cancel')]
57+
#[Permission(code: 'plugin:store:terminal:cancel')]
58+
public function cancel(string $taskNo): Result
59+
{
60+
return $this->success($this->service->cancel($taskNo));
61+
}
62+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Plugin\MineAdmin\AppStore\Enum;
6+
7+
enum TerminalAction: string
8+
{
9+
case Download = 'download';
10+
case Install = 'install';
11+
case Uninstall = 'uninstall';
12+
case FrontendDeps = 'frontend_deps';
13+
case BackendDeps = 'backend_deps';
14+
case InstallPnpm = 'install_pnpm';
15+
case CheckEnvironment = 'check_environment';
16+
17+
public static function values(): array
18+
{
19+
return array_column(self::cases(), 'value');
20+
}
21+
22+
public function permissionCode(): string
23+
{
24+
return match ($this) {
25+
self::Download => 'plugin:store:terminal:download',
26+
self::Install => 'plugin:store:terminal:install',
27+
self::Uninstall => 'plugin:store:terminal:uninstall',
28+
self::FrontendDeps => 'plugin:store:terminal:frontend-deps',
29+
self::BackendDeps => 'plugin:store:terminal:backend-deps',
30+
self::InstallPnpm => 'plugin:store:terminal:pnpm',
31+
self::CheckEnvironment => 'plugin:store:terminal',
32+
};
33+
}
34+
35+
public function label(): string
36+
{
37+
return match ($this) {
38+
self::Download => '下载插件',
39+
self::Install => '安装插件',
40+
self::Uninstall => '卸载插件',
41+
self::FrontendDeps => '安装前端依赖',
42+
self::BackendDeps => '安装后端依赖',
43+
self::InstallPnpm => '安装 pnpm',
44+
self::CheckEnvironment => '检查环境',
45+
};
46+
}
47+
48+
public function requiresIdentifier(): bool
49+
{
50+
return match ($this) {
51+
self::Download,
52+
self::Install,
53+
self::Uninstall,
54+
self::FrontendDeps,
55+
self::BackendDeps => true,
56+
self::InstallPnpm,
57+
self::CheckEnvironment => false,
58+
};
59+
}
60+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Plugin\MineAdmin\AppStore\Enum;
6+
7+
enum TerminalStatus: string
8+
{
9+
case Pending = 'pending';
10+
case Running = 'running';
11+
case Success = 'success';
12+
case Failed = 'failed';
13+
case Cancelled = 'cancelled';
14+
case Expired = 'expired';
15+
case Lost = 'lost';
16+
17+
public static function terminalValues(): array
18+
{
19+
return [
20+
self::Success->value,
21+
self::Failed->value,
22+
self::Cancelled->value,
23+
self::Expired->value,
24+
self::Lost->value,
25+
];
26+
}
27+
28+
public function isTerminal(): bool
29+
{
30+
return in_array($this->value, self::terminalValues(), true);
31+
}
32+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Plugin\MineAdmin\AppStore\Request;
6+
7+
use App\Http\Common\Request\Traits\NoAuthorizeTrait;
8+
use Hyperf\Validation\Request\FormRequest;
9+
use Plugin\MineAdmin\AppStore\Enum\TerminalAction;
10+
11+
class TerminalTaskRequest extends FormRequest
12+
{
13+
use NoAuthorizeTrait;
14+
15+
public function rules(): array
16+
{
17+
return [
18+
'action' => 'required|string|in:' . implode(',', TerminalAction::values()),
19+
'identifier' => 'sometimes|nullable|string|max:120',
20+
'version' => 'sometimes|nullable|string|max:80',
21+
];
22+
}
23+
}

0 commit comments

Comments
 (0)