mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 07:26:36 +08:00
refactor(plugins): restructure admin and message_gateway into standard layered sub-packages
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"Wavelet/core"
|
||||
"Wavelet/core/contracts"
|
||||
"Wavelet/pkg/config"
|
||||
"Wavelet/pkg/logger"
|
||||
"Wavelet/pkg/response"
|
||||
"net/http"
|
||||
"reflect"
|
||||
@@ -57,13 +58,9 @@ func (p *Plugin) Apply(ctx *core.Context) error {
|
||||
|
||||
// 2. Public config
|
||||
ctx.Router().GET("/api/v1/config/public", func(c *gin.Context) {
|
||||
type configItem struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
var configs []configItem
|
||||
if dbSvc, err := core.Inject[contracts.DBService](ctx); err == nil && dbSvc != nil {
|
||||
_ = dbSvc.DB(c.Request.Context()).Table("w_system_configs").Where("visibility = ?", "visible").Find(&configs).Error
|
||||
configs, err := listPublicSystemConfigs(c.Request.Context(), ctx)
|
||||
if err != nil {
|
||||
logger.ErrorF(c.Request.Context(), "[System] query public system configs failed: %v", err)
|
||||
}
|
||||
c.JSON(http.StatusOK, response.OK(gin.H{
|
||||
"configs": configs,
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright 2026 Arctel.net
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package system
|
||||
|
||||
import (
|
||||
"Wavelet/core"
|
||||
"Wavelet/core/contracts"
|
||||
"context"
|
||||
)
|
||||
|
||||
// publicSystemConfig 前端公共配置接口的只读投影。
|
||||
type publicSystemConfig struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// listPublicSystemConfigs 读取对前端可见的系统配置项。
|
||||
//
|
||||
// 注意:w_system_configs 的所有者插件是 admin,contracts 目前尚未暴露读取契约,
|
||||
// 因此此处仍只能直连只读查询;待 admin 提供 SettingsService 契约后应改为调用契约。
|
||||
func listPublicSystemConfigs(ctx context.Context, appCtx *core.Context) ([]publicSystemConfig, error) {
|
||||
dbSvc, err := core.Inject[contracts.DBService](appCtx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dbSvc == nil {
|
||||
return nil, nil
|
||||
}
|
||||
var configs []publicSystemConfig
|
||||
err = dbSvc.DB(ctx).Table("w_system_configs").
|
||||
Where("visibility = ?", "visible").
|
||||
Find(&configs).Error
|
||||
return configs, err
|
||||
}
|
||||
Reference in New Issue
Block a user