All checks were successful
Build Multi-Platform Binaries / build-frontend (push) Successful in 31s
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Successful in 1m30s
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Successful in 1m39s
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Successful in 1m19s
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Successful in 1m43s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Successful in 1m18s
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Successful in 1m38s
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Successful in 1m50s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Successful in 2m6s
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Successful in 1m18s
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Successful in 1m57s
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Successful in 1m25s
- 从 App.vue 中移除 naive-ui 组件及其主题配置 - 从组件声明中移除 NIcon 和 NTag 组件引用 - 将 JSPluginConfig 从 ServerConfig 中分离 - 在 ServerSettings 中整合 PluginStore 配置 - 更新配置 DTO 结构以支持 PluginStore 配置 - 移除 JS 插件加载和签名验证相关代码 - 从 main.ts 中移除 naive-ui 的引入和使用 - 从 package.json 中移除 naive-ui 和相关自动导入插件依赖 - 在设置页面添加插件商店 URL 配置字段 - 更新 StoreHandler 中插件商店 URL 的获取方式 - 移除 Vite 配置中的自动导入和组件解析插件
136 lines
3.2 KiB
Go
136 lines
3.2 KiB
Go
package handler
|
||
|
||
import (
|
||
"github.com/gin-gonic/gin"
|
||
// removed router import
|
||
"github.com/gotunnel/internal/server/router/dto"
|
||
)
|
||
|
||
// ConfigHandler 配置处理器
|
||
type ConfigHandler struct {
|
||
app AppInterface
|
||
}
|
||
|
||
// NewConfigHandler 创建配置处理器
|
||
func NewConfigHandler(app AppInterface) *ConfigHandler {
|
||
return &ConfigHandler{app: app}
|
||
}
|
||
|
||
// Get 获取服务器配置
|
||
// @Summary 获取配置
|
||
// @Description 返回服务器配置(敏感信息脱敏)
|
||
// @Tags 配置
|
||
// @Produce json
|
||
// @Security Bearer
|
||
// @Success 200 {object} Response{data=dto.ServerConfigResponse}
|
||
// @Router /api/config [get]
|
||
func (h *ConfigHandler) Get(c *gin.Context) {
|
||
cfg := h.app.GetConfig()
|
||
|
||
// Token 脱敏处理,只显示前4位
|
||
maskedToken := cfg.Server.Token
|
||
if len(maskedToken) > 4 {
|
||
maskedToken = maskedToken[:4] + "****"
|
||
}
|
||
|
||
resp := dto.ServerConfigResponse{
|
||
Server: dto.ServerConfigInfo{
|
||
BindAddr: cfg.Server.BindAddr,
|
||
BindPort: cfg.Server.BindPort,
|
||
Token: maskedToken,
|
||
HeartbeatSec: cfg.Server.HeartbeatSec,
|
||
HeartbeatTimeout: cfg.Server.HeartbeatTimeout,
|
||
},
|
||
Web: dto.WebConfigInfo{
|
||
Enabled: cfg.Server.Web.Enabled,
|
||
BindPort: cfg.Server.Web.BindPort,
|
||
Username: cfg.Server.Web.Username,
|
||
Password: "****",
|
||
},
|
||
PluginStore: dto.PluginStoreConfigInfo{
|
||
URL: cfg.Server.PluginStore.URL,
|
||
},
|
||
}
|
||
|
||
Success(c, resp)
|
||
}
|
||
|
||
// Update 更新服务器配置
|
||
// @Summary 更新配置
|
||
// @Description 更新服务器配置
|
||
// @Tags 配置
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Security Bearer
|
||
// @Param request body dto.UpdateServerConfigRequest true "配置内容"
|
||
// @Success 200 {object} Response
|
||
// @Failure 400 {object} Response
|
||
// @Router /api/config [put]
|
||
func (h *ConfigHandler) Update(c *gin.Context) {
|
||
var req dto.UpdateServerConfigRequest
|
||
if !BindJSON(c, &req) {
|
||
return
|
||
}
|
||
|
||
cfg := h.app.GetConfig()
|
||
|
||
// 更新 Server 配置
|
||
if req.Server != nil {
|
||
if req.Server.BindAddr != "" {
|
||
cfg.Server.BindAddr = req.Server.BindAddr
|
||
}
|
||
if req.Server.BindPort > 0 {
|
||
cfg.Server.BindPort = req.Server.BindPort
|
||
}
|
||
if req.Server.Token != "" {
|
||
cfg.Server.Token = req.Server.Token
|
||
}
|
||
if req.Server.HeartbeatSec > 0 {
|
||
cfg.Server.HeartbeatSec = req.Server.HeartbeatSec
|
||
}
|
||
if req.Server.HeartbeatTimeout > 0 {
|
||
cfg.Server.HeartbeatTimeout = req.Server.HeartbeatTimeout
|
||
}
|
||
}
|
||
|
||
// 更新 Web 配置
|
||
if req.Web != nil {
|
||
cfg.Server.Web.Enabled = req.Web.Enabled
|
||
if req.Web.BindPort > 0 {
|
||
cfg.Server.Web.BindPort = req.Web.BindPort
|
||
}
|
||
cfg.Server.Web.Username = req.Web.Username
|
||
cfg.Server.Web.Password = req.Web.Password
|
||
}
|
||
|
||
// 更新 PluginStore 配置
|
||
if req.PluginStore != nil {
|
||
cfg.Server.PluginStore.URL = req.PluginStore.URL
|
||
}
|
||
|
||
if err := h.app.SaveConfig(); err != nil {
|
||
InternalError(c, err.Error())
|
||
return
|
||
}
|
||
|
||
Success(c, gin.H{"status": "ok"})
|
||
}
|
||
|
||
// Reload 重新加载配置
|
||
// @Summary 重新加载配置
|
||
// @Description 重新加载服务器配置
|
||
// @Tags 配置
|
||
// @Produce json
|
||
// @Security Bearer
|
||
// @Success 200 {object} Response
|
||
// @Failure 500 {object} Response
|
||
// @Router /api/config/reload [post]
|
||
func (h *ConfigHandler) Reload(c *gin.Context) {
|
||
if err := h.app.GetServer().ReloadConfig(); err != nil {
|
||
InternalError(c, err.Error())
|
||
return
|
||
}
|
||
|
||
Success(c, gin.H{"status": "ok"})
|
||
}
|