引入2.1应做的全新UI变更

This commit is contained in:
2026-07-28 19:11:40 +08:00
parent c2516dc8ff
commit aaac3fc791
4 changed files with 233 additions and 38 deletions
+33 -1
View File
@@ -6,11 +6,13 @@ import (
"fmt"
"io"
"io/fs"
"net"
"net/http"
"os"
"strconv"
"strings"
"text/template"
"time"
"github.com/gin-gonic/gin"
"golang.org/x/crypto/bcrypt"
@@ -64,7 +66,7 @@ func SetupRouter() *gin.Engine {
auth.POST("/frpc/stop", stopFrpcHandler)
auth.GET("/frpc/status", getFrpcStatusHandler)
auth.GET("/frpc/log", getFrpcLogHandler)
auth.GET("/ping", pingHandler)
auth.POST("/import/toml", importTomlHandler)
auth.GET("/export/toml", ExportTomlHandler)
@@ -143,6 +145,36 @@ func registerHandler(c *gin.Context) {
})
}
// Ping 延迟检测
func pingHandler(c *gin.Context) {
target := c.Query("target")
if target == "" {
c.JSON(http.StatusBadRequest, gin.H{"code": 1, "msg": "缺少 target 参数"})
return
}
// 获取全局配置(获取服务端端口)
cfg, err := GetGlobalConfig()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"code": 2, "msg": "读取配置失败"})
return
}
port := cfg.ServerPort
address := net.JoinHostPort(target, strconv.Itoa(port))
start := time.Now()
conn, err := net.DialTimeout("tcp", address, 5*time.Second)
if err != nil {
c.JSON(http.StatusOK, gin.H{"code": 1, "msg": "ping 失败", "latency": -1})
return
}
conn.Close()
latency := time.Since(start).Milliseconds()
c.JSON(http.StatusOK, gin.H{"code": 0, "latency": latency})
}
func loginHandler(c *gin.Context) {
var req struct {
Username string `json:"username"`