diff --git a/api/core/app_server.go b/api/core/app_server.go index ed11ab0c..8ba434fa 100644 --- a/api/core/app_server.go +++ b/api/core/app_server.go @@ -227,7 +227,6 @@ func needLogin(c *gin.Context) bool { c.Request.URL.Path == "/api/sd/client" || c.Request.URL.Path == "/api/dall/imgWall" || c.Request.URL.Path == "/api/dall/client" || - c.Request.URL.Path == "/api/config/get" || c.Request.URL.Path == "/api/product/list" || c.Request.URL.Path == "/api/menu/list" || c.Request.URL.Path == "/api/markMap/client" || @@ -237,6 +236,7 @@ func needLogin(c *gin.Context) bool { c.Request.URL.Path == "/api/payment/doPay" || c.Request.URL.Path == "/api/payment/payWays" || strings.HasPrefix(c.Request.URL.Path, "/api/test") || + strings.HasPrefix(c.Request.URL.Path, "/api/config/") || strings.HasPrefix(c.Request.URL.Path, "/api/function/") || strings.HasPrefix(c.Request.URL.Path, "/api/sms/") || strings.HasPrefix(c.Request.URL.Path, "/api/captcha/") || diff --git a/api/core/types/config.go b/api/core/types/config.go index 8536cd51..c9881999 100644 --- a/api/core/types/config.go +++ b/api/core/types/config.go @@ -126,11 +126,16 @@ type RedisConfig struct { const LicenseKey = "Geek-AI-License" type License struct { - Key string `json:"key"` // 许可证书密钥 - MachineId string `json:"machine_id"` // 机器码 - UserNum int `json:"user_num"` // 用户数量 - ExpiredAt int64 `json:"expired_at"` // 过期时间 - IsActive bool `json:"is_active"` // 是否激活 + Key string `json:"key"` // 许可证书密钥 + MachineId string `json:"machine_id"` // 机器码 + ExpiredAt int64 `json:"expired_at"` // 过期时间 + IsActive bool `json:"is_active"` // 是否激活 + Configs LicenseConfig `json:"configs"` +} + +type LicenseConfig struct { + UserNum int `json:"user_num"` // 用户数量 + DeCopy bool `json:"de_copy"` // 去版权 } func (c RedisConfig) Url() string { @@ -207,4 +212,6 @@ type SystemConfig struct { ContextDeep int `json:"context_deep,omitempty"` SdNegPrompt string `json:"sd_neg_prompt"` // SD 默认反向提示词 + + RandBg bool `json:"rand_bg"` // 前端首页是否启用随机背景 } diff --git a/api/handler/admin/user_handler.go b/api/handler/admin/user_handler.go index bd9b926b..95da105f 100644 --- a/api/handler/admin/user_handler.go +++ b/api/handler/admin/user_handler.go @@ -87,7 +87,7 @@ func (h *UserHandler) Save(c *gin.Context) { // 检测最大注册人数 var totalUser int64 h.DB.Model(&model.User{}).Count(&totalUser) - if h.licenseService.GetLicense().UserNum > 0 && int(totalUser) >= h.licenseService.GetLicense().UserNum { + if h.licenseService.GetLicense().Configs.UserNum > 0 && int(totalUser) >= h.licenseService.GetLicense().Configs.UserNum { resp.ERROR(c, "当前注册用户数已达上限,请请升级 License") return } diff --git a/api/handler/config_handler.go b/api/handler/config_handler.go index 0b8fdb03..30e33b8a 100644 --- a/api/handler/config_handler.go +++ b/api/handler/config_handler.go @@ -9,6 +9,7 @@ package handler import ( "geekai/core" + "geekai/service" "geekai/store/model" "geekai/utils" "geekai/utils/resp" @@ -19,10 +20,11 @@ import ( type ConfigHandler struct { BaseHandler + licenseService *service.LicenseService } -func NewConfigHandler(app *core.AppServer, db *gorm.DB) *ConfigHandler { - return &ConfigHandler{BaseHandler: BaseHandler{App: app, DB: db}} +func NewConfigHandler(app *core.AppServer, db *gorm.DB, licenseService *service.LicenseService) *ConfigHandler { + return &ConfigHandler{BaseHandler: BaseHandler{App: app, DB: db}, licenseService: licenseService} } // Get 获取指定的系统配置 @@ -44,3 +46,9 @@ func (h *ConfigHandler) Get(c *gin.Context) { resp.SUCCESS(c, value) } + +// License 获取 License 配置 +func (h *ConfigHandler) License(c *gin.Context) { + license := h.licenseService.GetLicense() + resp.SUCCESS(c, license.Configs) +} diff --git a/api/handler/user_handler.go b/api/handler/user_handler.go index 263a7139..2718d15e 100644 --- a/api/handler/user_handler.go +++ b/api/handler/user_handler.go @@ -71,7 +71,7 @@ func (h *UserHandler) Register(c *gin.Context) { // 检测最大注册人数 var totalUser int64 h.DB.Model(&model.User{}).Count(&totalUser) - if h.licenseService.GetLicense().UserNum > 0 && int(totalUser) >= h.licenseService.GetLicense().UserNum { + if h.licenseService.GetLicense().Configs.UserNum > 0 && int(totalUser) >= h.licenseService.GetLicense().Configs.UserNum { resp.ERROR(c, "当前注册用户数已达上限,请请升级 License") return } diff --git a/api/main.go b/api/main.go index 9b4458cf..8b585ee6 100644 --- a/api/main.go +++ b/api/main.go @@ -295,6 +295,7 @@ func main() { fx.Invoke(func(s *core.AppServer, h *handler.ConfigHandler) { group := s.Engine.Group("/api/config/") group.GET("get", h.Get) + group.GET("license", h.License) }), // 管理后台控制器 diff --git a/api/service/license_service.go b/api/service/license_service.go index 94e08c0b..4df6f6db 100644 --- a/api/service/license_service.go +++ b/api/service/license_service.go @@ -46,12 +46,13 @@ func NewLicenseService(server *core.AppServer, levelDB *store.LevelDB) *LicenseS } type License struct { - Name string `json:"name"` - License string `json:"license"` - MachineId string `json:"mid"` - ActiveAt int64 `json:"active_at"` - ExpiredAt int64 `json:"expired_at"` - UserNum int `json:"user_num"` + Name string `json:"name"` + License string `json:"license"` + MachineId string `json:"mid"` + ActiveAt int64 `json:"active_at"` + ExpiredAt int64 `json:"expired_at"` + UserNum int `json:"user_num"` + Configs types.LicenseConfig `json:"configs"` } // ActiveLicense 激活 License @@ -80,7 +81,7 @@ func (s *LicenseService) ActiveLicense(license string, machineId string) error { s.license = &types.License{ Key: license, MachineId: machineId, - UserNum: res.Data.UserNum, + Configs: res.Data.Configs, ExpiredAt: res.Data.ExpiredAt, IsActive: true, } @@ -140,7 +141,7 @@ func (s *LicenseService) fetchLicense() (*types.License, error) { return &types.License{ Key: res.Data.License, MachineId: res.Data.MachineId, - UserNum: res.Data.UserNum, + Configs: res.Data.Configs, ExpiredAt: res.Data.ExpiredAt, IsActive: true, }, nil diff --git a/web/src/views/Home.vue b/web/src/views/Home.vue index 43cf21f4..87043d42 100644 --- a/web/src/views/Home.vue +++ b/web/src/views/Home.vue @@ -11,8 +11,8 @@