6 Commits

Author SHA1 Message Date
f1c16e89f0 fix: 修复打包问题 2026-03-31 21:54:41 +08:00
1af7ba290c fix: 修复前端错误 2026-03-31 21:36:18 +08:00
4cbc107d1d fix(README): 修改拉取代码方式 2026-03-28 19:47:41 +08:00
5bd8f3e6ca chore: add frontend submodule 2026-03-28 19:42:24 +08:00
5acb536281 fix: 将开发和生产环境进行区分 2026-03-28 19:27:17 +08:00
bbd554a426 fix: 修改 CORS, 删除 开发代理 2026-03-27 20:08:58 +08:00
8 changed files with 86 additions and 8 deletions

4
.gitmodules vendored Normal file
View File

@@ -0,0 +1,4 @@
[submodule "web/frontend"]
path = web/frontend
url = https://gitea.kmux.cn/zhilv/wk-frontend
branch = main

View File

@@ -7,6 +7,14 @@
- 获取网课记录
- 学习接口
### 拉取代码
```shell
git clone --recurse-submodules https://gitea.kmux.cn/zhilv/wk-backend
```
### 代码构建
**推荐使用 [Taskfile](https://taskfile.dev/) 进行项目构建**

View File

@@ -39,8 +39,8 @@ func NewWK(username, password, host string, cookies []*http.Cookie) *WK {
req := request.NewClient(&request.Config{
UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0",
Proxy: "http://127.0.0.1:9000",
VerifySSL: false,
// Proxy: "http://127.0.0.1:9000",
// VerifySSL: false,
})
if len(cookies) > 0 {
req.SetCookies(cookies)

View File

@@ -42,6 +42,10 @@ type LoginReq struct {
Host string `json:"host" binding:"required"`
}
type CourseReq struct {
Status ckwk.CourseKind `json:"status"`
}
type StudyReq struct {
NodeID string `json:"node_id"`
StudyID string `json:"study_id"`

View File

@@ -93,6 +93,50 @@ func (h *WKHandler) Logout(ctx *gin.Context) {
ctx.JSON(200, dto.Ok())
}
func (h *WKHandler) UserInfo(ctx *gin.Context) {
val, ok := ctx.Get("wk_instance")
if !ok {
ctx.JSON(200, dto.Error(-1, "登录已过期"))
return
}
wk := val.(*ckwk.WK)
userinfo, err := wk.UserInfoGet()
if err != nil {
ctx.JSON(200, dto.Error(-1, err.Error()))
return
}
ctx.JSON(200, dto.Success(map[string]any{
"user": userinfo,
}))
}
func (h *WKHandler) Course(ctx *gin.Context) {
var req dto.CourseReq
if err := ctx.ShouldBindJSON(&req); err != nil {
ctx.JSON(200, dto.Error(-1, "请求参数错误"))
return
}
val, ok := ctx.Get("wk_instance")
if !ok {
ctx.JSON(200, dto.Error(-1, "登录已过期"))
return
}
wk := val.(*ckwk.WK)
courses, err := wk.CourseGet(req.Status)
if err != nil {
ctx.JSON(200, dto.Error(-1, err.Error()))
return
}
ctx.JSON(200, dto.Success(map[string]any{
"courses": courses,
}))
}
func (h *WKHandler) Study(ctx *gin.Context) {
val, ok := ctx.Get("wk_instance")
if !ok {

View File

@@ -16,17 +16,34 @@ import (
"go.uber.org/zap"
)
func SetupRouter() *gin.Engine {
var (
AllowOrigins []string
AllowMethods []string
AllowHeaders []string
)
func init() {
if conf.Mode != gin.ReleaseMode {
AllowOrigins = []string{"*"}
AllowMethods = []string{"*"}
AllowHeaders = []string{"*"}
gin.SetMode(gin.DebugMode)
} else {
AllowOrigins = []string{"*.kmux.cn"}
AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "PATCH"}
AllowHeaders = []string{"X-Session-Id"}
gin.SetMode(gin.ReleaseMode)
}
}
func SetupRouter() *gin.Engine {
r := gin.Default()
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"*.kmux.cn"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "PATCH"},
AllowHeaders: []string{"X-Session-Id"},
AllowOrigins: AllowOrigins,
AllowMethods: AllowMethods,
AllowHeaders: AllowHeaders,
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
@@ -56,6 +73,8 @@ func SetupRouter() *gin.Engine {
v2 := api.Group("/v2", sessionMiddleware)
{
v2.POST("/logout", wkHandler.Logout)
v2.POST("/userinfo", wkHandler.UserInfo)
v2.POST("/course", wkHandler.Course)
v2.POST("/study", wkHandler.Study)
v2.POST("/record", wkHandler.AllRecord)
}

2
web/.gitignore vendored
View File

@@ -1,2 +0,0 @@
frontend
dist

1
web/frontend Submodule

Submodule web/frontend added at a061123e36