Skip to content

Commit

Permalink
feat: 支持实时日志流
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Oct 20, 2024
1 parent 354705e commit 8470339
Show file tree
Hide file tree
Showing 25 changed files with 896 additions and 1,246 deletions.
1 change: 0 additions & 1 deletion internal/biz/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ type CronRepo interface {
Update(req *request.CronUpdate) error
Delete(id uint) error
Status(id uint, status bool) error
Log(id uint) (string, error)
}
3 changes: 1 addition & 2 deletions internal/data/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ func (r *websiteRepo) Get(id uint) (*types.WebsiteSetting, error) {
rewrite, _ := io.Read(filepath.Join(app.Root, "server/vhost/rewrite", website.Name+".conf"))
setting.Rewrite = rewrite
// 访问日志
log, _ := shell.Execf(`tail -n 100 '%s/wwwlogs/%s.log'`, app.Root, website.Name)
setting.Log = log
setting.Log = fmt.Sprintf("%s/wwwlogs/%s.log", app.Root, website.Name)

return setting, err
}
Expand Down
1 change: 0 additions & 1 deletion internal/route/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func Http(r chi.Router) {
r.Get("/{id}", cron.Get)
r.Delete("/{id}", cron.Delete)
r.Post("/{id}/status", cron.Status)
r.Get("/{id}/log", cron.Log)
})

r.Route("/safe", func(r chi.Router) {
Expand Down
16 changes: 0 additions & 16 deletions internal/service/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,3 @@ func (s *CronService) Status(w http.ResponseWriter, r *http.Request) {

Success(w, nil)
}

func (s *CronService) Log(w http.ResponseWriter, r *http.Request) {
req, err := Bind[request.ID](r)
if err != nil {
Error(w, http.StatusUnprocessableEntity, "%v", err)
return
}

log, err := s.cronRepo.Log(req.ID)
if err != nil {
Error(w, http.StatusInternalServerError, "%v", err)
return
}

Success(w, log)
}
6 changes: 0 additions & 6 deletions internal/service/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/TheTNB/panel/internal/biz"
"github.com/TheTNB/panel/internal/data"
"github.com/TheTNB/panel/internal/http/request"
"github.com/TheTNB/panel/pkg/shell"
)

type TaskService struct {
Expand Down Expand Up @@ -59,11 +58,6 @@ func (s *TaskService) Get(w http.ResponseWriter, r *http.Request) {
return
}

log, err := shell.Execf(`tail -n 500 '%s'`, task.Log)
if err == nil {
task.Log = log
}

Success(w, task)
}

Expand Down
2 changes: 2 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"@guolao/vue-monaco-editor": "^1.5.4",
"@vue-js-cron/naive-ui": "^2.0.5",
"@vueuse/core": "^11.1.0",
"@xterm/addon-attach": "^0.11.0",
"@xterm/addon-clipboard": "^0.1.0",
Expand All @@ -29,6 +30,7 @@
"@xterm/addon-webgl": "^0.18.0",
"@xterm/xterm": "^5.5.0",
"axios": "^1.7.7",
"cronstrue": "^2.50.0",
"echarts": "^5.5.1",
"install": "^0.13.0",
"lodash-es": "^4.17.21",
Expand Down
32 changes: 32 additions & 0 deletions web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8470339

Please sign in to comment.