mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-05 20:10:26 +00:00
no message
This commit is contained in:
parent
2bb646d150
commit
7be1171004
@ -79,6 +79,28 @@ class AppsController extends AbstractController
|
|||||||
return Apps::appInfo($appName);
|
return Apps::appInfo($appName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @api {get} api/apps/entry 04. 获取应用入口点(限管理员)
|
||||||
|
*
|
||||||
|
* @apiVersion 1.0.0
|
||||||
|
* @apiGroup apps
|
||||||
|
* @apiName entry
|
||||||
|
*
|
||||||
|
* @apiParam {String} [app_name] 应用名称
|
||||||
|
* - 不指定则获取所有已安装的应用入口点
|
||||||
|
*
|
||||||
|
* @apiSuccess {Number} ret 返回状态码(1正确、0错误)
|
||||||
|
* @apiSuccess {String} msg 返回信息(错误描述)
|
||||||
|
* @apiSuccess {Object} data 应用入口点信息
|
||||||
|
*/
|
||||||
|
public function entry()
|
||||||
|
{
|
||||||
|
User::auth();
|
||||||
|
//
|
||||||
|
$appName = Request::input('app_name');
|
||||||
|
return Apps::getAppEntryPoints($appName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @api {post} api/apps/install 04. 安装应用(限管理员)
|
* @api {post} api/apps/install 04. 安装应用(限管理员)
|
||||||
*
|
*
|
||||||
@ -158,9 +180,6 @@ class AppsController extends AbstractController
|
|||||||
User::auth('admin');
|
User::auth('admin');
|
||||||
//
|
//
|
||||||
$url = Request::input('url');
|
$url = Request::input('url');
|
||||||
if (empty($url)) {
|
|
||||||
return Base::retError('应用url不能为空');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 下载应用
|
// 下载应用
|
||||||
$res = Apps::downloadApp($url);
|
$res = Apps::downloadApp($url);
|
||||||
|
|||||||
@ -342,10 +342,24 @@ class Apps
|
|||||||
/**
|
/**
|
||||||
* 获取应用的入口点配置
|
* 获取应用的入口点配置
|
||||||
*
|
*
|
||||||
|
* @param string|null $appName 应用名称,如果为null则获取所有已安装应用的入口点
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getAppEntryPoints(?string $appName = null): array
|
||||||
|
{
|
||||||
|
if ($appName !== null) {
|
||||||
|
return self::getSingleAppEntryPoints($appName);
|
||||||
|
}
|
||||||
|
return self::getAllInstalledAppsEntryPoints();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取单个应用的入口点配置
|
||||||
|
*
|
||||||
* @param string $appName 应用名称
|
* @param string $appName 应用名称
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getAppEntryPoints(string $appName): array
|
private static function getSingleAppEntryPoints(string $appName): array
|
||||||
{
|
{
|
||||||
$baseDir = base_path('docker/appstore/apps/' . $appName);
|
$baseDir = base_path('docker/appstore/apps/' . $appName);
|
||||||
$entryPoints = [];
|
$entryPoints = [];
|
||||||
@ -354,36 +368,91 @@ class Apps
|
|||||||
return Base::retSuccess("success", $entryPoints);
|
return Base::retSuccess("success", $entryPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
$configData = Yaml::parseFile($baseDir . '/config.yml');
|
try {
|
||||||
if (isset($configData['entry_points']) && is_array($configData['entry_points'])) {
|
$configData = Yaml::parseFile($baseDir . '/config.yml');
|
||||||
foreach ($configData['entry_points'] as $entry) {
|
if (isset($configData['entry_points']) && is_array($configData['entry_points'])) {
|
||||||
// 检查必需的字段
|
foreach ($configData['entry_points'] as $entry) {
|
||||||
if (!isset($entry['location']) || !isset($entry['url'])) {
|
$normalizedEntry = self::normalizeEntryPoint($entry, $appName);
|
||||||
continue;
|
if ($normalizedEntry) {
|
||||||
}
|
$entryPoints[] = $normalizedEntry;
|
||||||
|
|
||||||
// 标准化入口点结构
|
|
||||||
$normalizedEntry = [
|
|
||||||
'location' => $entry['location'],
|
|
||||||
'url' => $entry['url'],
|
|
||||||
'icon' => self::processAppIcon($appName, [$entry['icon']]),
|
|
||||||
'label' => self::getMultiLanguageField($entry['label']),
|
|
||||||
];
|
|
||||||
|
|
||||||
// 处理可选的UI配置
|
|
||||||
foreach (['transparent', 'keepAlive'] as $option) {
|
|
||||||
if (isset($entry[$option])) {
|
|
||||||
$normalizedEntry[$option] = $entry[$option];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$entryPoints[] = $normalizedEntry;
|
|
||||||
}
|
}
|
||||||
|
} catch (ParseException $e) {
|
||||||
|
return Base::retError('配置文件解析失败:' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Base::retSuccess("success", $entryPoints);
|
return Base::retSuccess("success", $entryPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有已安装应用的入口点配置
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function getAllInstalledAppsEntryPoints(): array
|
||||||
|
{
|
||||||
|
$allEntryPoints = [];
|
||||||
|
$baseDir = base_path('docker/appstore/apps');
|
||||||
|
|
||||||
|
if (!is_dir($baseDir)) {
|
||||||
|
return Base::retSuccess("success", $allEntryPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dirs = scandir($baseDir);
|
||||||
|
foreach ($dirs as $dir) {
|
||||||
|
if ($dir === '.' || $dir === '..' || str_starts_with($dir, '.')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!self::isInstalled($dir)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$appEntryPoints = self::getSingleAppEntryPoints($dir);
|
||||||
|
if (Base::isSuccess($appEntryPoints)) {
|
||||||
|
$allEntryPoints = array_merge($allEntryPoints, $appEntryPoints['data']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Base::retSuccess("success", $allEntryPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标准化入口点配置
|
||||||
|
*
|
||||||
|
* @param array $entry 入口点配置
|
||||||
|
* @param string $appName 应用名称
|
||||||
|
* @return array|null 标准化后的入口点配置,如果配置无效则返回null
|
||||||
|
*/
|
||||||
|
private static function normalizeEntryPoint(array $entry, string $appName): ?array
|
||||||
|
{
|
||||||
|
// 检查必需的字段
|
||||||
|
if (!isset($entry['location']) || !isset($entry['url'])) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 基础配置
|
||||||
|
$normalizedEntry = [
|
||||||
|
'app_name' => $appName,
|
||||||
|
'location' => $entry['location'],
|
||||||
|
'url' => $entry['url'],
|
||||||
|
'key' => $entry['key'] ?? substr(md5($entry['url']), 0, 16),
|
||||||
|
'icon' => self::processAppIcon($appName, [$entry['icon'] ?? '']),
|
||||||
|
'label' => self::getMultiLanguageField($entry['label'] ?? ''),
|
||||||
|
];
|
||||||
|
|
||||||
|
// 处理可选的UI配置
|
||||||
|
$optionalConfigs = ['transparent', 'keepAlive'];
|
||||||
|
foreach ($optionalConfigs as $config) {
|
||||||
|
if (isset($entry[$config])) {
|
||||||
|
$normalizedEntry[$config] = $entry[$config];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $normalizedEntry;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取应用配置信息
|
* 获取应用配置信息
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user