refactor(app): 移除 naive-ui 依赖并优化配置结构
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 配置中的自动导入和组件解析插件
This commit is contained in:
Flik
2026-01-22 20:37:11 +08:00
parent d1058f9e89
commit 7cddb7b3e7
13 changed files with 352 additions and 958 deletions

View File

@@ -27,7 +27,6 @@ import (
"github.com/gotunnel/internal/server/tunnel"
"github.com/gotunnel/pkg/crypto"
"github.com/gotunnel/pkg/plugin"
"github.com/gotunnel/pkg/plugin/sign"
"github.com/gotunnel/pkg/version"
)
@@ -83,12 +82,6 @@ func main() {
server.SetPluginRegistry(registry)
server.SetJSPluginStore(clientStore) // 设置 JS 插件存储,用于客户端重连时恢复插件
// 加载 JS 插件配置
if len(cfg.JSPlugins) > 0 {
jsPlugins := loadJSPlugins(cfg.JSPlugins)
server.LoadJSPlugins(jsPlugins)
}
// 启动 Web 控制台
if cfg.Server.Web.Enabled {
// 强制生成 Web 凭据(如果未配置)
@@ -128,69 +121,3 @@ func main() {
log.Fatal(server.Run())
}
// loadJSPlugins 加载 JS 插件文件
func loadJSPlugins(configs []config.JSPluginConfig) []tunnel.JSPluginEntry {
var plugins []tunnel.JSPluginEntry
for _, cfg := range configs {
source, err := os.ReadFile(cfg.Path)
if err != nil {
log.Printf("[JSPlugin] Failed to load %s: %v", cfg.Path, err)
continue
}
// 加载签名文件
sigPath := cfg.SigPath
if sigPath == "" {
sigPath = cfg.Path + ".sig"
}
signature, err := os.ReadFile(sigPath)
if err != nil {
log.Printf("[JSPlugin] Failed to load signature for %s: %v", cfg.Name, err)
continue
}
// 服务端也验证签名,防止配置文件被篡改
if err := verifyPluginSignature(cfg.Name, string(source), string(signature)); err != nil {
log.Printf("[JSPlugin] Signature verification failed for %s: %v", cfg.Name, err)
continue
}
plugins = append(plugins, tunnel.JSPluginEntry{
Name: cfg.Name,
Source: string(source),
Signature: string(signature),
AutoPush: cfg.AutoPush,
Config: cfg.Config,
AutoStart: cfg.AutoStart,
})
log.Printf("[JSPlugin] Loaded: %s from %s (verified)", cfg.Name, cfg.Path)
}
return plugins
}
// verifyPluginSignature 验证插件签名
func verifyPluginSignature(name, source, signature string) error {
// 解码签名
signed, err := sign.DecodeSignedPlugin(signature)
if err != nil {
return fmt.Errorf("decode signature: %w", err)
}
// 获取公钥
pubKey, err := sign.GetPublicKeyByID(signed.Payload.KeyID)
if err != nil {
return err
}
// 验证插件名称
if signed.Payload.Name != name {
return fmt.Errorf("name mismatch: %s vs %s", signed.Payload.Name, name)
}
// 验证签名
return sign.VerifyPlugin(pubKey, signed, source)
}

View File

@@ -11,18 +11,6 @@ import (
// ServerConfig 服务端配置
type ServerConfig struct {
Server ServerSettings `yaml:"server"`
PluginStore PluginStoreSettings `yaml:"plugin_store"`
JSPlugins []JSPluginConfig `yaml:"js_plugins,omitempty"`
}
// JSPluginConfig JS 插件配置
type JSPluginConfig struct {
Name string `yaml:"name"`
Path string `yaml:"path"` // JS 文件路径
SigPath string `yaml:"sig_path,omitempty"` // 签名文件路径 (默认为 path + ".sig")
AutoPush []string `yaml:"auto_push,omitempty"` // 自动推送到的客户端 ID 列表
Config map[string]string `yaml:"config,omitempty"` // 插件配置
AutoStart bool `yaml:"auto_start,omitempty"` // 是否自动启动
}
// PluginStoreSettings 插件仓库设置
@@ -51,6 +39,7 @@ type ServerSettings struct {
DBPath string `yaml:"db_path"`
TLSDisabled bool `yaml:"tls_disabled"`
Web WebSettings `yaml:"web"`
PluginStore PluginStoreSettings `yaml:"plugin_store"`
}
// WebSettings Web控制台设置

View File

@@ -5,6 +5,7 @@ package dto
type UpdateServerConfigRequest struct {
Server *ServerConfigPart `json:"server"`
Web *WebConfigPart `json:"web"`
PluginStore *PluginStoreConfigPart `json:"plugin_store"`
}
// ServerConfigPart 服务器配置部分
@@ -31,6 +32,7 @@ type WebConfigPart struct {
type ServerConfigResponse struct {
Server ServerConfigInfo `json:"server"`
Web WebConfigInfo `json:"web"`
PluginStore PluginStoreConfigInfo `json:"plugin_store"`
}
// ServerConfigInfo 服务器配置信息
@@ -49,3 +51,13 @@ type WebConfigInfo struct {
Username string `json:"username"`
Password string `json:"password"` // 显示为 ****
}
// PluginStoreConfigPart 插件商店配置部分
type PluginStoreConfigPart struct {
URL string `json:"url"`
}
// PluginStoreConfigInfo 插件商店配置信息
type PluginStoreConfigInfo struct {
URL string `json:"url"`
}

View File

@@ -47,6 +47,9 @@ func (h *ConfigHandler) Get(c *gin.Context) {
Username: cfg.Server.Web.Username,
Password: "****",
},
PluginStore: dto.PluginStoreConfigInfo{
URL: cfg.Server.PluginStore.URL,
},
}
Success(c, resp)
@@ -100,6 +103,11 @@ func (h *ConfigHandler) Update(c *gin.Context) {
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

View File

@@ -34,7 +34,7 @@ func NewStoreHandler(app AppInterface) *StoreHandler {
// @Router /api/store/plugins [get]
func (h *StoreHandler) ListPlugins(c *gin.Context) {
cfg := h.app.GetConfig()
storeURL := cfg.PluginStore.GetPluginStoreURL()
storeURL := cfg.Server.PluginStore.GetPluginStoreURL()
// 从远程 URL 获取插件列表
client := &http.Client{Timeout: 10 * time.Second}

2
web/components.d.ts vendored
View File

@@ -17,8 +17,6 @@ declare module 'vue' {
HelloWorld: typeof import('./src/components/HelloWorld.vue')['default']
InlineLogPanel: typeof import('./src/components/InlineLogPanel.vue')['default']
LogViewer: typeof import('./src/components/LogViewer.vue')['default']
NIcon: typeof import('naive-ui')['NIcon']
NTag: typeof import('naive-ui')['NTag']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
}

974
web/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,6 @@
"dependencies": {
"@vicons/ionicons5": "^0.13.0",
"axios": "^1.13.2",
"naive-ui": "^2.43.2",
"vue": "^3.5.24",
"vue-router": "^4.6.4"
},
@@ -24,8 +23,6 @@
"postcss": "^8.5.6",
"tailwindcss": "^4.1.18",
"typescript": "~5.9.3",
"unplugin-auto-import": "^20.3.0",
"unplugin-vue-components": "^30.0.0",
"vite": "^7.2.4",
"vue-tsc": "^3.1.4"
}

View File

@@ -1,10 +1,6 @@
<script setup lang="ts">
import { ref, onMounted, computed, watch } from 'vue'
import { RouterView, useRouter, useRoute } from 'vue-router'
import {
NConfigProvider, NMessageProvider, NDialogProvider, NGlobalStyle,
type GlobalThemeOverrides
} from 'naive-ui'
import {
HomeOutline, DesktopOutline, SettingsOutline,
PersonCircleOutline, LogOutOutline, LogoGithub, ServerOutline, CheckmarkCircleOutline, ArrowUpCircleOutline
@@ -88,29 +84,9 @@ const logout = () => {
const toggleUserMenu = () => {
showUserMenu.value = !showUserMenu.value
}
// 紫色渐变主题
const themeOverrides: GlobalThemeOverrides = {
common: {
primaryColor: '#6366f1',
primaryColorHover: '#818cf8',
primaryColorPressed: '#4f46e5',
},
Layout: {
headerColor: '#ffffff'
},
Tabs: {
tabTextColorActiveLine: '#6366f1',
barColor: '#6366f1'
}
}
</script>
<template>
<n-config-provider :theme-overrides="themeOverrides">
<n-global-style />
<n-dialog-provider>
<n-message-provider>
<div v-if="!isLoginPage" class="app-layout">
<!-- Header -->
<header class="app-header">
@@ -174,9 +150,6 @@ const themeOverrides: GlobalThemeOverrides = {
</footer>
</div>
<RouterView v-else />
</n-message-provider>
</n-dialog-provider>
</n-config-provider>
</template>
<style scoped>

View File

@@ -212,14 +212,20 @@ export interface WebConfigInfo {
password: string
}
export interface PluginStoreConfigInfo {
url: string
}
export interface ServerConfigResponse {
server: ServerConfigInfo
web: WebConfigInfo
plugin_store: PluginStoreConfigInfo
}
export interface UpdateServerConfigRequest {
server?: Partial<ServerConfigInfo>
web?: Partial<WebConfigInfo>
plugin_store?: Partial<PluginStoreConfigInfo>
}
export const getServerConfig = () => get<ServerConfigResponse>('/config')

View File

@@ -1,10 +1,8 @@
import { createApp } from 'vue'
import naive from 'naive-ui'
import './style.css'
import App from './App.vue'
import router from './router'
const app = createApp(App)
app.use(router)
app.use(naive)
app.mount('#app')

View File

@@ -30,7 +30,8 @@ const configForm = ref({
heartbeat_sec: 30,
heartbeat_timeout: 90,
web_username: '',
web_password: ''
web_password: '',
plugin_store_url: ''
})
const loadVersionInfo = async () => {
@@ -55,7 +56,8 @@ const loadServerConfig = async () => {
heartbeat_sec: data.server.heartbeat_sec,
heartbeat_timeout: data.server.heartbeat_timeout,
web_username: data.web.username,
web_password: ''
web_password: '',
plugin_store_url: data.plugin_store.url
}
} catch (e) {
console.error('Failed to load server config', e)
@@ -75,6 +77,9 @@ const handleSaveConfig = async () => {
},
web: {
username: configForm.value.web_username
},
plugin_store: {
url: configForm.value.plugin_store_url
}
}
// 只有填写了密码才更新
@@ -269,6 +274,19 @@ onMounted(() => {
</div>
</div>
<div class="form-divider"></div>
<div class="form-group">
<label class="form-label">插件商店地址</label>
<input
v-model="configForm.plugin_store_url"
type="text"
class="glass-input"
placeholder="https://example.com/plugins"
/>
<span class="form-hint">插件商店的 API 地址</span>
</div>
<div class="form-actions">
<button
class="glass-btn primary"

View File

@@ -1,24 +1,10 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
// https://vite.dev/config/
export default defineConfig({
plugins: [
vue(),
AutoImport({
imports: [
'vue',
{
'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar']
}
]
}),
Components({
resolvers: [NaiveUiResolver()]
})
vue()
],
build: {
chunkSizeWarningLimit: 1500,