From 1a9fe40b80f0609342a8ee52b0dd6b9e320b5bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Thu, 17 Oct 2024 17:32:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20cli=E6=94=AF=E6=8C=81=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/ISSUE_TEMPLATE/bug_report.yml | 2 +- internal/data/app.go | 2 +- internal/data/setting.go | 12 ++++++------ internal/http/middleware/status.go | 2 +- internal/route/cli.go | 7 ++++++- internal/service/cli.go | 23 +++++++++++++++++++---- internal/service/dashboard.go | 6 +++--- web/src/i18n/zh_CN.json | 20 ++++++++++---------- 8 files changed, 47 insertions(+), 27 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 4adc52df..fcd1602e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -27,7 +27,7 @@ body: required: false - label: 这个问题可以被稳定复现 (The problem can be stably reproduced) required: false - - label: 问题是在升级之后产生的 (The problem is generated after upgrading) + - label: 问题是在更新之后产生的 (The problem is generated after upgrading) required: false - type: dropdown id: system diff --git a/internal/data/app.go b/internal/data/app.go index b6eba8b0..d2c0bb37 100644 --- a/internal/data/app.go +++ b/internal/data/app.go @@ -295,7 +295,7 @@ func (r *appRepo) Update(slug string) error { } task := new(biz.Task) - task.Name = "升级应用 " + item.Name + task.Name = "更新应用 " + item.Name task.Status = biz.TaskStatusWaiting task.Shell = fmt.Sprintf(`curl -fsLm 10 --retry 3 "%s" | bash -s -- "%s" "%s" >> /tmp/%s.log 2>&1`, shellUrl, shellChannel, shellVersion, item.Slug) task.Log = "/tmp/" + item.Slug + ".log" diff --git a/internal/data/setting.go b/internal/data/setting.go index fb7eb3c5..79548172 100644 --- a/internal/data/setting.go +++ b/internal/data/setting.go @@ -276,7 +276,7 @@ func (r *settingRepo) UpdatePanel(version, url, checksum string) error { color.Greenln("|-前置检查...") } if io.Exists("/tmp/panel-storage.zip") { - return errors.New("检测到 /tmp 存在临时文件,可能是上次升级失败所致,请运行 panel-cli fix 修复后重试") + return errors.New("检测到 /tmp 存在临时文件,可能是上次更新失败所致,请运行 panel-cli fix 修复后重试") } if app.IsCli { @@ -328,10 +328,10 @@ func (r *settingRepo) UpdatePanel(version, url, checksum string) error { } if app.IsCli { - color.Greenln("|-运行升级后脚本...") + color.Greenln("|-运行更新后脚本...") } if _, err := shell.Execf("curl -fsLm 10 https://dl.cdn.haozi.net/panel/auto_update.sh | bash"); err != nil { - return fmt.Errorf("运行面板升级后脚本失败:%w", err) + return fmt.Errorf("运行面板更新后脚本失败:%w", err) } if _, err := shell.Execf(`wget -O /etc/systemd/system/panel.service https://dl.cdn.haozi.net/panel/panel.service && sed -i "s|/www|%s|g" /etc/systemd/system/panel.service`, app.Root); err != nil { return fmt.Errorf("下载面板服务文件失败:%w", err) @@ -351,7 +351,7 @@ func (r *settingRepo) UpdatePanel(version, url, checksum string) error { _ = io.Chmod(filepath.Join(app.Root, "panel"), 0700) if app.IsCli { - color.Greenln("|-升级完成") + color.Greenln("|-更新完成") } _, _ = shell.Execf("systemctl daemon-reload") @@ -378,7 +378,7 @@ func (r *settingRepo) FixPanel() error { flag = true } if !flag { - return fmt.Errorf("文件正常无需修复,请运行 panel-cli update 升级面板") + return fmt.Errorf("文件正常无需修复,请运行 panel-cli update 更新面板") } // 再次确认是否需要修复 @@ -391,7 +391,7 @@ func (r *settingRepo) FixPanel() error { return fmt.Errorf("清理临时文件失败:%w", err) } if app.IsCli { - color.Greenln("已清理临时文件,请运行 panel-cli update 升级面板") + color.Greenln("已清理临时文件,请运行 panel-cli update 更新面板") } return nil } diff --git a/internal/http/middleware/status.go b/internal/http/middleware/status.go index 7cf22bba..1de2221a 100644 --- a/internal/http/middleware/status.go +++ b/internal/http/middleware/status.go @@ -16,7 +16,7 @@ func Status(next http.Handler) http.Handler { render := chix.NewRender(w) render.Status(http.StatusServiceUnavailable) render.JSON(chix.M{ - "message": "面板升级中,请稍后刷新", + "message": "面板更新中,请稍后刷新", }) return case app.StatusMaintain: diff --git a/internal/route/cli.go b/internal/route/cli.go index 09debbe0..ad0b5d64 100644 --- a/internal/route/cli.go +++ b/internal/route/cli.go @@ -26,7 +26,7 @@ func Cli() []*cli.Command { }, { Name: "update", - Usage: "升级面板", + Usage: "更新面板", Action: cliService.Update, }, { @@ -327,6 +327,11 @@ func Cli() []*cli.Command { Usage: "卸载应用", Action: cliService.AppUnInstall, }, + { + Name: "update", + Usage: "更新应用", + Action: cliService.AppUpdate, + }, { Name: "write", Usage: "添加面板应用标记(仅限指导下使用)", diff --git a/internal/service/cli.go b/internal/service/cli.go index a6dca5db..ae16250f 100644 --- a/internal/service/cli.go +++ b/internal/service/cli.go @@ -530,8 +530,8 @@ func (s *CliService) CutoffClear(ctx context.Context, cmd *cli.Command) error { } func (s *CliService) AppInstall(ctx context.Context, cmd *cli.Command) error { - channel := cmd.Args().Get(0) - slug := cmd.Args().Get(1) + slug := cmd.Args().First() + channel := cmd.Args().Get(1) if channel == "" || slug == "" { return fmt.Errorf("参数不能为空") } @@ -540,7 +540,7 @@ func (s *CliService) AppInstall(ctx context.Context, cmd *cli.Command) error { return fmt.Errorf("应用安装失败:%v", err) } - color.Greenln(fmt.Sprintf("已创建应用 %s 安装任务", slug)) + color.Greenln(fmt.Sprintf("应用 %s 安装完成", slug)) return nil } @@ -555,7 +555,22 @@ func (s *CliService) AppUnInstall(ctx context.Context, cmd *cli.Command) error { return fmt.Errorf("应用卸载失败:%v", err) } - color.Greenln(fmt.Sprintf("已创建应用 %s 卸载任务", slug)) + color.Greenln(fmt.Sprintf("应用 %s 卸载完成", slug)) + + return nil +} + +func (s *CliService) AppUpdate(ctx context.Context, cmd *cli.Command) error { + slug := cmd.Args().First() + if slug == "" { + return fmt.Errorf("参数不能为空") + } + + if err := s.appRepo.Update(slug); err != nil { + return fmt.Errorf("应用更新失败:%v", err) + } + + color.Greenln(fmt.Sprintf("应用 %s 更新完成", slug)) return nil } diff --git a/internal/service/dashboard.go b/internal/service/dashboard.go index 29aa1b16..0556d41a 100644 --- a/internal/service/dashboard.go +++ b/internal/service/dashboard.go @@ -311,7 +311,7 @@ func (s *DashboardService) UpdateInfo(w http.ResponseWriter, r *http.Request) { versions, err := s.api.IntermediateVersions() if err != nil { - Error(w, http.StatusInternalServerError, "获取升级信息失败:%v", err) + Error(w, http.StatusInternalServerError, "获取更新信息失败:%v", err) return } @@ -320,12 +320,12 @@ func (s *DashboardService) UpdateInfo(w http.ResponseWriter, r *http.Request) { func (s *DashboardService) Update(w http.ResponseWriter, r *http.Request) { if offline, _ := s.settingRepo.GetBool(biz.SettingKeyOfflineMode); offline { - Error(w, http.StatusForbidden, "离线模式下无法升级") + Error(w, http.StatusForbidden, "离线模式下无法更新") return } if s.taskRepo.HasRunningTask() { - Error(w, http.StatusInternalServerError, "后台任务正在运行,禁止升级,请稍后再试") + Error(w, http.StatusInternalServerError, "后台任务正在运行,禁止更新,请稍后再试") return } diff --git a/web/src/i18n/zh_CN.json b/web/src/i18n/zh_CN.json index 8aa8cb72..bfb9933e 100644 --- a/web/src/i18n/zh_CN.json +++ b/web/src/i18n/zh_CN.json @@ -13,22 +13,22 @@ "title": "文件管理" }, "homeUpdate": { - "title": "升级面板", + "title": "更新面板", "loading": "正在加载更新信息,稍等片刻", "alerts": { - "success": "面板升级成功", - "info": "取消升级" + "success": "面板更新成功", + "info": "取消更新" }, "button": { - "update": "立即升级" + "update": "立即更新" }, "confirm": { "update": { - "title": "升级面板", - "content": "确定升级面板吗?", + "title": "更新面板", + "content": "确定更新面板吗?", "positiveText": "确定", "negativeText": "取消", - "loading": "面板升级中..." + "loading": "面板更新中..." } } }, @@ -39,7 +39,7 @@ "title": "应用中心", "alerts": { "cache": "缓存更新成功", - "warning": "升级应用前强烈建议先备份/快照,以免出现问题时无法回滚!", + "warning": "更新应用前强烈建议先备份/快照,以免出现问题时无法回滚!", "setup": "设置成功", "install": "任务已提交,请稍后查看任务进度", "update": "任务已提交,请前往后台任务查看任务进度", @@ -49,11 +49,11 @@ "updateCache": "更新缓存", "install": "安装", "manage": "管理", - "update": "升级", + "update": "更新", "uninstall": "卸载" }, "confirm": { - "update": "升级 {app} 应用可能会重置相关配置到默认状态,确定继续吗?", + "update": "更新 {app} 应用可能会重置相关配置到默认状态,确定继续吗?", "uninstall": "确定卸载应用 {app} 吗?" }, "columns": {