即梦视频后台管理页面初始化

This commit is contained in:
GeekMaster
2025-07-18 21:19:59 +08:00
parent 5e4ba6d971
commit 73d003d6c3
10 changed files with 172 additions and 65 deletions

View File

@@ -60,13 +60,28 @@ func (s *AppServer) Init(debug bool, client *redis.Client) {
}
func (s *AppServer) Run(db *gorm.DB) error {
// 重命名 config 表字段
if db.Migrator().HasColumn(&model.Config{}, "config_json") {
db.Migrator().RenameColumn(&model.Config{}, "config_json", "value")
}
if db.Migrator().HasColumn(&model.Config{}, "marker") {
db.Migrator().RenameColumn(&model.Config{}, "marker", "name")
}
if db.Migrator().HasIndex(&model.Config{}, "idx_chatgpt_configs_key") {
db.Migrator().DropIndex(&model.Config{}, "idx_chatgpt_configs_key")
}
if db.Migrator().HasIndex(&model.Config{}, "marker") {
db.Migrator().DropIndex(&model.Config{}, "marker")
}
// load system configs
var sysConfig model.Config
err := db.Where("marker", "system").First(&sysConfig).Error
err := db.Where("name", "system").First(&sysConfig).Error
if err != nil {
return fmt.Errorf("failed to load system config: %v", err)
}
err = utils.JsonDecode(sysConfig.Config, &s.SysConfig)
err = utils.JsonDecode(sysConfig.Value, &s.SysConfig)
if err != nil {
return fmt.Errorf("failed to decode system config: %v", err)
}

View File

@@ -66,15 +66,15 @@ func (h *ConfigHandler) Update(c *gin.Context) {
}
value := utils.JsonEncode(&data.Config)
config := model.Config{Key: data.Key, Config: value}
res := h.DB.FirstOrCreate(&config, model.Config{Key: data.Key})
config := model.Config{Name: data.Key, Value: value}
res := h.DB.FirstOrCreate(&config, model.Config{Name: data.Key})
if res.Error != nil {
resp.ERROR(c, res.Error.Error())
return
}
if config.Id > 0 {
config.Config = value
config.Value = value
res := h.DB.Updates(&config)
if res.Error != nil {
resp.ERROR(c, res.Error.Error())
@@ -83,16 +83,16 @@ func (h *ConfigHandler) Update(c *gin.Context) {
// update config cache for AppServer
var cfg model.Config
h.DB.Where("marker", data.Key).First(&cfg)
h.DB.Where("name", data.Key).First(&cfg)
var err error
if data.Key == "system" {
err = utils.JsonDecode(cfg.Config, &h.App.SysConfig)
err = utils.JsonDecode(cfg.Value, &h.App.SysConfig)
}
if err != nil {
resp.ERROR(c, "Failed to update config cache: "+err.Error())
return
}
logger.Infof("Update AppServer's config successfully: %v", config.Config)
logger.Infof("Update AppServer's config successfully: %v", config.Value)
}
resp.SUCCESS(c, config)
@@ -102,14 +102,14 @@ func (h *ConfigHandler) Update(c *gin.Context) {
func (h *ConfigHandler) Get(c *gin.Context) {
key := c.Query("key")
var config model.Config
res := h.DB.Where("marker", key).First(&config)
res := h.DB.Where("name", key).First(&config)
if res.Error != nil {
resp.ERROR(c, res.Error.Error())
return
}
var value map[string]interface{}
err := utils.JsonDecode(config.Config, &value)
err := utils.JsonDecode(config.Value, &value)
if err != nil {
resp.ERROR(c, err.Error())
return

View File

@@ -31,14 +31,14 @@ func NewConfigHandler(app *core.AppServer, db *gorm.DB, licenseService *service.
func (h *ConfigHandler) Get(c *gin.Context) {
key := c.Query("key")
var config model.Config
res := h.DB.Where("marker", key).First(&config)
res := h.DB.Where("name", key).First(&config)
if res.Error != nil {
resp.ERROR(c, res.Error.Error())
return
}
var value map[string]interface{}
err := utils.JsonDecode(config.Config, &value)
var value map[string]any
err := utils.JsonDecode(config.Value, &value)
if err != nil {
resp.ERROR(c, err.Error())
return

View File

@@ -1,9 +1,9 @@
package model
type Config struct {
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
Key string `gorm:"column:marker;type:varchar(20);uniqueIndex;not null;comment:标识" json:"marker"`
Config string `gorm:"column:config_json;type:text;not null" json:"config_json"`
Id uint `gorm:"column:id;primaryKey;autoIncrement"`
Name string `gorm:"column:name;type:varchar(20);uniqueIndex;not null;comment:配置名称"`
Value string `gorm:"column:value;type:text;not null"`
}
func (m *Config) TableName() string {

View File

@@ -1,9 +0,0 @@
package vo
import "geekai/core/types"
type Config struct {
Id uint `json:"id"`
Key string `json:"key"`
SystemConfig types.SystemConfig `json:"system_config"`
}