将 license 存储到数据库

This commit is contained in:
RockYang 2025-03-02 21:49:34 +08:00
parent f98dcee7d4
commit 6b0d4e81bf
6 changed files with 35 additions and 8 deletions

View File

@ -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
}

View File

@ -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 信息

View File

@ -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

View File

@ -146,7 +146,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).

View File

@ -90,7 +90,7 @@
.song {
display flex
padding 10px
background-color #252020
background-color var(--el-bg-color)
border-radius 10px
margin-bottom 10px
font-size 14px
@ -109,6 +109,7 @@
display flex
margin-left 10px
align-items center
color var(--el-color-primary)
}
.el-button--info {
@ -347,7 +348,9 @@
.task {
height 100px
background-color #2A2525
background-color var(--el-bg-color)
border: 1px solid var(--el-border-color-light);
border-radius 5px
display flex
margin-bottom 10px
.left {
@ -358,7 +361,7 @@
width 320px
.title {
font-size 14px
color #e1e1e1
color var(--el-text-color-primary)
white-space: nowrap; /* */
overflow: hidden; /* */
text-overflow: ellipsis; /* */

View File

@ -151,7 +151,7 @@ const store = useSharedStore();
onMounted(() => {
checkSession().then(() => {
fetchData(1);
});
}).catch(() => {});
store.addMessageHandler("luma", (data) => {
//