no message

This commit is contained in:
kuaifan 2025-05-09 10:16:59 +08:00
parent 14bc7a0f76
commit 9ac3fd3615

View File

@ -246,7 +246,7 @@ class Apps
$info = [ $info = [
'name' => $appName, 'name' => $appName,
'description' => '', 'description' => '',
'icon' => '', 'icon' => self::processAppIcon($appName, ['logo.svg', 'logo.png', 'icon.svg', 'icon.png']),
'author' => '', 'author' => '',
'website' => '', 'website' => '',
'github' => '', 'github' => '',
@ -255,27 +255,6 @@ class Apps
'require_uninstalls' => [], 'require_uninstalls' => [],
]; ];
// 处理应用图标
$iconFiles = ['logo.svg', 'logo.png', 'icon.svg', 'icon.png'];
foreach ($iconFiles as $iconFile) {
$iconPath = $baseDir . '/' . $iconFile;
if (file_exists($iconPath)) {
// 创建目标目录、路径
$targetDir = public_path('uploads/file/apps/' . $appName);
$targetFile = $targetDir . '/' . $iconFile;
// 判断目标文件是否存在,或源文件是否比目标文件新
if (!file_exists($targetFile) || filemtime($iconPath) > filemtime($targetFile)) {
Base::makeDir($targetDir);
copy($iconPath, $targetFile);
}
// 设置图标URL
$info['icon'] = Base::fillUrl('uploads/file/apps/' . $appName . '/' . $iconFile);
break;
}
}
if (file_exists($baseDir . '/config.yml')) { if (file_exists($baseDir . '/config.yml')) {
$configData = Yaml::parseFile($baseDir . '/config.yml'); $configData = Yaml::parseFile($baseDir . '/config.yml');
@ -371,6 +350,62 @@ class Apps
return $info; return $info;
} }
/**
* 获取应用的入口点配置
*
* @param string $appName 应用名称
* @return array
*/
public static function getAppEntryPoints(string $appName): array
{
$baseDir = base_path('docker/apps/' . $appName);
$entryPoints = [];
if (!file_exists($baseDir . '/config.yml')) {
return Base::retSuccess("success", $entryPoints);
}
$configData = Yaml::parseFile($baseDir . '/config.yml');
if (isset($configData['entry_points']) && is_array($configData['entry_points'])) {
foreach ($configData['entry_points'] as $entry) {
// 检查必需的字段
if (!isset($entry['location']) || !isset($entry['url'])) {
continue;
}
// 标准化入口点结构
$normalizedEntry = [
'location' => $entry['location'],
'url' => $entry['url'],
'icon' => '',
];
// 处理图标
if (isset($entry['icon'])) {
$normalizedEntry['icon'] = self::processAppIcon($appName, [$entry['icon']]);
}
// 处理label支持多语言
if (isset($entry['label'])) {
$normalizedEntry['label'] = self::getMultiLanguageField($entry['label']);
} else {
$normalizedEntry['label'] = '';
}
// 处理可选的UI配置
foreach (['transparent', 'keepAlive'] as $option) {
if (isset($entry[$option])) {
$normalizedEntry[$option] = $entry[$option];
}
}
$entryPoints[] = $normalizedEntry;
}
}
return Base::retSuccess("success", $entryPoints);
}
/** /**
* 获取应用的本地安装信息 * 获取应用的本地安装信息
* *
@ -564,6 +599,44 @@ class Apps
return $field[$lang] ?? $field[array_key_first($field)]; return $field[$lang] ?? $field[array_key_first($field)];
} }
/**
* 处理应用图标
*
* @param string $appName 应用名称
* @param array $iconFiles 待处理的图标文件名数组
* @return string 处理后的图标URL如果没有可用图标则返回空字符串
*/
private static function processAppIcon(string $appName, array $iconFiles): string
{
$baseDir = base_path('docker/apps/' . $appName);
foreach ($iconFiles as $iconFile) {
// 检查是否为URL方式以http或https开头
if (preg_match('/^https?:\/\//i', $iconFile)) {
return $iconFile;
}
$iconPath = $baseDir . '/' . $iconFile;
if (file_exists($iconPath)) {
// 创建目标目录、路径
$targetDir = public_path('uploads/file/apps/' . $appName);
$iconName = str_replace(['/', '\\'], '_', $iconFile);
$targetFile = $targetDir . '/' . $iconName;
// 判断目标文件是否存在,或源文件是否比目标文件新
if (!file_exists($targetFile) || filemtime($iconPath) > filemtime($targetFile)) {
Base::makeDir($targetDir);
copy($iconPath, $targetFile);
}
// 返回图标URL
return Base::fillUrl('uploads/file/apps/' . $appName . '/' . $iconName);
}
}
return '';
}
/** /**
* 获取应用的可用版本列表 * 获取应用的可用版本列表
* *