Files
TaskPool/internal/router/register.go
T
admin f7a7d44ebe
Build and Deploy / build-and-push (push) Failing after 42s
feat: 添加安装页面,支持 SQLite 和 Redis 配置
- 新增安装控制器 (install_controller.go)
- 新增安装服务 (install_service.go)
- 添加 Redis 配置结构到配置服务
- 更新路由注册,添加安装 API
- 创建前端安装页面 (Install.tsx)
- 支持 SQLite 和 MySQL 数据库选择
- Redis 为可选配置
- 安装完成后创建管理员账号

API 端点:
- GET /api/v1/install/status - 获取安装状态
- POST /api/v1/install - 执行安装
2026-07-21 17:07:41 +00:00

84 lines
3.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package router
import (
"github.com/engigu/baihu-panel/internal/constant"
"github.com/engigu/baihu-panel/internal/controllers"
"github.com/engigu/baihu-panel/internal/services"
"github.com/engigu/baihu-panel/internal/services/tasks"
)
var executorService *tasks.ExecutorService
func RegisterControllers() *Controllers {
// 初始化服务
settingsService := services.NewSettingsService()
loginLogService := services.NewLoginLogService()
// 执行系统初始化(返回 userService
initService := services.NewInitService(settingsService)
userService := initService.Initialize()
taskService := tasks.NewTaskService()
envService := services.NewEnvService()
scriptService := services.NewScriptService()
sendStatsService := services.NewSendStatsService()
agentWSManager := services.GetAgentWSManager()
systemWSManager := services.GetSystemWSManager()
taskLogService := tasks.NewTaskLogService(sendStatsService)
// 创建任务执行服务(需要依赖注入)
notifyService := services.NewNotificationService()
appLogService := services.NewAppLogService()
interconnectService := services.NewInterconnectService()
// 清理 task 运行状态的任务可以直接由 executorService 承担或在此处通过 Database 直接清理
// 简单期间,我们使用一个新方法 tasks.CleanupRunningTasks() 或者让 executorService 启动时清理
executorService = tasks.NewExecutorService(taskService, taskLogService, agentWSManager, settingsService, envService)
// 启动时清理残留的运行状态
_ = executorService.CleanupRunningTasks()
// 启动计划任务
executorService.StartCron()
// 初始化所有关注系统总线的服务
setupEventHandlers(appLogService, notifyService, loginLogService, systemWSManager)
startAppLogCleanup(appLogService)
taskController := controllers.NewTaskController(taskService, executorService)
envController := controllers.NewEnvController(envService)
// 初始化并返回控制器
return &Controllers{
Task: taskController,
Auth: controllers.NewAuthController(userService, settingsService, loginLogService),
Env: envController,
Script: controllers.NewScriptController(scriptService),
Executor: controllers.NewExecutorController(executorService),
File: controllers.NewFileController(constant.ScriptsWorkDir),
Dashboard: controllers.NewDashboardController(executorService),
Log: controllers.NewLogController(),
LogSSE: controllers.NewLogSSEController(),
Terminal: controllers.NewTerminalController(envService),
Settings: controllers.NewSettingsController(userService, loginLogService, executorService),
Dependency: controllers.NewDependencyController(),
Agent: controllers.NewAgentController(settingsService),
Mise: controllers.NewMiseController(services.NewMiseService()),
Notification: controllers.NewNotificationController(),
AppLog: controllers.NewAppLogController(),
SystemWS: controllers.NewSystemWSController(),
WebUI: controllers.NewWebUIController(services.NewWebUIService(settingsService)),
Monitor: controllers.NewMonitorController(executorService),
Interconnect: controllers.NewInterconnectController(interconnectService),
Data: controllers.NewDataController(taskController, envController),
Install: controllers.NewInstallController(),
}
}
// StopCron 停止计划任务服务
func StopCron() {
if executorService != nil {
executorService.Stop()
}
}