diff --git a/src/Crontab/src/Command/CrontabMigrateCommand.php b/src/Crontab/src/Command/CrontabMigrateCommand.php index 245f53fb..51f707b4 100644 --- a/src/Crontab/src/Command/CrontabMigrateCommand.php +++ b/src/Crontab/src/Command/CrontabMigrateCommand.php @@ -14,7 +14,9 @@ use Hyperf\Command\Command as Base; use Hyperf\Database\Migrations\Migrator; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\NullOutput; class CrontabMigrateCommand extends Base @@ -36,7 +38,7 @@ public function __invoke() $migrator = $this->migrator; $migrator->setConnection($connection); $this->migrator - ->setOutput(new NullOutput()) + ->setOutput(new NullOutput(new ArrayInput([]), new ConsoleOutput())) ->run(dirname(__DIR__, 2) . '/Database/Migrations'); } diff --git a/src/app-store/src/Command/DownloadCommand.php b/src/app-store/src/Command/DownloadCommand.php index c7650590..e7a2cbdf 100644 --- a/src/app-store/src/Command/DownloadCommand.php +++ b/src/app-store/src/Command/DownloadCommand.php @@ -27,14 +27,16 @@ class DownloadCommand extends Base public function __invoke() { - $name = $this->input->getOption('name'); + $identifier = $this->input->getOption('identifier'); + $version = $this->input->getOption('version'); $appStoreService = ApplicationContext::getContainer()->get(AppStoreService::class); - $appStoreService->download($name); + $appStoreService->download($identifier, $version); $this->output->success('Plugin Downloaded Successfully'); } protected function configure() { - $this->addOption('name', 'n', InputOption::VALUE_REQUIRED, 'Plug-in Name'); + $this->addOption('identifier', 'n', InputOption::VALUE_REQUIRED, '必选,应用唯一标识符'); + $this->addOption('version', null, InputOption::VALUE_OPTIONAL, '应用版本号,默认latest', 'latest'); } } diff --git a/src/app-store/src/Command/ListCommand.php b/src/app-store/src/Command/ListCommand.php index 1ced53c6..4d4c65df 100644 --- a/src/app-store/src/Command/ListCommand.php +++ b/src/app-store/src/Command/ListCommand.php @@ -36,7 +36,7 @@ public function __invoke() $params['title'] = $title; } $appStoreService = ApplicationContext::getContainer()->get(AppStoreService::class); - $result = $appStoreService->list($params); + $result = $appStoreService->list($params)['data']['list'] ?? []; $headers = [ 'extensionName', 'description', 'author', 'homePage', 'status', ]; diff --git a/src/app-store/src/Service/AppStoreService.php b/src/app-store/src/Service/AppStoreService.php index 86687aae..13128ac9 100644 --- a/src/app-store/src/Service/AppStoreService.php +++ b/src/app-store/src/Service/AppStoreService.php @@ -25,7 +25,7 @@ public function request(string $uri, array $data = []): array; /** * Download the specified plug-in to a local directory. */ - public function download(string $identifier): bool; + public function download(string $identifier, string $version): bool; /** * Get the details of the specified plugin. diff --git a/src/app-store/src/Service/Impl/AppStoreServiceImpl.php b/src/app-store/src/Service/Impl/AppStoreServiceImpl.php index 5490982b..dd281e45 100644 --- a/src/app-store/src/Service/Impl/AppStoreServiceImpl.php +++ b/src/app-store/src/Service/Impl/AppStoreServiceImpl.php @@ -15,6 +15,7 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\RequestOptions; +use Hyperf\Collection\Collection; use Hyperf\Contract\ConfigInterface; use Hyperf\Guzzle\ClientFactory; use Xmo\AppStore\Plugin; @@ -81,12 +82,27 @@ public function view(string $identifier): array /** * Download the specified plug-in to a local directory. */ - public function download(string $identifier): bool + public function download(string $identifier, string $version): bool { - $downloadToken = $this->request(__FUNCTION__, compact('identifier'))[0] ?? ''; + $downloadResponse = Collection::make($this->request(__FUNCTION__, compact('identifier', 'version'))); + if (! $downloadResponse->get('success')) { + throw new \RuntimeException('服务端返回错误' . $downloadResponse->get('message')); + } + $file_token = $downloadResponse->get('data.token'); + if (empty($file_token)) { + throw new \RuntimeException('Failed to get download token'); + } + $downLoadFileResponse = Collection::make($this->request('download_file', compact('file_token'))); + if (! $downLoadFileResponse->get('success')) { + throw new \RuntimeException('服务端返回错误' . $downLoadFileResponse->get('message')); + } + $file_url = $downLoadFileResponse->get('data.url'); + if (empty($file_url)) { + throw new \RuntimeException('Failed to get download url'); + } $tmpFile = sys_get_temp_dir() . '/' . uniqid('mine', true) . '.zip'; $tmpFileResource = fopen(sys_get_temp_dir() . '/' . uniqid('mine', true) . '.zip', 'wb+'); - $response = $this->client->get('download_file?token=' . $downloadToken, [ + $response = $this->client->get($file_url, [ RequestOptions::SINK => $tmpFileResource, ]); if ($response->getStatusCode() !== 200) { diff --git a/src/mine-generator/src/ModelGenerator.php b/src/mine-generator/src/ModelGenerator.php index da37db54..49c848e3 100644 --- a/src/mine-generator/src/ModelGenerator.php +++ b/src/mine-generator/src/ModelGenerator.php @@ -33,6 +33,7 @@ use Psr\Container\NotFoundExceptionInterface; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\ArrayInput; +use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\NullOutput; use function Hyperf\Support\env; @@ -96,7 +97,7 @@ public function generator(): void } $input = new ArrayInput($command); - $output = new NullOutput(); + $output = new NullOutput(new ArrayInput([]), new BufferedOutput()); /** @var Application $application */ $application = $this->container->get(ApplicationInterface::class);