diff --git a/api/core/types/config.go b/api/core/types/config.go index 0b1c568c..5023a413 100644 --- a/api/core/types/config.go +++ b/api/core/types/config.go @@ -140,12 +140,12 @@ type SystemConfig struct { Title string `json:"title"` AdminTitle string `json:"admin_title"` Models []string `json:"models"` - InitChatCalls int `json:"init_chat_calls"` // 新用户注册赠送对话次数 - InitImgCalls int `json:"init_img_calls"` // 新用户注册赠送绘图次数 - VipMonthCalls int `json:"vip_month_calls"` // 会员每个赠送的调用次数 - EnabledRegister bool `json:"enabled_register"` - EnabledMsg bool `json:"enabled_msg"` // 启用短信验证码服务 - EnabledDraw bool `json:"enabled_draw"` // 启动 AI 绘画功能 + InitChatCalls int `json:"init_chat_calls"` // 新用户注册赠送对话次数 + InitImgCalls int `json:"init_img_calls"` // 新用户注册赠送绘图次数 + VipMonthCalls int `json:"vip_month_calls"` // 会员每个赠送的调用次数 + EnabledRegister bool `json:"enabled_register"` // 是否启用注册功能,关闭注册功能之后将无法注册 + EnabledMsg bool `json:"enabled_msg"` // 是否启用短信验证码服务 + EnabledDraw bool `json:"enabled_draw"` // 是否启用 AI 绘画功能 RewardImg string `json:"reward_img"` // 众筹收款二维码地址 EnabledFunction bool `json:"enabled_function"` // 启用 API 函数功能 EnabledReward bool `json:"enabled_reward"` // 启用众筹功能 @@ -155,4 +155,5 @@ type SystemConfig struct { OrderPayInfoText string `json:"order_pay_info_text"` // 订单支付页面说明文字 InviteChatCalls int `json:"invite_chat_calls"` // 邀请用户注册奖励对话次数 InviteImgCalls int `json:"invite_img_calls"` // 邀请用户注册奖励绘图次数 + ForceInvite bool `json:"force_invite"` // 是否强制必须使用邀请码才能注册 } diff --git a/api/handler/sms_handler.go b/api/handler/sms_handler.go index 07e26067..9ccb4e3d 100644 --- a/api/handler/sms_handler.go +++ b/api/handler/sms_handler.go @@ -58,13 +58,3 @@ func (h *SmsHandler) SendCode(c *gin.Context) { resp.SUCCESS(c) } - -type statusVo struct { - EnabledMsgService bool `json:"enabled_msg_service"` - EnabledRegister bool `json:"enabled_register"` -} - -// Status check if the message service is enabled -func (h *SmsHandler) Status(c *gin.Context) { - resp.SUCCESS(c, statusVo{EnabledMsgService: h.App.SysConfig.EnabledMsg, EnabledRegister: h.App.SysConfig.EnabledRegister}) -} diff --git a/api/handler/user_handler.go b/api/handler/user_handler.go index e43ea064..9a64a37e 100644 --- a/api/handler/user_handler.go +++ b/api/handler/user_handler.go @@ -71,7 +71,12 @@ func (h *UserHandler) Register(c *gin.Context) { // 验证邀请码 inviteCode := model.InviteCode{} - if data.InviteCode != "" { + if data.InviteCode == "" { + if h.App.SysConfig.ForceInvite { + resp.ERROR(c, "当前系统设定必须使用邀请码才能注册") + return + } + } else { res := h.db.Where("code = ?", data.InviteCode).First(&inviteCode) if res.Error != nil { resp.ERROR(c, "无效的邀请码") diff --git a/api/main.go b/api/main.go index 7aea70d0..f81976fa 100644 --- a/api/main.go +++ b/api/main.go @@ -237,7 +237,6 @@ func main() { }), fx.Invoke(func(s *core.AppServer, h *handler.SmsHandler) { group := s.Engine.Group("/api/sms/") - group.GET("status", h.Status) group.POST("code", h.SendCode) }), fx.Invoke(func(s *core.AppServer, h *handler.CaptchaHandler) { diff --git a/api/service/fun/func_mj.go b/api/service/fun/func_mj.go index 0b5899db..bbd83554 100644 --- a/api/service/fun/func_mj.go +++ b/api/service/fun/func_mj.go @@ -4,6 +4,7 @@ import ( "chatplus/core/types" "chatplus/service/mj" "chatplus/utils" + "errors" ) // AI 绘画函数 @@ -11,15 +12,21 @@ import ( type FuncMidJourney struct { name string service *mj.Service + config types.MidJourneyConfig } -func NewMidJourneyFunc(mjService *mj.Service) FuncMidJourney { +func NewMidJourneyFunc(mjService *mj.Service, config types.MidJourneyConfig) FuncMidJourney { return FuncMidJourney{ name: "MidJourney AI 绘画", + config: config, service: mjService} } func (f FuncMidJourney) Invoke(params map[string]interface{}) (string, error) { + if !f.config.Enabled { + return "", errors.New("MidJourney AI 绘画功能没有启用") + } + logger.Infof("MJ 绘画参数:%+v", params) prompt := utils.InterfaceToString(params["prompt"]) f.service.PushTask(types.MjTask{ diff --git a/api/service/fun/function.go b/api/service/fun/function.go index 76e523bd..8b33dcbb 100644 --- a/api/service/fun/function.go +++ b/api/service/fun/function.go @@ -34,6 +34,6 @@ func NewFunctions(config *types.AppConfig, mjService *mj.Service) map[string]Fun types.FuncZaoBao: NewZaoBao(config.ApiConfig), types.FuncWeibo: NewWeiboHot(config.ApiConfig), types.FuncHeadLine: NewHeadLines(config.ApiConfig), - types.FuncMidJourney: NewMidJourneyFunc(mjService), + types.FuncMidJourney: NewMidJourneyFunc(mjService, config.MjConfig), } } diff --git a/web/src/views/Invitation.vue b/web/src/views/Invitation.vue index 57a2c8b7..2667437d 100644 --- a/web/src/views/Invitation.vue +++ b/web/src/views/Invitation.vue @@ -78,7 +78,7 @@
',
+ type: 'info',
+ duration: 0,
+ })
+ }
}
+}).catch(e => {
+ ElMessage.error("获取系统配置失败:" + e.message)
})
httpGet("/api/invite/hits", {code: formData.value.invite_code}).then(() => {
diff --git a/web/src/views/admin/SysConfig.vue b/web/src/views/admin/SysConfig.vue
index 3255afcc..13751a62 100644
--- a/web/src/views/admin/SysConfig.vue
+++ b/web/src/views/admin/SysConfig.vue
@@ -27,6 +27,19 @@