Files
qitongxue-api/internal/logic/app_config.go
2026-09-30 17:01:18 +08:00

41 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package logic
import (
"context"
"encoding/json"
"github.com/gogf/gf/v2/frame/g"
userv1 "tool-api/api/user/v1"
"tool-api/internal/consts"
)
// ============================================================================
// 应用配置(迭代-2026-09-30):界面级轻量配置下发
//
// 数据源是 settings 表(约定 S9),这里只做「解析 + URL 拼接」,不引入新表。
// 解析失败一律回落空 map(fail-open):配置坏了不能把首页打挂。
// ============================================================================
// AppConfig 下发应用配置(首页便捷功能卡背景图等)。
// covers 值为相对路径,输出统一 absoluteURL 拼接(图片域名不落库)。
func AppConfig(ctx context.Context) (*userv1.AppConfigRes, error) {
res := &userv1.AppConfigRes{FeatureCovers: map[string]string{}}
raw := SettingValue(ctx, consts.SettingHomeFeatureCovers)
if raw == "" {
return res, nil
}
paths := map[string]string{}
if err := json.Unmarshal([]byte(raw), &paths); err != nil {
g.Log().Warningf(ctx, "[appconfig] %s 解析失败,回落空配置: %v", consts.SettingHomeFeatureCovers, err)
return res, nil
}
for key, p := range paths {
if key == "" || p == "" {
continue
}
res.FeatureCovers[key] = absoluteURL(ctx, p)
}
return res, nil
}