release: v0.1.3

This commit is contained in:
2026-04-03 14:24:29 +08:00
parent 98839e9782
commit 83ee4bb5ea
14 changed files with 413 additions and 132 deletions

View File

@@ -1,6 +1,7 @@
package handler
import (
"ckwk/internal/conf"
"encoding/json"
"fmt"
"net/http"
@@ -19,13 +20,44 @@ var debugLogUpgrader = websocket.Upgrader{
},
}
type debugConfigReq struct {
Enabled bool `json:"enabled"`
}
func DebugConfig(ctx *gin.Context) {
ctx.JSON(http.StatusOK, dto.Success(map[string]any{
"enabled": conf.IsRuntimeDebugEnabled(),
"proxy": conf.DebugProxy,
"skip_ssl_verify": conf.DebugSkipSSLVerify,
"build_mode": conf.Mode,
"proxy_configured": conf.DebugProxy != "",
}))
}
func UpdateDebugConfig(ctx *gin.Context) {
var req debugConfigReq
if err := ctx.ShouldBindJSON(&req); err != nil {
ctx.JSON(http.StatusBadRequest, dto.Error(400, "请求参数错误"))
return
}
conf.SetRuntimeDebugEnabled(req.Enabled)
DebugConfig(ctx)
}
func DebugLogs(ctx *gin.Context) {
if !ensureDebugEnabled(ctx) {
return
}
ctx.JSON(http.StatusOK, dto.Success(map[string]any{
"list": log.Entries(),
}))
}
func DebugLogsDownload(ctx *gin.Context) {
if !ensureDebugEnabled(ctx) {
return
}
entries := log.Entries()
content, err := json.MarshalIndent(entries, "", " ")
if err != nil {
@@ -40,6 +72,9 @@ func DebugLogsDownload(ctx *gin.Context) {
}
func DebugLogWS(ctx *gin.Context) {
if !ensureDebugEnabled(ctx) {
return
}
conn, err := debugLogUpgrader.Upgrade(ctx.Writer, ctx.Request, nil)
if err != nil {
return
@@ -86,3 +121,12 @@ func DebugLogWS(ctx *gin.Context) {
}
}
}
func ensureDebugEnabled(ctx *gin.Context) bool {
if conf.IsRuntimeDebugEnabled() {
return true
}
ctx.JSON(http.StatusForbidden, dto.Error(403, "调试功能未开启,请先在设置页手动开启"))
return false
}