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

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);