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

@@ -4,6 +4,7 @@ import (
"ckwk/internal/ckwk"
"ckwk/internal/dto"
"ckwk/pkg/log"
"errors"
"fmt"
"net/http"
@@ -44,25 +45,22 @@ func (h *WKHandler) Login(ctx *gin.Context) {
ctx.JSON(200, dto.Error(-1, "登录失败:请提供账号密码或有效的 Token并确保 Host 正确"))
return
}
userinfo, err := wk.UserInfoGet()
if err != nil {
ctx.JSON(200, dto.Error(-1, err.Error()))
return
}
courses, err := wk.CourseGet(req.Status)
if err != nil {
ctx.JSON(200, dto.Error(-1, err.Error()))
return
if req.Token == "" {
ok, err := wk.Login()
if err != nil {
ctx.JSON(200, dto.Error(-1, err.Error()))
return
}
if !ok {
ctx.JSON(200, dto.Error(-1, "登录失败"))
return
}
}
sessionID := h.Session.Store(wk)
ctx.JSON(200, dto.Success(map[string]any{
"session_id": sessionID,
"user": userinfo,
"courses": courses,
}))
}
@@ -76,6 +74,10 @@ func (h *WKHandler) Online(ctx *gin.Context) {
flag, err := wk.Online()
if err != nil {
if errors.Is(err, ckwk.ErrSessionRemoved) {
ctx.JSON(http.StatusUnauthorized, dto.Error(401, err.Error()))
return
}
ctx.JSON(200, dto.Error(-1, err.Error()))
return
}
@@ -153,6 +155,10 @@ func (h *WKHandler) Study(ctx *gin.Context) {
result, err := wk.Study(req.NodeID, req.StudyID, req.StudyTime, req.Status)
if err != nil {
if errors.Is(err, ckwk.ErrSessionRemoved) {
ctx.JSON(http.StatusUnauthorized, dto.Error(401, err.Error()))
return
}
ctx.JSON(200, dto.Error(-1, err.Error()))
return
}

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
}

View File

@@ -8,12 +8,13 @@ import (
)
func Version(ctx *gin.Context) {
ctx.JSON(200, dto.Success(map[string]string{
"Mode": conf.Mode,
"Version": conf.Version,
"BuildAt": conf.BuildAt,
"GitAuthor": conf.GitAuthor,
"GitEmail": conf.GitEmail,
"GitCommit": conf.GitCommit,
ctx.JSON(200, dto.Success(map[string]any{
"Mode": conf.Mode,
"Version": conf.Version,
"BuildAt": conf.BuildAt,
"GitAuthor": conf.GitAuthor,
"GitEmail": conf.GitEmail,
"GitCommit": conf.GitCommit,
"DebugEnabled": conf.IsRuntimeDebugEnabled(),
}))
}