mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-12-04 23:36:06 +08:00
将 license 存储到数据库
This commit is contained in:
@@ -171,5 +171,6 @@ type SystemConfig struct {
|
||||
EmailWhiteList []string `json:"email_white_list"` // 邮箱白名单列表
|
||||
TranslateModelId int `json:"translate_model_id"` // 用来做提示词翻译的大模型 id
|
||||
MaxFileSize int `json:"max_file_size"` // 最大文件大小,单位:MB
|
||||
License string `json:"license"` // License
|
||||
|
||||
}
|
||||
|
||||
@@ -131,8 +131,17 @@ func (h *ConfigHandler) Active(c *gin.Context) {
|
||||
resp.ERROR(c, err.Error())
|
||||
return
|
||||
}
|
||||
h.App.SysConfig.License = data.License
|
||||
|
||||
// 将 license 写入数据库
|
||||
err = h.DB.Model(&model.Config{}).Where("marker", "system").UpdateColumn("config_json", utils.JsonEncode(h.App.SysConfig)).Error
|
||||
if err != nil {
|
||||
resp.ERROR(c, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
resp.SUCCESS(c)
|
||||
|
||||
resp.SUCCESS(c, info.HostID)
|
||||
}
|
||||
|
||||
// GetLicense 获取 License 信息
|
||||
|
||||
@@ -13,6 +13,9 @@ import (
|
||||
"geekai/core"
|
||||
"geekai/core/types"
|
||||
"geekai/store"
|
||||
"geekai/store/model"
|
||||
"geekai/utils"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -22,16 +25,27 @@ import (
|
||||
|
||||
type LicenseService struct {
|
||||
config types.ApiConfig
|
||||
db *gorm.DB
|
||||
levelDB *store.LevelDB
|
||||
license *types.License
|
||||
urlWhiteList []string
|
||||
machineId string
|
||||
}
|
||||
|
||||
func NewLicenseService(server *core.AppServer, levelDB *store.LevelDB) *LicenseService {
|
||||
func NewLicenseService(server *core.AppServer, levelDB *store.LevelDB, db *gorm.DB) *LicenseService {
|
||||
var license types.License
|
||||
var machineId string
|
||||
_ = levelDB.Get(types.LicenseKey, &license)
|
||||
err := levelDB.Get(types.LicenseKey, &license)
|
||||
logger.Infof("License: %+v", server.SysConfig)
|
||||
if err != nil {
|
||||
var cfg model.Config
|
||||
db.Where("marker", "system").First(&cfg)
|
||||
var sysConfig types.SystemConfig
|
||||
if err := utils.JsonDecode(cfg.Config, &sysConfig); err == nil {
|
||||
license.Key = sysConfig.License
|
||||
license.IsActive = true
|
||||
}
|
||||
}
|
||||
info, err := host.Info()
|
||||
if err == nil {
|
||||
machineId = info.HostID
|
||||
|
||||
@@ -142,7 +142,7 @@ func (s *Service) Create(task types.SunoTask) (RespVo, error) {
|
||||
|
||||
var res RespVo
|
||||
apiURL := fmt.Sprintf("%s/suno/submit/music", apiKey.ApiURL)
|
||||
logger.Debugf("API URL: %s, request body: %+v", apiURL, reqBody)
|
||||
logger.Debugf("API URL: %s, request body: %s", apiURL, utils.JsonEncode(reqBody))
|
||||
r, err := req.C().R().
|
||||
SetHeader("Authorization", "Bearer "+apiKey.Value).
|
||||
SetBody(reqBody).
|
||||
|
||||
Reference in New Issue
Block a user