diff --git a/go.sum b/go.sum index d98c2edc..6c638a5e 100644 --- a/go.sum +++ b/go.sum @@ -156,6 +156,8 @@ github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OI github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs= github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/wire v0.7.0 h1:JxUKI6+CVBgCO2WToKy/nQk0sS+amI9z9EjVmdaocj4= @@ -336,6 +338,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ github.com/pkg/sftp v1.13.10 h1:+5FbKNTe5Z9aspU88DPIKJ9z2KZoaGCu6Sr6kKR/5mU= github.com/pkg/sftp v1.13.10/go.mod h1:bJ1a7uDhrX/4OII+agvy28lzRvQrmIQuaHrcI1HbeGA= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU= github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= diff --git a/internal/apps/mysql/app.go b/internal/apps/mysql/app.go index 61fe8d32..abd6c35f 100644 --- a/internal/apps/mysql/app.go +++ b/internal/apps/mysql/app.go @@ -40,9 +40,7 @@ func (s *App) Route(r chi.Router) { r.Get("/load", s.Load) r.Get("/config", s.GetConfig) r.Post("/config", s.UpdateConfig) - r.Post("/clear_log", s.ClearLog) r.Get("/slow_log", s.SlowLog) - r.Post("/clear_slow_log", s.ClearSlowLog) r.Get("/root_password", s.GetRootPassword) r.Post("/root_password", s.SetRootPassword) r.Get("/config_tune", s.GetConfigTune) @@ -194,31 +192,11 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) { service.Success(w, load) } -// ClearLog 清空日志 -func (s *App) ClearLog(w http.ResponseWriter, r *http.Request) { - if err := systemctl.LogClear("mysqld"); err != nil { - service.Error(w, http.StatusInternalServerError, "%v", err) - return - } - - service.Success(w, nil) -} - // SlowLog 获取慢查询日志 func (s *App) SlowLog(w http.ResponseWriter, r *http.Request) { service.Success(w, fmt.Sprintf("%s/server/mysql/mysql-slow.log", app.Root)) } -// ClearSlowLog 清空慢查询日志 -func (s *App) ClearSlowLog(w http.ResponseWriter, r *http.Request) { - if _, err := shell.Execf("cat /dev/null > %s/server/mysql/mysql-slow.log", app.Root); err != nil { - service.Error(w, http.StatusInternalServerError, "%v", err) - return - } - - service.Success(w, nil) -} - // GetRootPassword 获取root密码 func (s *App) GetRootPassword(w http.ResponseWriter, r *http.Request) { rootPassword, err := s.settingRepo.Get(biz.SettingKeyMySQLRootPassword) diff --git a/internal/apps/postgresql/app.go b/internal/apps/postgresql/app.go index 4ba49b50..07fa1c8b 100644 --- a/internal/apps/postgresql/app.go +++ b/internal/apps/postgresql/app.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" "os" + "path/filepath" "strings" - "time" "github.com/go-chi/chi/v5" "github.com/leonelquinteros/gotext" @@ -41,7 +41,6 @@ func (s *App) Route(r chi.Router) { r.Post("/user_config", s.UpdateUserConfig) r.Get("/load", s.Load) r.Get("/log", s.Log) - r.Post("/clear_log", s.ClearLog) r.Get("/postgres_password", s.GetPostgresPassword) r.Post("/postgres_password", s.SetPostgresPassword) r.Get("/config_tune", s.GetConfigTune) @@ -175,19 +174,15 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) { service.Success(w, data) } -// Log 获取日志 +// Log 获取应用日志路径列表 func (s *App) Log(w http.ResponseWriter, r *http.Request) { - service.Success(w, fmt.Sprintf("%s/server/postgresql/logs/postgresql-%s.log", app.Root, time.Now().Format(time.DateOnly))) -} - -// ClearLog 清空日志 -func (s *App) ClearLog(w http.ResponseWriter, r *http.Request) { - if _, err := shell.Execf("rm -rf %s/server/postgresql/logs/postgresql-*.log", app.Root); err != nil { + paths, err := filepath.Glob(fmt.Sprintf("%s/server/postgresql/logs/postgresql-*.log", app.Root)) + if err != nil { service.Error(w, http.StatusInternalServerError, "%v", err) return } - service.Success(w, nil) + service.Success(w, paths) } // GetPostgresPassword 获取 postgres 用户密码 diff --git a/internal/apps/supervisor/app.go b/internal/apps/supervisor/app.go index 53d51c51..54382224 100644 --- a/internal/apps/supervisor/app.go +++ b/internal/apps/supervisor/app.go @@ -37,7 +37,6 @@ func NewApp(t *gotext.Locale) *App { func (s *App) Route(r chi.Router) { r.Get("/service", s.Service) - r.Post("/clear_log", s.ClearLog) r.Get("/config", s.GetConfig) r.Post("/config", s.UpdateConfig) r.Get("/processes", s.Processes) @@ -45,7 +44,6 @@ func (s *App) Route(r chi.Router) { r.Post("/processes/{process}/stop", s.StopProcess) r.Post("/processes/{process}/restart", s.RestartProcess) r.Get("/processes/{process}/log", s.ProcessLog) - r.Post("/processes/{process}/clear_log", s.ClearProcessLog) r.Get("/processes/{process}", s.ProcessConfig) r.Post("/processes/{process}", s.UpdateProcessConfig) r.Delete("/processes/{process}", s.DeleteProcess) @@ -57,16 +55,6 @@ func (s *App) Service(w http.ResponseWriter, r *http.Request) { service.Success(w, s.name) } -// ClearLog 清空日志 -func (s *App) ClearLog(w http.ResponseWriter, r *http.Request) { - if _, err := shell.Execf(`cat /dev/null > /var/log/supervisor/supervisord.log`); err != nil { - service.Error(w, http.StatusInternalServerError, "%v", err) - return - } - - service.Success(w, nil) -} - // GetConfig 获取配置 func (s *App) GetConfig(w http.ResponseWriter, r *http.Request) { var config string @@ -227,35 +215,6 @@ func (s *App) ProcessLog(w http.ResponseWriter, r *http.Request) { service.Success(w, logPath) } -// ClearProcessLog 清空进程日志 -func (s *App) ClearProcessLog(w http.ResponseWriter, r *http.Request) { - req, err := service.Bind[ProcessName](r) - if err != nil { - service.Error(w, http.StatusUnprocessableEntity, "%v", err) - return - } - - name := programName(req.Process) - var logPath string - if os.IsRHEL() { - logPath, err = shell.Execf(`cat '/etc/supervisord.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, name) - } else { - logPath, err = shell.Execf(`cat '/etc/supervisor/conf.d/%s.conf' | grep stdout_logfile= | awk -F "=" '{print $2}'`, name) - } - - if err != nil { - service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get log path for process %s: %v", req.Process, err)) - return - } - - if _, err = shell.Execf(`cat /dev/null > '%s'`, logPath); err != nil { - service.Error(w, http.StatusInternalServerError, "%v", err) - return - } - - service.Success(w, nil) -} - // ProcessConfig 获取进程配置 func (s *App) ProcessConfig(w http.ResponseWriter, r *http.Request) { req, err := service.Bind[ProcessName](r) diff --git a/internal/biz/website.go b/internal/biz/website.go index a43bbbac..8cd22193 100644 --- a/internal/biz/website.go +++ b/internal/biz/website.go @@ -45,7 +45,6 @@ type WebsiteRepo interface { Create(ctx context.Context, req *request.WebsiteCreate) (*Website, error) Update(ctx context.Context, req *request.WebsiteUpdate) error Delete(ctx context.Context, req *request.WebsiteDelete) error - ClearLog(id uint) error UpdateRemark(id uint, remark string) error ResetConfig(id uint) error UpdateStatus(id uint, status bool) error diff --git a/internal/data/website.go b/internal/data/website.go index 4d5b0357..bc2d41f7 100644 --- a/internal/data/website.go +++ b/internal/data/website.go @@ -828,16 +828,6 @@ func (r *websiteRepo) Delete(ctx context.Context, req *request.WebsiteDelete) er return r.reloadWebServer() } -func (r *websiteRepo) ClearLog(id uint) error { - website := new(biz.Website) - if err := r.db.Where("id", id).First(website).Error; err != nil { - return err - } - - _, err := shell.Execf(`cat /dev/null > %s/sites/%s/log/access.log`, app.Root, website.Name) - return err -} - func (r *websiteRepo) UpdateRemark(id uint, remark string) error { website := new(biz.Website) if err := r.db.Where("id", id).First(website).Error; err != nil { diff --git a/internal/route/http.go b/internal/route/http.go index bb596c09..46c18b7e 100644 --- a/internal/route/http.go +++ b/internal/route/http.go @@ -264,7 +264,6 @@ func (route *Http) Register(r *chi.Mux) { r.Get("/{id}", route.website.Get) r.Put("/{id}", route.website.Update) r.Delete("/{id}", route.website.Delete) - r.Delete("/{id}/log", route.website.ClearLog) r.Post("/{id}/update_remark", route.website.UpdateRemark) r.Post("/{id}/reset_config", route.website.ResetConfig) r.Post("/{id}/status", route.website.UpdateStatus) @@ -432,8 +431,6 @@ func (route *Http) Register(r *chi.Mux) { r.Get("/{version}/load", route.environmentPHP.Load) r.Get("/{version}/log", route.environmentPHP.Log) r.Get("/{version}/slow_log", route.environmentPHP.SlowLog) - r.Post("/{version}/clear_log", route.environmentPHP.ClearLog) - r.Post("/{version}/clear_slow_log", route.environmentPHP.ClearSlowLog) r.Get("/{version}/modules", route.environmentPHP.ModuleList) r.Post("/{version}/modules", route.environmentPHP.InstallModule) r.Delete("/{version}/modules", route.environmentPHP.UninstallModule) @@ -556,6 +553,7 @@ func (route *Http) Register(r *chi.Mux) { r.Post("/create", route.file.Create) r.Get("/content", route.file.Content) r.Post("/save", route.file.Save) + r.Post("/truncate", route.file.Truncate) r.Post("/delete", route.file.Delete) r.Post("/upload", route.file.Upload) r.Post("/exist", route.file.Exist) @@ -606,6 +604,7 @@ func (route *Http) Register(r *chi.Mux) { r.Post("/reload", route.systemctl.Reload) r.Post("/start", route.systemctl.Start) r.Post("/stop", route.systemctl.Stop) + r.Post("/clear_log", route.systemctl.ClearLog) }) r.Route("/toolbox_network", func(r chi.Router) { diff --git a/internal/service/environment_php.go b/internal/service/environment_php.go index 2237f745..9ad49f68 100644 --- a/internal/service/environment_php.go +++ b/internal/service/environment_php.go @@ -249,44 +249,6 @@ func (s *EnvironmentPHPService) SlowLog(w http.ResponseWriter, r *http.Request) Success(w, fmt.Sprintf("%s/server/php/%d/var/log/slow.log", app.Root, req.Version)) } -func (s *EnvironmentPHPService) ClearLog(w http.ResponseWriter, r *http.Request) { - req, err := Bind[request.EnvironmentPHPVersion](r) - if err != nil { - Error(w, http.StatusUnprocessableEntity, "%v", err) - return - } - if !s.environmentRepo.IsInstalled("php", fmt.Sprintf("%d", req.Version)) { - Error(w, http.StatusUnprocessableEntity, s.t.Get("PHP-%d is not installed", req.Version)) - return - } - - if _, err = shell.Execf("cat /dev/null > %s/server/php/%d/var/log/php-fpm.log", app.Root, req.Version); err != nil { - Error(w, http.StatusInternalServerError, "%v", err) - return - } - - Success(w, nil) -} - -func (s *EnvironmentPHPService) ClearSlowLog(w http.ResponseWriter, r *http.Request) { - req, err := Bind[request.EnvironmentPHPVersion](r) - if err != nil { - Error(w, http.StatusUnprocessableEntity, "%v", err) - return - } - if !s.environmentRepo.IsInstalled("php", fmt.Sprintf("%d", req.Version)) { - Error(w, http.StatusUnprocessableEntity, s.t.Get("PHP-%d is not installed", req.Version)) - return - } - - if _, err = shell.Execf("cat /dev/null > %s/server/php/%d/var/log/slow.log", app.Root, req.Version); err != nil { - Error(w, http.StatusInternalServerError, "%v", err) - return - } - - Success(w, nil) -} - func (s *EnvironmentPHPService) ModuleList(w http.ResponseWriter, r *http.Request) { req, err := Bind[request.EnvironmentPHPVersion](r) if err != nil { diff --git a/internal/service/file.go b/internal/service/file.go index 485fa78a..138998b7 100644 --- a/internal/service/file.go +++ b/internal/service/file.go @@ -106,6 +106,22 @@ func (s *FileService) Content(w http.ResponseWriter, r *http.Request) { }) } +// Truncate 截断文件至 0 长度(保留文件本身和元数据) +func (s *FileService) Truncate(w http.ResponseWriter, r *http.Request) { + req, err := Bind[request.FilePath](r) + if err != nil { + Error(w, http.StatusUnprocessableEntity, "%v", err) + return + } + + if err = stdos.Truncate(req.Path, 0); err != nil { + Error(w, http.StatusInternalServerError, "%v", err) + return + } + + Success(w, nil) +} + func (s *FileService) Save(w http.ResponseWriter, r *http.Request) { req, err := Bind[request.FileSave](r) if err != nil { diff --git a/internal/service/systemctl.go b/internal/service/systemctl.go index 28f3dc88..a6d920f6 100644 --- a/internal/service/systemctl.go +++ b/internal/service/systemctl.go @@ -140,3 +140,19 @@ func (s *SystemctlService) Stop(w http.ResponseWriter, r *http.Request) { Success(w, nil) } + +// ClearLog 清空指定 systemd 服务的 journald 日志 +func (s *SystemctlService) ClearLog(w http.ResponseWriter, r *http.Request) { + req, err := Bind[request.SystemctlService](r) + if err != nil { + Error(w, http.StatusUnprocessableEntity, "%v", err) + return + } + + if err = systemctl.LogClear(req.Service); err != nil { + Error(w, http.StatusInternalServerError, s.t.Get("failed to clear log for %s service: %v", req.Service, err)) + return + } + + Success(w, nil) +} diff --git a/internal/service/website.go b/internal/service/website.go index b377d7ce..f93397af 100644 --- a/internal/service/website.go +++ b/internal/service/website.go @@ -177,21 +177,6 @@ func (s *WebsiteService) Delete(w http.ResponseWriter, r *http.Request) { Success(w, nil) } -func (s *WebsiteService) ClearLog(w http.ResponseWriter, r *http.Request) { - req, err := Bind[request.ID](r) - if err != nil { - Error(w, http.StatusUnprocessableEntity, "%v", err) - return - } - - if err = s.websiteRepo.ClearLog(req.ID); err != nil { - Error(w, http.StatusInternalServerError, "%v", err) - return - } - - Success(w, nil) -} - func (s *WebsiteService) UpdateRemark(w http.ResponseWriter, r *http.Request) { req, err := Bind[request.WebsiteUpdateRemark](r) if err != nil { diff --git a/web/src/api/apps/mariadb/index.ts b/web/src/api/apps/mariadb/index.ts index a16a1564..cbc2f1d6 100644 --- a/web/src/api/apps/mariadb/index.ts +++ b/web/src/api/apps/mariadb/index.ts @@ -7,12 +7,8 @@ export default { config: (): any => http.Get('/apps/mariadb/config'), // 保存配置 saveConfig: (config: string): any => http.Post('/apps/mariadb/config', { config }), - // 清空日志 - clearLog: (): any => http.Post('/apps/mariadb/clear_log'), // 获取慢查询日志 slowLog: (): any => http.Get('/apps/mariadb/slow_log'), - // 清空慢查询日志 - clearSlowLog: (): any => http.Post('/apps/mariadb/clear_slow_log'), // 获取 root 密码 rootPassword: (): any => http.Get('/apps/mariadb/root_password'), // 修改 root 密码 diff --git a/web/src/api/apps/mysql/index.ts b/web/src/api/apps/mysql/index.ts index 9d055abb..95301848 100644 --- a/web/src/api/apps/mysql/index.ts +++ b/web/src/api/apps/mysql/index.ts @@ -7,12 +7,8 @@ export default { config: (): any => http.Get('/apps/mysql/config'), // 保存配置 saveConfig: (config: string): any => http.Post('/apps/mysql/config', { config }), - // 清空日志 - clearLog: (): any => http.Post('/apps/mysql/clear_log'), // 获取慢查询日志 slowLog: (): any => http.Get('/apps/mysql/slow_log'), - // 清空慢查询日志 - clearSlowLog: (): any => http.Post('/apps/mysql/clear_slow_log'), // 获取 root 密码 rootPassword: (): any => http.Get('/apps/mysql/root_password'), // 修改 root 密码 diff --git a/web/src/api/apps/percona/index.ts b/web/src/api/apps/percona/index.ts index 6118053b..85d498e6 100644 --- a/web/src/api/apps/percona/index.ts +++ b/web/src/api/apps/percona/index.ts @@ -7,12 +7,8 @@ export default { config: (): any => http.Get('/apps/percona/config'), // 保存配置 saveConfig: (config: string): any => http.Post('/apps/percona/config', { config }), - // 清空日志 - clearLog: (): any => http.Post('/apps/percona/clear_log'), // 获取慢查询日志 slowLog: (): any => http.Get('/apps/percona/slow_log'), - // 清空慢查询日志 - clearSlowLog: (): any => http.Post('/apps/percona/clear_slow_log'), // 获取 root 密码 rootPassword: (): any => http.Get('/apps/percona/root_password'), // 修改 root 密码 diff --git a/web/src/api/apps/postgresql/index.ts b/web/src/api/apps/postgresql/index.ts index 55601d28..9e32fd2b 100644 --- a/web/src/api/apps/postgresql/index.ts +++ b/web/src/api/apps/postgresql/index.ts @@ -13,8 +13,6 @@ export default { saveUserConfig: (config: string): any => http.Post('/apps/postgresql/user_config', { config }), // 获取日志 log: (): any => http.Get('/apps/postgresql/log'), - // 清空错误日志 - clearLog: (): any => http.Post('/apps/postgresql/clear_log'), // 获取 postgres 密码 postgresPassword: (): any => http.Get('/apps/postgresql/postgres_password'), // 设置 postgres 密码 diff --git a/web/src/api/apps/supervisor/index.ts b/web/src/api/apps/supervisor/index.ts index 81622401..3943dbfa 100644 --- a/web/src/api/apps/supervisor/index.ts +++ b/web/src/api/apps/supervisor/index.ts @@ -5,8 +5,6 @@ export default { service: (): any => http.Get('/apps/supervisor/service'), // 获取错误日志 log: (): any => http.Get('/apps/supervisor/log'), - // 清空错误日志 - clearLog: (): any => http.Post('/apps/supervisor/clear_log'), // 获取配置 config: (): any => http.Get('/apps/supervisor/config'), // 保存配置 @@ -23,9 +21,6 @@ export default { http.Post(`/apps/supervisor/processes/${process}/restart`), // 进程日志 processLog: (process: string): any => http.Get(`/apps/supervisor/processes/${process}/log`), - // 清空进程日志 - clearProcessLog: (process: string): any => - http.Post(`/apps/supervisor/processes/${process}/clear_log`), // 进程配置 processConfig: (process: string): any => http.Get(`/apps/supervisor/processes/${process}`), // 保存进程配置 diff --git a/web/src/api/panel/environment/php/index.ts b/web/src/api/panel/environment/php/index.ts index c645c155..45494b23 100644 --- a/web/src/api/panel/environment/php/index.ts +++ b/web/src/api/panel/environment/php/index.ts @@ -19,12 +19,8 @@ export default { load: (slug: number): any => http.Get(`/environment/php/${slug}/load`), // 获取日志 log: (slug: number): any => http.Get(`/environment/php/${slug}/log`), - // 清空日志 - clearLog: (slug: number): any => http.Post(`/environment/php/${slug}/clear_log`), // 获取慢日志 slowLog: (slug: number): any => http.Get(`/environment/php/${slug}/slow_log`), - // 清空慢日志 - clearSlowLog: (slug: number): any => http.Post(`/environment/php/${slug}/clear_slow_log`), // 拓展列表 modules: (slug: number): any => http.Get(`/environment/php/${slug}/modules`), // 安装拓展 diff --git a/web/src/api/panel/file/index.ts b/web/src/api/panel/file/index.ts index f2d0e1c2..f099e8d0 100644 --- a/web/src/api/panel/file/index.ts +++ b/web/src/api/panel/file/index.ts @@ -7,6 +7,8 @@ export default { content: (path: string): any => http.Get('/file/content', { params: { path } }), // 保存文件 save: (path: string, content: string): any => http.Post('/file/save', { path, content }), + // 截断文件至 0 长度 + truncate: (path: string): any => http.Post('/file/truncate', { path }), // 删除文件 delete: (path: string): any => http.Post('/file/delete', { path }), // 上传文件 diff --git a/web/src/api/panel/systemctl/index.ts b/web/src/api/panel/systemctl/index.ts index be2f26cb..977f473b 100644 --- a/web/src/api/panel/systemctl/index.ts +++ b/web/src/api/panel/systemctl/index.ts @@ -16,5 +16,7 @@ export default { // 启动服务 start: (service: string): any => http.Post('/systemctl/start', { service }), // 停止服务 - stop: (service: string): any => http.Post('/systemctl/stop', { service }) + stop: (service: string): any => http.Post('/systemctl/stop', { service }), + // 清空指定服务的 journald 日志 + clearLog: (service: string): any => http.Post('/systemctl/clear_log', { service }) } diff --git a/web/src/api/panel/website/index.ts b/web/src/api/panel/website/index.ts index 9a212150..1c97adb7 100644 --- a/web/src/api/panel/website/index.ts +++ b/web/src/api/panel/website/index.ts @@ -19,8 +19,6 @@ export default { config: (id: number): any => http.Get('/website/' + id), // 保存网站配置 saveConfig: (id: number, data: any): any => http.Put(`/website/${id}`, data), - // 清空日志 - clearLog: (id: number): any => http.Delete('/website/' + id + '/log'), // 更新备注 updateRemark: (id: number, remark: string): any => http.Post(`/website/${id}` + '/update_remark', { remark }), diff --git a/web/src/components/common/RealtimeLog.vue b/web/src/components/common/RealtimeLog.vue index 1bf43116..7b6fd61a 100644 --- a/web/src/components/common/RealtimeLog.vue +++ b/web/src/components/common/RealtimeLog.vue @@ -203,6 +203,14 @@ onMounted(async () => { onUnmounted(() => { closeTerminal() }) + +// 由父组件在清空源文件/日志成功后调用,清掉终端 buffer 里残留的旧内容 +const clear = () => { + term.value?.clear() + term.value?.reset() +} + +defineExpose({ clear })