feat: fix agent logger display
This commit is contained in:
@@ -347,3 +347,29 @@ func (fc *FileController) UploadFiles(c *gin.Context) {
|
||||
|
||||
utils.SuccessMsg(c, "上传成功")
|
||||
}
|
||||
|
||||
func (fc *FileController) DownloadFile(c *gin.Context) {
|
||||
filePath := c.Query("path")
|
||||
if filePath == "" {
|
||||
utils.BadRequest(c, "path参数必填")
|
||||
return
|
||||
}
|
||||
|
||||
fullPath := filepath.Join(fc.workDir, filepath.Clean(filePath))
|
||||
if !strings.HasPrefix(fullPath, fc.workDir) {
|
||||
utils.Forbidden(c, "访问被拒绝")
|
||||
return
|
||||
}
|
||||
|
||||
info, err := os.Stat(fullPath)
|
||||
if err != nil || info.IsDir() {
|
||||
utils.NotFound(c, "文件不存在")
|
||||
return
|
||||
}
|
||||
|
||||
c.Header("Content-Description", "File Transfer")
|
||||
c.Header("Content-Transfer-Encoding", "binary")
|
||||
c.Header("Content-Disposition", "attachment; filename="+filepath.Base(fullPath))
|
||||
c.Header("Content-Type", "application/octet-stream")
|
||||
c.File(fullPath)
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"fmt"
|
||||
"github.com/engigu/baihu-panel/internal/constant"
|
||||
"github.com/engigu/baihu-panel/internal/database"
|
||||
"github.com/engigu/baihu-panel/internal/models"
|
||||
"github.com/engigu/baihu-panel/internal/services"
|
||||
"github.com/engigu/baihu-panel/internal/services/tasks"
|
||||
"github.com/engigu/baihu-panel/internal/utils"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
|
||||
@@ -75,6 +75,8 @@ func (m *CronManager) AddTask(task CronTask) error {
|
||||
cmd := task.GetCommand()
|
||||
name := task.GetName()
|
||||
timeout := task.GetTimeout()
|
||||
workDir := task.GetWorkDir()
|
||||
envs := task.GetEnvs()
|
||||
|
||||
entryID, err := m.cron.AddFunc(task.GetSchedule(), func() {
|
||||
defer func() {
|
||||
@@ -90,6 +92,8 @@ func (m *CronManager) AddTask(task CronTask) error {
|
||||
Command: cmd,
|
||||
Type: TaskTypeCron,
|
||||
Timeout: timeout,
|
||||
WorkDir: workDir,
|
||||
Envs: ParseEnvVars(envs),
|
||||
}
|
||||
|
||||
// 如果有关联的 Scheduler,加入队列执行
|
||||
|
||||
@@ -17,6 +17,8 @@ type Task interface {
|
||||
GetName() string
|
||||
GetCommand() string
|
||||
GetTimeout() int
|
||||
GetWorkDir() string
|
||||
GetEnvs() string
|
||||
}
|
||||
|
||||
// CronTask 计划任务接口
|
||||
|
||||
@@ -104,6 +104,17 @@ func SetupFileOutput(logDir string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetOutput 直接设置 Log 实例
|
||||
func SetOutput(l *zap.Logger) {
|
||||
Log = l
|
||||
Sugar = l.Sugar()
|
||||
}
|
||||
|
||||
// SetSugar 直接设置 Sugar 实例
|
||||
func SetSugar(s *zap.SugaredLogger) {
|
||||
Sugar = s
|
||||
}
|
||||
|
||||
// SetLevel 设置日志级别
|
||||
func SetLevel(level string) {
|
||||
switch level {
|
||||
|
||||
@@ -35,4 +35,4 @@ type Script struct {
|
||||
|
||||
func (Script) TableName() string {
|
||||
return constant.TablePrefix + "scripts"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,14 @@ func (t *Task) GetTimeout() int {
|
||||
return t.Timeout
|
||||
}
|
||||
|
||||
func (t *Task) GetWorkDir() string {
|
||||
return t.WorkDir
|
||||
}
|
||||
|
||||
func (t *Task) GetEnvs() string {
|
||||
return t.Envs
|
||||
}
|
||||
|
||||
func (t *Task) GetSchedule() string {
|
||||
return t.Schedule
|
||||
}
|
||||
|
||||
@@ -20,4 +20,4 @@ type User struct {
|
||||
|
||||
func (User) TableName() string {
|
||||
return constant.TablePrefix + "users"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,6 +155,7 @@ func Setup(c *Controllers) *gin.Engine {
|
||||
{
|
||||
files.GET("/tree", c.File.GetFileTree)
|
||||
files.GET("/content", c.File.GetFileContent)
|
||||
files.GET("/download", c.File.DownloadFile)
|
||||
files.POST("/content", c.File.SaveFileContent)
|
||||
files.POST("/create", c.File.CreateFile)
|
||||
files.POST("/delete", c.File.DeleteFile)
|
||||
|
||||
Reference in New Issue
Block a user