Initial commit: TaskPool React panel

- React frontend with route-level code splitting
- Backend rebranded from Baihu to TaskPool
- DB brand migration script and local compatibility
This commit is contained in:
2026-07-26 08:43:52 +08:00
commit e6956aa001
397 changed files with 73621 additions and 0 deletions
+144
View File
@@ -0,0 +1,144 @@
package vo
import (
"time"
"github.com/engigu/taskpool/internal/models"
"github.com/engigu/taskpool/internal/utils"
)
// AgentVO 代理视图对象
type AgentVO struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Status string `json:"status"`
LastSeen *models.LocalTime `json:"last_seen"`
IP string `json:"ip"`
Version string `json:"version"`
BuildTime string `json:"build_time"`
Hostname string `json:"hostname"`
OS string `json:"os"`
Arch string `json:"arch"`
ForceUpdate bool `json:"force_update"`
Enabled bool `json:"enabled"`
SchedulerConfig *AgentSchedulerConfigVO `json:"scheduler_config"`
CreatedAt models.LocalTime `json:"created_at"`
UpdatedAt models.LocalTime `json:"updated_at"`
// 隐藏 Token 和 MachineID
}
// ToAgentVO 将 Agent 模型转换为 AgentVO
func ToAgentVO(agent *models.Agent) *AgentVO {
if agent == nil {
return nil
}
var schedulerConfigVO *AgentSchedulerConfigVO
if agent.SchedulerConfig.WorkerCount > 0 {
schedulerConfigVO = &AgentSchedulerConfigVO{
WorkerCount: agent.SchedulerConfig.WorkerCount,
QueueSize: agent.SchedulerConfig.QueueSize,
RateInterval: int(agent.SchedulerConfig.RateInterval / time.Millisecond),
Verbose: agent.SchedulerConfig.Verbose,
StrictQueue: agent.SchedulerConfig.StrictQueue,
}
}
return &AgentVO{
ID: agent.ID,
Name: agent.Name,
Description: agent.Description,
Status: agent.Status,
LastSeen: agent.LastSeen,
IP: agent.IP,
Version: agent.Version,
BuildTime: agent.BuildTime,
Hostname: agent.Hostname,
OS: agent.OS,
Arch: agent.Arch,
ForceUpdate: agent.ForceUpdate,
Enabled: utils.DerefBool(agent.Enabled, true),
SchedulerConfig: schedulerConfigVO,
CreatedAt: agent.CreatedAt,
UpdatedAt: agent.UpdatedAt,
}
}
// ToAgentVOList 将 Agent 模型列表转换为 AgentVO 列表
func ToAgentVOList(agents []*models.Agent) []*AgentVO {
if agents == nil {
return nil
}
vos := make([]*AgentVO, len(agents))
for i, a := range agents {
vos[i] = ToAgentVO(a)
}
return vos
}
// ToAgentVOListFromModels 将 Agent 模型列表转换为 AgentVO 列表
func ToAgentVOListFromModels(agents []models.Agent) []*AgentVO {
vos := make([]*AgentVO, len(agents))
for i := range agents {
vos[i] = ToAgentVO(&agents[i])
}
return vos
}
// AgentTokenVO 代理令牌视图对象
type AgentTokenVO struct {
ID string `json:"id"`
Token string `json:"token"`
Remark string `json:"remark"`
MaxUses int `json:"max_uses"`
UsedCount int `json:"used_count"`
ExpiresAt *models.LocalTime `json:"expires_at"`
Enabled bool `json:"enabled"`
CreatedAt models.LocalTime `json:"created_at"`
}
// ToAgentTokenVO 将 AgentToken 模型转换为 AgentTokenVO
func ToAgentTokenVO(token *models.AgentToken) *AgentTokenVO {
if token == nil {
return nil
}
return &AgentTokenVO{
ID: token.ID,
Token: token.Token,
Remark: token.Remark,
MaxUses: token.MaxUses,
UsedCount: token.UsedCount,
ExpiresAt: token.ExpiresAt,
Enabled: utils.DerefBool(token.Enabled, true),
CreatedAt: token.CreatedAt,
}
}
// ToAgentTokenVOList 将 AgentToken 模型列表转换为 AgentTokenVO 列表
func ToAgentTokenVOList(tokens []*models.AgentToken) []*AgentTokenVO {
if tokens == nil {
return nil
}
vos := make([]*AgentTokenVO, len(tokens))
for i, t := range tokens {
vos[i] = ToAgentTokenVO(t)
}
return vos
}
// ToAgentTokenVOListFromModels 将 AgentToken 模型列表转换为 AgentTokenVO 列表
func ToAgentTokenVOListFromModels(tokens []models.AgentToken) []*AgentTokenVO {
vos := make([]*AgentTokenVO, len(tokens))
for i := range tokens {
vos[i] = ToAgentTokenVO(&tokens[i])
}
return vos
}
// AgentSchedulerConfigVO 调度配置视图对象
type AgentSchedulerConfigVO struct {
WorkerCount int `json:"worker_count"`
QueueSize int `json:"queue_size"`
RateInterval int `json:"rate_interval"` // 毫秒
Verbose bool `json:"verbose"`
StrictQueue bool `json:"strict_queue"`
}
+47
View File
@@ -0,0 +1,47 @@
package vo
import (
"time"
"github.com/engigu/taskpool/internal/models"
)
// DependencyVO 依赖包视图对象
type DependencyVO struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Language string `json:"language"`
LangVersion string `json:"lang_version"`
Remark string `json:"remark"`
Log string `json:"log,omitempty"` // 仅在需要时返回
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// ToDependencyVO 将 Dependency 模型转换为 DependencyVO
func ToDependencyVO(dep *models.Dependency) *DependencyVO {
if dep == nil {
return nil
}
return &DependencyVO{
ID: dep.ID,
Name: dep.Name,
Version: dep.Version,
Language: dep.Language,
LangVersion: dep.LangVersion,
Remark: dep.Remark,
Log: string(dep.Log),
CreatedAt: dep.CreatedAt,
UpdatedAt: dep.UpdatedAt,
}
}
// ToDependencyVOListFromModels 将 Dependency 模型列表转换为 DependencyVO 列表
func ToDependencyVOListFromModels(deps []models.Dependency) []*DependencyVO {
vos := make([]*DependencyVO, len(deps))
for i := range deps {
vos[i] = ToDependencyVO(&deps[i])
}
return vos
}
+37
View File
@@ -0,0 +1,37 @@
package vo
import (
"github.com/engigu/taskpool/internal/models"
)
// ScriptVO 脚本视图对象
type ScriptVO struct {
ID string `json:"id"`
Name string `json:"name"`
Content string `json:"content,omitempty"` // 仅在拉取详情时返回
CreatedAt models.LocalTime `json:"created_at"`
UpdatedAt models.LocalTime `json:"updated_at"`
}
// ToScriptVO 将 Script 模型转换为 ScriptVO
func ToScriptVO(script *models.Script) *ScriptVO {
if script == nil {
return nil
}
return &ScriptVO{
ID: script.ID,
Name: script.Name,
Content: string(script.Content),
CreatedAt: script.CreatedAt,
UpdatedAt: script.UpdatedAt,
}
}
// ToScriptVOListFromModels 将 Script 模型列表转换为 ScriptVO 列表
func ToScriptVOListFromModels(scripts []models.Script) []*ScriptVO {
vos := make([]*ScriptVO, len(scripts))
for i := range scripts {
vos[i] = ToScriptVO(&scripts[i])
}
return vos
}
+108
View File
@@ -0,0 +1,108 @@
package vo
import (
"github.com/engigu/taskpool/internal/constant"
"github.com/engigu/taskpool/internal/models"
"github.com/engigu/taskpool/internal/utils"
)
// UserVO 用户视图对象
type UserVO struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Role string `json:"role"`
CreatedAt models.LocalTime `json:"created_at"`
UpdatedAt models.LocalTime `json:"updated_at"`
}
// ToUserVO 将 User 模型转换为 UserVO
func ToUserVO(user *models.User) *UserVO {
if user == nil {
return nil
}
return &UserVO{
ID: user.ID,
Username: user.Username,
Email: user.Email,
Role: user.Role,
CreatedAt: user.CreatedAt,
UpdatedAt: user.UpdatedAt,
}
}
// EnvVO 环境变量视图对象
type EnvVO struct {
ID string `json:"id"`
Name string `json:"name"`
Value string `json:"value"`
Remark string `json:"remark"`
Type string `json:"type"`
Tags string `json:"tags"`
Hidden bool `json:"hidden"`
Enabled bool `json:"enabled"`
CreatedAt models.LocalTime `json:"created_at"`
UpdatedAt models.LocalTime `json:"updated_at"`
}
// ToEnvVO 将 Env 模型转换为 EnvVO
func ToEnvVO(env *models.EnvironmentVariable) *EnvVO {
if env == nil {
return nil
}
val := string(env.Value)
if env.Type == constant.EnvTypeSecret {
val = "********"
}
return &EnvVO{
ID: env.ID,
Name: env.Name,
Value: val,
Remark: env.Remark,
Type: env.Type,
Tags: env.Tags,
Hidden: utils.DerefBool(env.Hidden, true),
Enabled: utils.DerefBool(env.Enabled, true),
CreatedAt: env.CreatedAt,
UpdatedAt: env.UpdatedAt,
}
}
// ToEnvVOList 将 Env 模型列表转换为 EnvVO 列表
func ToEnvVOList(envs []*models.EnvironmentVariable) []*EnvVO {
if envs == nil {
return nil
}
vos := make([]*EnvVO, len(envs))
for i, e := range envs {
vos[i] = ToEnvVO(e)
}
return vos
}
// ToEnvVOListFromModels 将 Env 模型列表转换为 EnvVO 列表
func ToEnvVOListFromModels(envs []models.EnvironmentVariable) []*EnvVO {
vos := make([]*EnvVO, len(envs))
for i := range envs {
vos[i] = ToEnvVO(&envs[i])
}
return vos
}
// LoginLogVO 登录日志视图对象
type LoginLogVO struct {
ID string `json:"id"`
Username string `json:"username"`
IP string `json:"ip"`
UserAgent string `json:"user_agent"`
Status string `json:"status"`
Message string `json:"message"`
CreatedAt models.LocalTime `json:"created_at"`
}
// TokenConfig Token 配置结构体
type TokenConfig struct {
Enabled bool `json:"enabled"`
Token string `json:"token"`
ExpireAt string `json:"expire_at"`
}
+263
View File
@@ -0,0 +1,263 @@
package vo
import (
"github.com/engigu/taskpool/internal/executor"
"github.com/engigu/taskpool/internal/models"
"github.com/engigu/taskpool/internal/utils"
)
// TaskCreateReq 任务创建请求
type TaskCreateReq struct {
Name string `json:"name" binding:"required" example:"测试任务"`
Remark string `json:"remark" example:"备注信息"`
Command string `json:"command" example:"echo 'Hello World'"`
PreCommand string `json:"pre_command" example:"echo 'pre'"`
PostCommand string `json:"post_command" example:"echo 'post'"`
Tags string `json:"tags" example:"test,dev"`
Type string `json:"type" example:"repo"` // 可以是 common, repo 等
Config string `json:"config" swaggertype:"string" example:"{\"source_url\":\"https://github.com/abc/repo\",\"branch\":\"main\"}"`
Schedule string `json:"schedule" example:"0 0 * * *"`
Timeout int `json:"timeout" example:"3600"`
WorkDir string `json:"work_dir" example:"/tmp"`
CleanConfig string `json:"clean_config" example:"true"`
Envs string `json:"envs" example:"{\"ENV_VAR\":\"value\"}"`
Languages models.TaskLanguages `json:"languages"`
AgentID *string `json:"agent_id" example:"agent-1"`
TriggerType string `json:"trigger_type" example:"cron"`
RetryCount int `json:"retry_count" example:"3"`
RetryInterval int `json:"retry_interval" example:"60"`
RandomRange int `json:"random_range" example:"10"`
PinType string `json:"pin_type" example:"time"`
}
// TaskUpdateReq 任务更新请求
type TaskUpdateReq struct {
Name string `json:"name" example:"测试任务"`
Remark string `json:"remark" example:"备注信息"`
Command string `json:"command" example:"echo 'Hello World'"`
PreCommand string `json:"pre_command" example:"echo 'pre'"`
PostCommand string `json:"post_command" example:"echo 'post'"`
Tags string `json:"tags" example:"test,dev"`
Type string `json:"type" example:"repo"`
Config string `json:"config" swaggertype:"string" example:"{\"source_url\":\"https://github.com/abc/repo\",\"branch\":\"main\"}"`
Schedule string `json:"schedule" example:"0 0 * * *"`
Timeout int `json:"timeout" example:"3600"`
WorkDir string `json:"work_dir" example:"/tmp"`
CleanConfig string `json:"clean_config" example:"true"`
Envs string `json:"envs" example:"{\"ENV_VAR\":\"value\"}"`
Enabled bool `json:"enabled" example:"true"`
Languages models.TaskLanguages `json:"languages"`
AgentID *string `json:"agent_id" example:"agent-1"`
TriggerType string `json:"trigger_type" example:"cron"`
RetryCount int `json:"retry_count" example:"3"`
RetryInterval int `json:"retry_interval" example:"60"`
RandomRange int `json:"random_range" example:"10"`
PinType string `json:"pin_type" example:"time"`
}
// TaskVO 任务视图对象
type TaskVO struct {
ID string `json:"id"`
Name string `json:"name"`
Remark string `json:"remark"`
Command string `json:"command"`
PreCommand string `json:"pre_command"`
PostCommand string `json:"post_command"`
Tags string `json:"tags"`
Type string `json:"type"`
TriggerType string `json:"trigger_type"`
Config string `json:"config"`
Schedule string `json:"schedule"`
Timeout int `json:"timeout"`
WorkDir string `json:"work_dir"`
CleanConfig string `json:"clean_config"`
Envs string `json:"envs"`
Languages models.TaskLanguages `json:"languages"`
AgentID *string `json:"agent_id"`
RepoTaskID string `json:"repo_task_id"`
Enabled bool `json:"enabled"`
RetryCount int `json:"retry_count"`
RetryInterval int `json:"retry_interval"`
RandomRange int `json:"random_range"`
PinType string `json:"pin_type"`
LastRun *models.LocalTime `json:"last_run"`
NextRun *models.LocalTime `json:"next_run"`
CreatedAt models.LocalTime `json:"created_at"`
UpdatedAt models.LocalTime `json:"updated_at"`
RunningStatus string `json:"running_status"`
}
// ToTaskVO 将 Task 模型转换为 TaskVO
func ToTaskVO(task *models.Task) *TaskVO {
if task == nil {
return nil
}
return &TaskVO{
ID: task.ID,
Name: task.Name,
Remark: task.Remark,
Command: string(task.Command),
PreCommand: string(task.PreCommand),
PostCommand: string(task.PostCommand),
Tags: task.Tags,
Type: task.Type,
TriggerType: task.TriggerType,
Config: string(task.Config),
Schedule: task.Schedule,
Timeout: task.Timeout,
WorkDir: task.WorkDir,
CleanConfig: task.CleanConfig,
Envs: string(task.Envs),
Languages: task.Languages,
AgentID: task.AgentID,
RepoTaskID: task.RepoTaskID,
Enabled: utils.DerefBool(task.Enabled, true),
RetryCount: task.RetryCount,
RetryInterval: task.RetryInterval,
RandomRange: task.RandomRange,
PinType: task.PinType,
LastRun: task.LastRun,
NextRun: task.NextRun,
CreatedAt: task.CreatedAt,
UpdatedAt: task.UpdatedAt,
RunningStatus: func() string {
if task.IsRunning() {
return "running"
}
return "idle"
}(),
}
}
// ToTaskVOList 将 Task 模型列表转换为 TaskVO 列表
func ToTaskVOList(tasks []*models.Task) []*TaskVO {
if tasks == nil {
return nil
}
vos := make([]*TaskVO, len(tasks))
for i, t := range tasks {
vos[i] = ToTaskVO(t)
}
return vos
}
// ToTaskVOListFromModels 将 Task 模型列表转换为 TaskVO 列表
func ToTaskVOListFromModels(tasks []models.Task) []*TaskVO {
vos := make([]*TaskVO, len(tasks))
for i := range tasks {
vos[i] = ToTaskVO(&tasks[i])
}
return vos
}
// TaskLogVO 任务历史视图对象
type TaskLogVO struct {
ID string `json:"id"`
TaskID string `json:"task_id"`
TaskName string `json:"task_name"`
TaskType string `json:"task_type"`
AgentID *string `json:"agent_id"`
Command string `json:"command"`
Error string `json:"error"`
Status string `json:"status"`
Duration int64 `json:"duration"`
ExitCode int `json:"exit_code"`
StartTime *models.LocalTime `json:"start_time"`
EndTime *models.LocalTime `json:"end_time"`
CreatedAt models.LocalTime `json:"created_at"`
Output string `json:"output,omitempty"`
}
// ToTaskLogVO 将 TaskLog 模型转换为 TaskLogVO
// Note: This function assumes the Task field within models.TaskLog is preloaded
// or that taskName and taskType are provided from an external source.
func ToTaskLogVO(log *models.TaskLog) *TaskLogVO {
if log == nil {
return nil
}
return &TaskLogVO{
ID: log.ID,
TaskID: log.TaskID,
AgentID: log.AgentID,
Command: string(log.Command),
Error: string(log.Error),
Status: log.Status,
Duration: log.Duration,
ExitCode: log.ExitCode,
StartTime: log.StartTime,
EndTime: log.EndTime,
CreatedAt: log.CreatedAt,
Output: string(log.Output),
}
}
// ToTaskLogVOList 将 TaskLog 模型列表转换为 TaskLogVO 列表
func ToTaskLogVOList(logs []*models.TaskLog) []*TaskLogVO {
if logs == nil {
return nil
}
vos := make([]*TaskLogVO, len(logs))
for i, l := range logs {
vos[i] = ToTaskLogVO(l)
}
return vos
}
// ToTaskLogVOListFromModels 将 TaskLog 模型列表转换为 TaskLogVO 列表
func ToTaskLogVOListFromModels(logs []models.TaskLog) []*TaskLogVO {
vos := make([]*TaskLogVO, len(logs))
for i := range logs {
vos[i] = ToTaskLogVO(&logs[i])
}
return vos
}
// ExecutionResultVO 任务执行结果视图对象
type ExecutionResultVO struct {
TaskID string `json:"task_id"`
LogID string `json:"log_id,omitempty"`
Success bool `json:"success"`
Status string `json:"status"`
Output string `json:"output,omitempty"`
Error string `json:"error,omitempty"`
Duration int64 `json:"duration,omitempty"`
ExitCode int `json:"exit_code,omitempty"`
StartTime string `json:"start_time,omitempty"`
EndTime string `json:"end_time,omitempty"`
}
// ToExecutionResultVO 将 ExecutionResult 转换为 ExecutionResultVO
func ToExecutionResultVO(res *executor.ExecutionResult) *ExecutionResultVO {
if res == nil {
return nil
}
vo := &ExecutionResultVO{
TaskID: res.TaskID,
LogID: res.LogID,
Success: res.Success,
Status: res.Status,
Output: res.Output,
Error: res.Error,
Duration: res.Duration,
ExitCode: res.ExitCode,
}
if !res.StartTime.IsZero() {
vo.StartTime = res.StartTime.Format("2006-01-02 15:04:05")
}
if !res.EndTime.IsZero() {
vo.EndTime = res.EndTime.Format("2006-01-02 15:04:05")
}
return vo
}
// ToExecutionResultVOList 将 ExecutionResult 列表转换为 ExecutionResultVO 列表
func ToExecutionResultVOList(results []executor.ExecutionResult) []*ExecutionResultVO {
if results == nil {
return nil
}
vos := make([]*ExecutionResultVO, len(results))
for i := range results {
vos[i] = ToExecutionResultVO(&results[i])
}
return vos
}
+8
View File
@@ -0,0 +1,8 @@
package vo
// WSMessage 通用 WebSocket 消息结构
type WSMessage struct {
Type string `json:"type"` // 事件类型: task_status, notice, system_stats
Timestamp int64 `json:"timestamp"` // 毫秒时间戳
Payload interface{} `json:"payload"` // 负载数据
}