feat: add plugin update support + fix bugs

This commit is contained in:
xboard
2025-07-13 08:53:00 +08:00
parent 328461b093
commit 18de0e8a43
3 changed files with 17 additions and 4 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ class Shadowsocks extends AbstractProtocol
"remarks" => $server['name'],
"server" => $server['host'],
"server_port" => $server['port'],
"password" => $item['password'],
"password" => $server['password'],
"method" => data_get($server, 'protocol_settings.cipher')
];
return $config;
-1
View File
@@ -37,7 +37,6 @@ class OrderService
* @param Plan $plan
* @param string $period
* @param string|null $couponCode
* @param array|null $telegramMessageIds
* @return Order
* @throws ApiException
*/
+16 -2
View File
@@ -428,8 +428,22 @@ class PluginManager
$targetPath = $this->pluginPath . '/' . Str::studly($config['code']);
if (File::exists($targetPath)) {
File::deleteDirectory($extractPath);
throw new \Exception('插件已存在');
$installedConfigPath = $targetPath . '/config.json';
if (!File::exists($installedConfigPath)) {
throw new \Exception('已安装插件缺少配置文件,无法判断是否可升级');
}
$installedConfig = json_decode(File::get($installedConfigPath), true);
$oldVersion = $installedConfig['version'] ?? null;
$newVersion = $config['version'] ?? null;
if (!$oldVersion || !$newVersion) {
throw new \Exception('插件缺少版本号,无法判断是否可升级');
}
if (version_compare($newVersion, $oldVersion, '<=')) {
throw new \Exception('上传插件版本不高于已安装版本,无法升级');
}
File::deleteDirectory($targetPath);
}
File::copyDirectory($pluginPath, $targetPath);