Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f1c16e89f0 | |||
| 1af7ba290c | |||
| 4cbc107d1d | |||
| 5bd8f3e6ca | |||
| 5acb536281 | |||
| bbd554a426 |
4
.gitmodules
vendored
Normal file
4
.gitmodules
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
[submodule "web/frontend"]
|
||||
path = web/frontend
|
||||
url = https://gitea.kmux.cn/zhilv/wk-frontend
|
||||
branch = main
|
||||
@@ -7,6 +7,14 @@
|
||||
- 获取网课记录
|
||||
- 学习接口
|
||||
|
||||
|
||||
|
||||
### 拉取代码
|
||||
|
||||
```shell
|
||||
git clone --recurse-submodules https://gitea.kmux.cn/zhilv/wk-backend
|
||||
```
|
||||
|
||||
### 代码构建
|
||||
|
||||
**推荐使用 [Taskfile](https://taskfile.dev/) 进行项目构建**
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
2
web/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
frontend
|
||||
dist
|
||||
|
||||
1
web/frontend
Submodule
1
web/frontend
Submodule
Submodule web/frontend added at a061123e36
Reference in New Issue
Block a user