mirror of
https://github.com/yangjian102621/geekai.git
synced 2026-09-16 18:27:13 +00:00
d4fd38ab7e
- 同步 Plus v4.3.1 功能源并移除商业 License 闭环 - 更新开源镜像命名、Docker 部署版本和 geekai 数据库配置 - 补充前端 ESLint 检查配置并修复存量解析与模板问题 - 保留 JWT、管理员权限、API Key 和 OAuth 等正常鉴权机制
91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
package handler
|
|
|
|
// * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// * Copyright 2023 The Geek-AI Authors. All rights reserved.
|
|
// * Use of this source code is governed by a Apache-2.0 license
|
|
// * that can be found in the LICENSE file.
|
|
// * @Author yangjian102621@163.com
|
|
// * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
import (
|
|
"errors"
|
|
"geekai/core"
|
|
"geekai/core/types"
|
|
"geekai/service/oss"
|
|
"geekai/store/model"
|
|
"geekai/utils"
|
|
"geekai/utils/resp"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ConfigHandler struct {
|
|
BaseHandler
|
|
uploaderManager *oss.UploaderManager
|
|
sysConfig *types.SystemConfig
|
|
}
|
|
|
|
func NewConfigHandler(app *core.AppServer, db *gorm.DB, uploaderManager *oss.UploaderManager, sysConfig *types.SystemConfig) *ConfigHandler {
|
|
return &ConfigHandler{
|
|
BaseHandler: BaseHandler{App: app, DB: db},
|
|
uploaderManager: uploaderManager,
|
|
sysConfig: sysConfig,
|
|
}
|
|
}
|
|
|
|
// RegisterRoutes 注册路由
|
|
func (h *ConfigHandler) RegisterRoutes() {
|
|
group := h.App.Engine.Group("/api/config/")
|
|
|
|
// 无需授权的接口
|
|
group.GET("get", h.Get)
|
|
group.GET("oss/thumb", h.GetOssThumbTemplate)
|
|
}
|
|
|
|
// Get 获取指定的系统配置
|
|
func (h *ConfigHandler) Get(c *gin.Context) {
|
|
key := c.Query("key")
|
|
var config model.Config
|
|
err := h.DB.Where("name", key).First(&config).Error
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
resp.SUCCESS(c, nil)
|
|
return
|
|
}
|
|
|
|
if err != nil {
|
|
resp.ERROR(c, err.Error())
|
|
return
|
|
}
|
|
|
|
var value map[string]any
|
|
err = utils.JsonDecode(config.Value, &value)
|
|
if err != nil {
|
|
resp.ERROR(c, err.Error())
|
|
return
|
|
}
|
|
|
|
if key == types.ConfigKeyWxGzh {
|
|
delete(value, "secret")
|
|
delete(value, "token")
|
|
delete(value, "encoding_aes_key")
|
|
}
|
|
if key == types.ConfigKeySystem {
|
|
if value == nil {
|
|
value = make(map[string]any)
|
|
}
|
|
// 支付开关在 payment 配置中,前端会员页仅需是否展示 Stripe
|
|
value["stripe_pay_enabled"] = h.sysConfig.Payment.Stripe.Enabled
|
|
}
|
|
resp.SUCCESS(c, value)
|
|
}
|
|
|
|
// GetOssThumbTemplate 获取当前存储引擎的缩略图模板
|
|
func (h *ConfigHandler) GetOssThumbTemplate(c *gin.Context) {
|
|
template := h.uploaderManager.GetThumbTemplate()
|
|
resp.SUCCESS(c, gin.H{
|
|
"template": template,
|
|
"active": h.sysConfig.OSS.Active,
|
|
})
|
|
}
|