feat: 添加版本和构建时间变量 fix: 修正短信队列类型注释错误 style: 清理未使用的代码和测试文件 docs: 更新安装文档中的下载链接 chore: 迁移数据库脚本添加日志和订阅配置
88 lines
3.1 KiB
Go
88 lines
3.1 KiB
Go
package common
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/perfect-panel/server/internal/svc"
|
|
"github.com/perfect-panel/server/internal/types"
|
|
"github.com/perfect-panel/server/pkg/logger"
|
|
"github.com/perfect-panel/server/pkg/tool"
|
|
"github.com/perfect-panel/server/pkg/xerr"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type GetGlobalConfigLogic struct {
|
|
logger.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// Get global config
|
|
func NewGetGlobalConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGlobalConfigLogic {
|
|
return &GetGlobalConfigLogic{
|
|
Logger: logger.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetGlobalConfigLogic) GetGlobalConfig() (resp *types.GetGlobalConfigResponse, err error) {
|
|
resp = new(types.GetGlobalConfigResponse)
|
|
|
|
currencyCfg, err := l.svcCtx.SystemModel.GetCurrencyConfig(l.ctx)
|
|
if err != nil {
|
|
l.Logger.Error("[GetGlobalConfigLogic] GetCurrencyConfig error: ", logger.Field("error", err.Error()))
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "GetCurrencyConfig error: %v", err.Error())
|
|
}
|
|
verifyCodeCfg, err := l.svcCtx.SystemModel.GetVerifyCodeConfig(l.ctx)
|
|
if err != nil {
|
|
l.Logger.Error("[GetGlobalConfigLogic] GetVerifyCodeConfig error: ", logger.Field("error", err.Error()))
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "GetVerifyCodeConfig error: %v", err.Error())
|
|
}
|
|
|
|
tool.DeepCopy(&resp.Site, l.svcCtx.Config.Site)
|
|
tool.DeepCopy(&resp.Subscribe, l.svcCtx.Config.Subscribe)
|
|
tool.DeepCopy(&resp.Auth.Email, l.svcCtx.Config.Email)
|
|
tool.DeepCopy(&resp.Auth.Mobile, l.svcCtx.Config.Mobile)
|
|
tool.DeepCopy(&resp.Auth.Register, l.svcCtx.Config.Register)
|
|
tool.DeepCopy(&resp.Verify, l.svcCtx.Config.Verify)
|
|
tool.DeepCopy(&resp.Invite, l.svcCtx.Config.Invite)
|
|
tool.SystemConfigSliceReflectToStruct(currencyCfg, &resp.Currency)
|
|
tool.SystemConfigSliceReflectToStruct(verifyCodeCfg, &resp.VerifyCode)
|
|
|
|
resp.Verify = types.VeifyConfig{
|
|
TurnstileSiteKey: l.svcCtx.Config.Verify.TurnstileSiteKey,
|
|
EnableLoginVerify: l.svcCtx.Config.Verify.LoginVerify,
|
|
EnableRegisterVerify: l.svcCtx.Config.Verify.RegisterVerify,
|
|
EnableResetPasswordVerify: l.svcCtx.Config.Verify.ResetPasswordVerify,
|
|
}
|
|
var methods []string
|
|
|
|
// auth methods
|
|
authMethods, err := l.svcCtx.AuthModel.FindAll(l.ctx)
|
|
if err != nil {
|
|
l.Logger.Error("[GetGlobalConfigLogic] FindAll error: ", logger.Field("error", err.Error()))
|
|
}
|
|
|
|
for _, method := range authMethods {
|
|
if *method.Enabled {
|
|
methods = append(methods, method.Method)
|
|
if method.Method == "device" {
|
|
_ = json.Unmarshal([]byte(method.Config), &resp.Auth.Device)
|
|
resp.Auth.Device.Enable = true
|
|
}
|
|
}
|
|
}
|
|
resp.OAuthMethods = methods
|
|
|
|
webAds, err := l.svcCtx.SystemModel.FindOneByKey(l.ctx, "WebAD")
|
|
if err != nil {
|
|
l.Logger.Error("[GetGlobalConfigLogic] FindOneByKey error: ", logger.Field("error", err.Error()), logger.Field("key", "WebAD"))
|
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "FindOneByKey error: %v", err.Error())
|
|
}
|
|
// web ads config
|
|
resp.WebAd = webAds.Value == "true"
|
|
return
|
|
}
|