2023-06-15 09:41:30 +08:00
|
|
|
package main
|
|
|
|
|
2024-05-06 14:41:27 +08:00
|
|
|
// * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// * Copyright 2023 The Geek-AI Authors. All rights reserved.
|
|
|
|
// * Use of this source code is governed by a Apache-2.0 license
|
|
|
|
// * that can be found in the LICENSE file.
|
|
|
|
// * @Author yangjian102621@163.com
|
|
|
|
// * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
2023-06-15 09:41:30 +08:00
|
|
|
import (
|
|
|
|
"context"
|
2023-06-22 11:08:44 +08:00
|
|
|
"embed"
|
2024-05-06 14:41:27 +08:00
|
|
|
"geekai/core"
|
|
|
|
"geekai/core/types"
|
|
|
|
"geekai/handler"
|
|
|
|
"geekai/handler/admin"
|
|
|
|
"geekai/handler/chatimpl"
|
|
|
|
logger2 "geekai/logger"
|
|
|
|
"geekai/service"
|
|
|
|
"geekai/service/dalle"
|
|
|
|
"geekai/service/mj"
|
|
|
|
"geekai/service/oss"
|
|
|
|
"geekai/service/payment"
|
|
|
|
"geekai/service/sd"
|
|
|
|
"geekai/service/sms"
|
|
|
|
"geekai/service/wx"
|
|
|
|
"geekai/store"
|
2023-06-22 11:08:44 +08:00
|
|
|
"io"
|
2023-06-15 09:41:30 +08:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2023-06-27 18:29:46 +08:00
|
|
|
"strconv"
|
2023-06-15 09:41:30 +08:00
|
|
|
"syscall"
|
|
|
|
"time"
|
2023-06-19 07:06:59 +08:00
|
|
|
|
2023-12-23 22:30:27 +08:00
|
|
|
"github.com/go-redis/redis/v8"
|
|
|
|
|
2023-06-19 07:06:59 +08:00
|
|
|
"github.com/lionsoul2014/ip2region/binding/golang/xdb"
|
|
|
|
"go.uber.org/fx"
|
|
|
|
"gorm.io/gorm"
|
2023-06-15 09:41:30 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var logger = logger2.GetLogger()
|
|
|
|
|
2023-11-08 17:48:07 +08:00
|
|
|
//go:embed res
|
2023-06-22 11:08:44 +08:00
|
|
|
var xdbFS embed.FS
|
|
|
|
|
2023-06-15 09:41:30 +08:00
|
|
|
// AppLifecycle 应用程序生命周期
|
|
|
|
type AppLifecycle struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnStart 应用程序启动时执行
|
|
|
|
func (l *AppLifecycle) OnStart(context.Context) error {
|
2024-04-23 18:46:32 +08:00
|
|
|
logger.Info("AppLifecycle OnStart")
|
2023-06-15 09:41:30 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// OnStop 应用程序停止时执行
|
|
|
|
func (l *AppLifecycle) OnStop(context.Context) error {
|
2024-04-23 18:46:32 +08:00
|
|
|
logger.Info("AppLifecycle OnStop")
|
2023-06-15 09:41:30 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-04-02 14:59:53 +08:00
|
|
|
func NewAppLifeCycle() *AppLifecycle {
|
|
|
|
return &AppLifecycle{}
|
|
|
|
}
|
|
|
|
|
2023-06-15 09:41:30 +08:00
|
|
|
func main() {
|
2023-06-27 18:29:46 +08:00
|
|
|
configFile := os.Getenv("CONFIG_FILE")
|
2023-06-28 05:51:55 +08:00
|
|
|
if configFile == "" {
|
|
|
|
configFile = "config.toml"
|
|
|
|
}
|
2024-01-03 11:15:54 +08:00
|
|
|
debug, _ := strconv.ParseBool(os.Getenv("APP_DEBUG"))
|
2023-06-15 09:41:30 +08:00
|
|
|
logger.Info("Loading config file: ", configFile)
|
2024-01-19 16:58:13 +08:00
|
|
|
if !debug {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
logger.Error("Panic Error:", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2023-06-25 11:34:55 +08:00
|
|
|
|
2023-06-15 09:41:30 +08:00
|
|
|
app := fx.New(
|
|
|
|
// 初始化配置应用配置
|
|
|
|
fx.Provide(func() *types.AppConfig {
|
|
|
|
config, err := core.LoadConfig(configFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-06-27 18:29:46 +08:00
|
|
|
config.Path = configFile
|
2023-07-25 15:02:43 +08:00
|
|
|
if debug {
|
|
|
|
_ = core.SaveConfig(config)
|
|
|
|
}
|
2023-06-15 09:41:30 +08:00
|
|
|
return config
|
|
|
|
}),
|
|
|
|
// 创建应用服务
|
|
|
|
fx.Provide(core.NewServer),
|
|
|
|
// 初始化
|
2023-09-05 11:47:03 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, client *redis.Client) {
|
|
|
|
s.Init(debug, client)
|
2023-06-15 09:41:30 +08:00
|
|
|
}),
|
|
|
|
|
|
|
|
// 初始化数据库
|
|
|
|
fx.Provide(store.NewGormConfig),
|
|
|
|
fx.Provide(store.NewMysql),
|
2023-09-04 06:43:15 +08:00
|
|
|
fx.Provide(store.NewRedisClient),
|
2024-04-02 17:24:38 +08:00
|
|
|
fx.Provide(store.NewLevelDB),
|
2023-06-15 09:41:30 +08:00
|
|
|
|
2023-11-06 17:55:46 +08:00
|
|
|
fx.Provide(func() embed.FS {
|
|
|
|
return xdbFS
|
|
|
|
}),
|
|
|
|
|
2023-06-15 09:41:30 +08:00
|
|
|
// 创建 Ip2Region 查询对象
|
|
|
|
fx.Provide(func() (*xdb.Searcher, error) {
|
2023-06-22 11:08:44 +08:00
|
|
|
file, err := xdbFS.Open("res/ip2region.xdb")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cBuff, err := io.ReadAll(file)
|
2023-06-15 09:41:30 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return xdb.NewWithBuffer(cBuff)
|
|
|
|
}),
|
|
|
|
|
|
|
|
// 创建控制器
|
|
|
|
fx.Provide(handler.NewChatRoleHandler),
|
|
|
|
fx.Provide(handler.NewUserHandler),
|
2023-10-11 15:46:40 +08:00
|
|
|
fx.Provide(chatimpl.NewChatHandler),
|
2023-06-27 12:11:55 +08:00
|
|
|
fx.Provide(handler.NewUploadHandler),
|
2023-07-25 17:00:24 +08:00
|
|
|
fx.Provide(handler.NewSmsHandler),
|
2023-07-21 18:26:51 +08:00
|
|
|
fx.Provide(handler.NewRewardHandler),
|
2023-07-25 17:00:24 +08:00
|
|
|
fx.Provide(handler.NewCaptchaHandler),
|
2023-08-11 18:46:56 +08:00
|
|
|
fx.Provide(handler.NewMidJourneyHandler),
|
2023-09-04 16:32:20 +08:00
|
|
|
fx.Provide(handler.NewChatModelHandler),
|
2023-09-28 18:09:45 +08:00
|
|
|
fx.Provide(handler.NewSdJobHandler),
|
2023-11-06 17:55:46 +08:00
|
|
|
fx.Provide(handler.NewPaymentHandler),
|
|
|
|
fx.Provide(handler.NewOrderHandler),
|
|
|
|
fx.Provide(handler.NewProductHandler),
|
2024-03-15 11:13:02 +08:00
|
|
|
fx.Provide(handler.NewConfigHandler),
|
2024-03-20 14:14:30 +08:00
|
|
|
fx.Provide(handler.NewPowerLogHandler),
|
2023-06-15 09:41:30 +08:00
|
|
|
|
2023-06-27 12:11:55 +08:00
|
|
|
fx.Provide(admin.NewConfigHandler),
|
2023-06-19 07:06:59 +08:00
|
|
|
fx.Provide(admin.NewAdminHandler),
|
|
|
|
fx.Provide(admin.NewApiKeyHandler),
|
2023-06-19 18:23:09 +08:00
|
|
|
fx.Provide(admin.NewUserHandler),
|
|
|
|
fx.Provide(admin.NewChatRoleHandler),
|
2023-07-24 15:59:29 +08:00
|
|
|
fx.Provide(admin.NewRewardHandler),
|
2023-08-02 16:37:47 +08:00
|
|
|
fx.Provide(admin.NewDashboardHandler),
|
2023-09-04 16:32:20 +08:00
|
|
|
fx.Provide(admin.NewChatModelHandler),
|
2023-11-06 17:55:46 +08:00
|
|
|
fx.Provide(admin.NewProductHandler),
|
|
|
|
fx.Provide(admin.NewOrderHandler),
|
2024-02-22 17:16:44 +08:00
|
|
|
fx.Provide(admin.NewChatHandler),
|
2024-03-21 13:46:39 +08:00
|
|
|
fx.Provide(admin.NewPowerLogHandler),
|
2023-06-19 07:06:59 +08:00
|
|
|
|
2023-07-02 20:51:13 +08:00
|
|
|
// 创建服务
|
2024-01-22 16:38:44 +08:00
|
|
|
fx.Provide(sms.NewSendServiceManager),
|
2023-07-25 17:00:24 +08:00
|
|
|
fx.Provide(func(config *types.AppConfig) *service.CaptchaService {
|
|
|
|
return service.NewCaptchaService(config.ApiConfig)
|
|
|
|
}),
|
2023-08-20 22:29:08 +08:00
|
|
|
fx.Provide(oss.NewUploaderManager),
|
2023-09-27 18:14:07 +08:00
|
|
|
fx.Provide(mj.NewService),
|
2024-04-21 20:23:47 +08:00
|
|
|
fx.Provide(dalle.NewService),
|
|
|
|
fx.Invoke(func(service *dalle.Service) {
|
|
|
|
service.Run()
|
|
|
|
service.CheckTaskNotify()
|
|
|
|
service.DownloadImages()
|
2024-04-21 21:44:28 +08:00
|
|
|
service.CheckTaskStatus()
|
2024-04-21 20:23:47 +08:00
|
|
|
}),
|
2023-07-02 20:51:13 +08:00
|
|
|
|
2024-01-05 18:17:11 +08:00
|
|
|
// 邮件服务
|
|
|
|
fx.Provide(service.NewSmtpService),
|
|
|
|
|
2023-09-27 18:14:07 +08:00
|
|
|
// 微信机器人服务
|
|
|
|
fx.Provide(wx.NewWeChatBot),
|
|
|
|
fx.Invoke(func(config *types.AppConfig, bot *wx.Bot) {
|
|
|
|
if config.WeChatBot {
|
|
|
|
err := bot.Run()
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("微信登录失败:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2023-12-13 16:38:27 +08:00
|
|
|
// MidJourney service pool
|
|
|
|
fx.Provide(mj.NewServicePool),
|
2024-05-11 17:27:14 +08:00
|
|
|
fx.Invoke(func(pool *mj.ServicePool, config *types.AppConfig) {
|
|
|
|
pool.InitServices(config.MjPlusConfigs, config.MjProxyConfigs)
|
2023-12-21 15:00:46 +08:00
|
|
|
if pool.HasAvailableService() {
|
|
|
|
pool.DownloadImages()
|
2023-12-22 17:25:31 +08:00
|
|
|
pool.CheckTaskNotify()
|
2024-01-12 18:24:28 +08:00
|
|
|
pool.SyncTaskProgress()
|
2023-12-21 15:00:46 +08:00
|
|
|
}
|
|
|
|
}),
|
2023-12-13 16:38:27 +08:00
|
|
|
|
2023-09-28 18:09:45 +08:00
|
|
|
// Stable Diffusion 机器人
|
2023-12-14 16:48:54 +08:00
|
|
|
fx.Provide(sd.NewServicePool),
|
2024-05-11 17:27:14 +08:00
|
|
|
fx.Invoke(func(pool *sd.ServicePool, config *types.AppConfig) {
|
|
|
|
pool.InitServices(config.SdConfigs)
|
2024-03-26 18:23:08 +08:00
|
|
|
if pool.HasAvailableService() {
|
|
|
|
pool.CheckTaskNotify()
|
|
|
|
pool.CheckTaskStatus()
|
|
|
|
}
|
|
|
|
}),
|
2023-11-06 17:55:46 +08:00
|
|
|
|
|
|
|
fx.Provide(payment.NewAlipayService),
|
2023-12-08 19:43:13 +08:00
|
|
|
fx.Provide(payment.NewHuPiPay),
|
2024-01-07 14:36:02 +08:00
|
|
|
fx.Provide(payment.NewPayJS),
|
2023-11-06 17:55:46 +08:00
|
|
|
fx.Provide(service.NewSnowflake),
|
|
|
|
fx.Provide(service.NewXXLJobExecutor),
|
2023-11-10 16:49:07 +08:00
|
|
|
fx.Invoke(func(exec *service.XXLJobExecutor, config *types.AppConfig) {
|
|
|
|
if config.XXLConfig.Enabled {
|
|
|
|
go func() {
|
|
|
|
log.Fatal(exec.Run())
|
|
|
|
}()
|
|
|
|
}
|
2023-11-06 17:55:46 +08:00
|
|
|
}),
|
|
|
|
|
2023-06-15 09:41:30 +08:00
|
|
|
// 注册路由
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.ChatRoleHandler) {
|
2023-06-20 11:46:13 +08:00
|
|
|
group := s.Engine.Group("/api/role/")
|
2023-06-15 09:41:30 +08:00
|
|
|
group.GET("list", h.List)
|
2023-10-16 10:46:10 +08:00
|
|
|
group.POST("update", h.UpdateRole)
|
2023-06-15 09:41:30 +08:00
|
|
|
}),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.UserHandler) {
|
|
|
|
group := s.Engine.Group("/api/user/")
|
|
|
|
group.POST("register", h.Register)
|
|
|
|
group.POST("login", h.Login)
|
|
|
|
group.GET("logout", h.Logout)
|
|
|
|
group.GET("session", h.Session)
|
|
|
|
group.GET("profile", h.Profile)
|
|
|
|
group.POST("profile/update", h.ProfileUpdate)
|
2023-11-22 18:00:45 +08:00
|
|
|
group.POST("password", h.UpdatePass)
|
2024-01-05 18:21:47 +08:00
|
|
|
group.POST("bind/username", h.BindUsername)
|
2023-11-22 18:00:45 +08:00
|
|
|
group.POST("resetPass", h.ResetPass)
|
2023-06-15 09:41:30 +08:00
|
|
|
}),
|
2023-10-11 15:46:40 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *chatimpl.ChatHandler) {
|
2023-06-15 09:41:30 +08:00
|
|
|
group := s.Engine.Group("/api/chat/")
|
|
|
|
group.Any("new", h.ChatHandle)
|
|
|
|
group.GET("list", h.List)
|
2023-08-04 12:08:07 +08:00
|
|
|
group.GET("detail", h.Detail)
|
2023-06-15 09:41:30 +08:00
|
|
|
group.POST("update", h.Update)
|
|
|
|
group.GET("remove", h.Remove)
|
|
|
|
group.GET("history", h.History)
|
|
|
|
group.GET("clear", h.Clear)
|
2023-09-11 13:34:20 +08:00
|
|
|
group.POST("tokens", h.Tokens)
|
2023-06-15 09:41:30 +08:00
|
|
|
group.GET("stop", h.StopGenerate)
|
|
|
|
}),
|
2023-06-27 12:11:55 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.UploadHandler) {
|
|
|
|
s.Engine.POST("/api/upload", h.Upload)
|
2024-01-15 18:48:01 +08:00
|
|
|
s.Engine.GET("/api/upload/list", h.List)
|
2024-02-19 16:43:03 +08:00
|
|
|
s.Engine.GET("/api/upload/remove", h.Remove)
|
2023-06-27 12:11:55 +08:00
|
|
|
}),
|
2023-07-25 17:00:24 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.SmsHandler) {
|
|
|
|
group := s.Engine.Group("/api/sms/")
|
2023-07-27 10:53:14 +08:00
|
|
|
group.POST("code", h.SendCode)
|
2023-07-25 17:00:24 +08:00
|
|
|
}),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.CaptchaHandler) {
|
|
|
|
group := s.Engine.Group("/api/captcha/")
|
|
|
|
group.GET("get", h.Get)
|
|
|
|
group.POST("check", h.Check)
|
2024-03-28 15:00:53 +08:00
|
|
|
group.GET("slide/get", h.SlideGet)
|
|
|
|
group.POST("slide/check", h.SlideCheck)
|
2023-07-02 20:51:13 +08:00
|
|
|
}),
|
2023-07-21 18:26:51 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.RewardHandler) {
|
|
|
|
group := s.Engine.Group("/api/reward/")
|
2023-07-21 22:29:14 +08:00
|
|
|
group.POST("verify", h.Verify)
|
2023-07-21 18:26:51 +08:00
|
|
|
}),
|
2023-08-11 18:46:56 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.MidJourneyHandler) {
|
2023-09-12 18:01:24 +08:00
|
|
|
group := s.Engine.Group("/api/mj/")
|
2023-12-22 17:25:31 +08:00
|
|
|
group.Any("client", h.Client)
|
2023-09-17 18:03:45 +08:00
|
|
|
group.POST("image", h.Image)
|
2023-09-12 18:01:24 +08:00
|
|
|
group.POST("upscale", h.Upscale)
|
|
|
|
group.POST("variation", h.Variation)
|
2023-09-15 17:40:39 +08:00
|
|
|
group.GET("jobs", h.JobList)
|
2024-03-03 10:40:32 +08:00
|
|
|
group.GET("imgWall", h.ImgWall)
|
2023-12-18 17:44:52 +08:00
|
|
|
group.POST("remove", h.Remove)
|
2024-01-19 06:52:23 +08:00
|
|
|
group.POST("publish", h.Publish)
|
2023-08-11 18:46:56 +08:00
|
|
|
}),
|
2023-09-28 18:09:45 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.SdJobHandler) {
|
|
|
|
group := s.Engine.Group("/api/sd")
|
2024-02-26 15:45:54 +08:00
|
|
|
group.Any("client", h.Client)
|
2023-09-28 18:09:45 +08:00
|
|
|
group.POST("image", h.Image)
|
|
|
|
group.GET("jobs", h.JobList)
|
2024-03-03 10:40:32 +08:00
|
|
|
group.GET("imgWall", h.ImgWall)
|
2023-12-18 17:44:52 +08:00
|
|
|
group.POST("remove", h.Remove)
|
2024-01-19 06:52:23 +08:00
|
|
|
group.POST("publish", h.Publish)
|
2023-09-28 18:09:45 +08:00
|
|
|
}),
|
2024-03-15 11:13:02 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.ConfigHandler) {
|
|
|
|
group := s.Engine.Group("/api/config/")
|
|
|
|
group.GET("get", h.Get)
|
|
|
|
}),
|
2023-06-19 15:58:52 +08:00
|
|
|
|
2023-06-27 12:11:55 +08:00
|
|
|
// 管理后台控制器
|
2023-06-19 15:58:52 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.ConfigHandler) {
|
2024-04-23 18:46:32 +08:00
|
|
|
group := s.Engine.Group("/api/admin/")
|
|
|
|
group.POST("config/update", h.Update)
|
|
|
|
group.GET("config/get", h.Get)
|
2023-06-15 09:41:30 +08:00
|
|
|
}),
|
2023-06-19 07:06:59 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.ManagerHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/")
|
|
|
|
group.POST("login", h.Login)
|
|
|
|
group.GET("logout", h.Logout)
|
2023-06-19 11:09:23 +08:00
|
|
|
group.GET("session", h.Session)
|
2024-03-21 15:24:28 +08:00
|
|
|
group.GET("list", h.List)
|
|
|
|
group.POST("save", h.Save)
|
|
|
|
group.POST("enable", h.Enable)
|
|
|
|
group.GET("remove", h.Remove)
|
|
|
|
group.POST("resetPass", h.ResetPass)
|
2023-06-19 07:06:59 +08:00
|
|
|
}),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.ApiKeyHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/apikey/")
|
2023-06-20 18:05:33 +08:00
|
|
|
group.POST("save", h.Save)
|
2023-06-19 07:06:59 +08:00
|
|
|
group.GET("list", h.List)
|
2024-01-04 10:48:04 +08:00
|
|
|
group.POST("set", h.Set)
|
2024-04-06 20:36:52 +08:00
|
|
|
group.GET("remove", h.Remove)
|
2023-06-19 07:06:59 +08:00
|
|
|
}),
|
2023-06-19 18:23:09 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.UserHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/user/")
|
|
|
|
group.GET("list", h.List)
|
2023-08-01 16:02:49 +08:00
|
|
|
group.POST("save", h.Save)
|
2024-03-19 18:25:01 +08:00
|
|
|
group.GET("remove", h.Remove)
|
2023-06-21 06:53:41 +08:00
|
|
|
group.GET("loginLog", h.LoginLog)
|
2023-07-26 15:22:11 +08:00
|
|
|
group.POST("resetPass", h.ResetPass)
|
2023-06-19 18:23:09 +08:00
|
|
|
}),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.ChatRoleHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/role/")
|
|
|
|
group.GET("list", h.List)
|
2023-06-20 18:05:33 +08:00
|
|
|
group.POST("save", h.Save)
|
2023-09-04 16:32:20 +08:00
|
|
|
group.POST("sort", h.Sort)
|
2023-12-29 17:51:56 +08:00
|
|
|
group.POST("set", h.Set)
|
2024-05-10 17:38:55 +08:00
|
|
|
group.GET("remove", h.Remove)
|
2023-06-19 18:23:09 +08:00
|
|
|
}),
|
2023-07-24 15:59:29 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.RewardHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/reward/")
|
|
|
|
group.GET("list", h.List)
|
2024-03-13 14:40:38 +08:00
|
|
|
group.POST("remove", h.Remove)
|
2023-07-24 15:59:29 +08:00
|
|
|
}),
|
2023-08-02 16:37:47 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.DashboardHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/dashboard/")
|
|
|
|
group.GET("stats", h.Stats)
|
|
|
|
}),
|
2023-09-04 16:32:20 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.ChatModelHandler) {
|
|
|
|
group := s.Engine.Group("/api/model/")
|
|
|
|
group.GET("list", h.List)
|
|
|
|
}),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.ChatModelHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/model/")
|
|
|
|
group.POST("save", h.Save)
|
|
|
|
group.GET("list", h.List)
|
2023-11-23 07:11:13 +08:00
|
|
|
group.POST("set", h.Set)
|
2023-09-04 16:32:20 +08:00
|
|
|
group.POST("sort", h.Sort)
|
2024-03-15 18:35:10 +08:00
|
|
|
group.GET("remove", h.Remove)
|
2023-09-04 16:32:20 +08:00
|
|
|
}),
|
2023-11-06 17:55:46 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.PaymentHandler) {
|
|
|
|
group := s.Engine.Group("/api/payment/")
|
2023-12-08 19:43:13 +08:00
|
|
|
group.GET("doPay", h.DoPay)
|
|
|
|
group.GET("payWays", h.GetPayWays)
|
2023-11-06 17:55:46 +08:00
|
|
|
group.POST("query", h.OrderQuery)
|
2023-12-08 19:43:13 +08:00
|
|
|
group.POST("qrcode", h.PayQrcode)
|
2024-03-20 16:14:02 +08:00
|
|
|
group.POST("mobile", h.Mobile)
|
2023-11-06 17:55:46 +08:00
|
|
|
group.POST("alipay/notify", h.AlipayNotify)
|
2023-12-08 19:43:13 +08:00
|
|
|
group.POST("hupipay/notify", h.HuPiPayNotify)
|
2024-01-07 14:36:02 +08:00
|
|
|
group.POST("payjs/notify", h.PayJsNotify)
|
2023-11-06 17:55:46 +08:00
|
|
|
}),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.ProductHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/product/")
|
|
|
|
group.POST("save", h.Save)
|
|
|
|
group.GET("list", h.List)
|
|
|
|
group.POST("enable", h.Enable)
|
|
|
|
group.POST("sort", h.Sort)
|
|
|
|
group.GET("remove", h.Remove)
|
|
|
|
}),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.OrderHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/order/")
|
|
|
|
group.POST("list", h.List)
|
|
|
|
group.GET("remove", h.Remove)
|
|
|
|
}),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.OrderHandler) {
|
|
|
|
group := s.Engine.Group("/api/order/")
|
|
|
|
group.POST("list", h.List)
|
|
|
|
}),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.ProductHandler) {
|
|
|
|
group := s.Engine.Group("/api/product/")
|
|
|
|
group.GET("list", h.List)
|
|
|
|
}),
|
2023-06-19 07:06:59 +08:00
|
|
|
|
2023-11-23 16:30:15 +08:00
|
|
|
fx.Provide(handler.NewInviteHandler),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.InviteHandler) {
|
|
|
|
group := s.Engine.Group("/api/invite/")
|
|
|
|
group.GET("code", h.Code)
|
2023-11-23 17:40:15 +08:00
|
|
|
group.POST("list", h.List)
|
2023-11-23 16:30:15 +08:00
|
|
|
group.GET("hits", h.Hits)
|
|
|
|
}),
|
|
|
|
|
2023-12-21 08:58:24 +08:00
|
|
|
fx.Provide(admin.NewFunctionHandler),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.FunctionHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/function/")
|
|
|
|
group.POST("save", h.Save)
|
2023-12-23 22:30:27 +08:00
|
|
|
group.POST("set", h.Set)
|
2023-12-21 08:58:24 +08:00
|
|
|
group.GET("list", h.List)
|
|
|
|
group.GET("remove", h.Remove)
|
2023-12-24 22:12:12 +08:00
|
|
|
group.GET("token", h.GenToken)
|
2023-12-21 08:58:24 +08:00
|
|
|
}),
|
|
|
|
|
2024-03-11 13:51:26 +08:00
|
|
|
// 验证码
|
|
|
|
fx.Provide(admin.NewCaptchaHandler),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.CaptchaHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/login/")
|
|
|
|
group.GET("captcha", h.GetCaptcha)
|
2024-03-07 08:37:48 +08:00
|
|
|
}),
|
|
|
|
|
2024-03-11 13:51:26 +08:00
|
|
|
fx.Provide(admin.NewUploadHandler),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.UploadHandler) {
|
|
|
|
s.Engine.POST("/api/admin/upload", h.Upload)
|
|
|
|
}),
|
|
|
|
|
2023-12-28 18:14:38 +08:00
|
|
|
fx.Provide(handler.NewFunctionHandler),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.FunctionHandler) {
|
|
|
|
group := s.Engine.Group("/api/function/")
|
|
|
|
group.POST("weibo", h.WeiBo)
|
|
|
|
group.POST("zaobao", h.ZaoBao)
|
|
|
|
group.POST("dalle3", h.Dall3)
|
|
|
|
}),
|
2024-02-22 17:16:44 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.ChatHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/chat/")
|
|
|
|
group.POST("list", h.List)
|
|
|
|
group.POST("message", h.Messages)
|
|
|
|
group.GET("history", h.History)
|
|
|
|
group.GET("remove", h.RemoveChat)
|
|
|
|
group.GET("message/remove", h.RemoveMessage)
|
|
|
|
}),
|
2024-03-20 14:14:30 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.PowerLogHandler) {
|
|
|
|
group := s.Engine.Group("/api/powerLog/")
|
|
|
|
group.POST("list", h.List)
|
2023-12-08 19:43:13 +08:00
|
|
|
}),
|
2024-03-21 13:46:39 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.PowerLogHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/powerLog/")
|
|
|
|
group.POST("list", h.List)
|
|
|
|
}),
|
2024-03-29 15:41:58 +08:00
|
|
|
fx.Provide(admin.NewMenuHandler),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *admin.MenuHandler) {
|
|
|
|
group := s.Engine.Group("/api/admin/menu/")
|
|
|
|
group.POST("save", h.Save)
|
|
|
|
group.GET("list", h.List)
|
|
|
|
group.POST("enable", h.Enable)
|
|
|
|
group.POST("sort", h.Sort)
|
|
|
|
group.GET("remove", h.Remove)
|
|
|
|
}),
|
|
|
|
fx.Provide(handler.NewMenuHandler),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.MenuHandler) {
|
|
|
|
group := s.Engine.Group("/api/menu/")
|
|
|
|
group.GET("list", h.List)
|
|
|
|
}),
|
2024-04-15 06:16:53 +08:00
|
|
|
fx.Provide(handler.NewMarkMapHandler),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.MarkMapHandler) {
|
|
|
|
group := s.Engine.Group("/api/markMap/")
|
2024-04-15 17:23:59 +08:00
|
|
|
group.Any("client", h.Client)
|
2024-04-15 06:16:53 +08:00
|
|
|
}),
|
2024-04-21 20:23:47 +08:00
|
|
|
fx.Provide(handler.NewDallJobHandler),
|
|
|
|
fx.Invoke(func(s *core.AppServer, h *handler.DallJobHandler) {
|
|
|
|
group := s.Engine.Group("/api/dall")
|
|
|
|
group.Any("client", h.Client)
|
|
|
|
group.POST("image", h.Image)
|
|
|
|
group.GET("jobs", h.JobList)
|
|
|
|
group.GET("imgWall", h.ImgWall)
|
|
|
|
group.POST("remove", h.Remove)
|
|
|
|
group.POST("publish", h.Publish)
|
|
|
|
}),
|
2023-06-15 09:41:30 +08:00
|
|
|
fx.Invoke(func(s *core.AppServer, db *gorm.DB) {
|
2024-04-02 14:59:53 +08:00
|
|
|
go func() {
|
|
|
|
err := s.Run(db)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
2023-06-15 09:41:30 +08:00
|
|
|
}),
|
2024-04-02 14:59:53 +08:00
|
|
|
fx.Provide(NewAppLifeCycle),
|
2023-06-15 09:41:30 +08:00
|
|
|
// 注册生命周期回调函数
|
|
|
|
fx.Invoke(func(lifecycle fx.Lifecycle, lc *AppLifecycle) {
|
|
|
|
lifecycle.Append(fx.Hook{
|
|
|
|
OnStart: func(ctx context.Context) error {
|
|
|
|
return lc.OnStart(ctx)
|
|
|
|
},
|
|
|
|
OnStop: func(ctx context.Context) error {
|
|
|
|
return lc.OnStop(ctx)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
// 启动应用程序
|
|
|
|
go func() {
|
|
|
|
if err := app.Start(context.Background()); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// 监听退出信号
|
|
|
|
quit := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
<-quit
|
|
|
|
|
|
|
|
// 关闭应用程序
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
if err := app.Stop(ctx); err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|