浏览代码

正在添加 Web 设置

Signed-off-by: 716 <[email protected]>
716 3 年之前
父节点
当前提交
dc9273ed7b

+ 1 - 0
go.mod

@@ -87,6 +87,7 @@ require (
 	github.com/go-playground/validator/v10 v10.10.0 // indirect
 	github.com/golang/protobuf v1.5.2 // indirect
 	github.com/golang/snappy v0.0.3 // indirect
+	github.com/google/uuid v1.3.0 // indirect
 	github.com/hashicorp/errwrap v1.0.0 // indirect
 	github.com/hashicorp/go-multierror v1.1.0 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect

+ 2 - 0
go.sum

@@ -235,6 +235,8 @@ github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OI
 github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
 github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
+github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
+github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
 github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=

+ 10 - 0
internal/backend/backend.go

@@ -1 +1,11 @@
 package backend
+
+import (
+	"github.com/google/uuid"
+)
+
+// GenerateAccessToken 生成随机的 AccessToken
+func GenerateAccessToken() string {
+	u4 := uuid.New()
+	return u4.String()
+}

+ 1 - 0
internal/backend/global_value.go

@@ -0,0 +1 @@
+package backend

+ 21 - 0
internal/backend/middle/auth.go

@@ -0,0 +1,21 @@
+package middle
+
+import (
+	"github.com/allanpk716/ChineseSubFinder/internal/types/backend"
+	"github.com/gin-gonic/gin"
+	"net/http"
+)
+
+func CheckAuth() gin.HandlerFunc {
+
+	return func(context *gin.Context) {
+		authHeader := context.Request.Header.Get("AccessToken")
+		if authHeader != "123456" {
+			context.JSON(http.StatusUnauthorized, backend.ReplyCheckAuth{Message: "Need Login!"})
+			context.Abort()
+			return
+		}
+		// 向下传递消息
+		context.Next()
+	}
+}

+ 0 - 1
internal/backend/routers/api_v1/api_v1.go

@@ -1 +0,0 @@
-package api_v1

+ 35 - 0
internal/backend/routers/handler_v1/handler_v1.go

@@ -0,0 +1,35 @@
+package handler_v1
+
+import "github.com/gin-gonic/gin"
+
+func PostLoginHandler(c *gin.Context) {
+
+}
+
+func PostChangePwdHandler(c *gin.Context) {
+
+}
+
+func GetSettingsHandler(c *gin.Context) {
+
+}
+
+func PatchSettingsHandler(c *gin.Context) {
+
+}
+
+func PostCheckProxyHandler(c *gin.Context) {
+
+}
+
+func PostCheckPathHandler(c *gin.Context) {
+
+}
+
+func PostJobStartHandler(c *gin.Context) {
+
+}
+
+func PostJobStopHandler(c *gin.Context) {
+
+}

+ 22 - 6
internal/backend/routers/router_v1/router_v1.go

@@ -1,13 +1,29 @@
 package router_v1
 
-import "github.com/gin-gonic/gin"
+import (
+	"github.com/allanpk716/ChineseSubFinder/internal/backend/middle"
+	"github.com/allanpk716/ChineseSubFinder/internal/backend/routers/handler_v1"
+	"github.com/gin-gonic/gin"
+)
 
 func GetRouters(router *gin.Engine) *gin.RouterGroup {
+
+	router.Use(middle.CheckAuth())
 	v1 := router.Group("/v1")
-	//{
-	//	v1.POST("/login", loginEndpoint)
-	//	v1.POST("/submit", submitEndpoint)
-	//	v1.POST("/read", readEndpoint)
-	//}
+	{
+		v1.POST("/login", handler_v1.PostLoginHandler)
+
+		v1.POST("/change-pwd", handler_v1.PostChangePwdHandler)
+
+		v1.GET("/settings", handler_v1.GetSettingsHandler)
+		v1.PATCH("/settings", handler_v1.PatchSettingsHandler)
+
+		v1.POST("/check-proxy", handler_v1.PostCheckProxyHandler)
+
+		v1.POST("/check-path", handler_v1.PostCheckPathHandler)
+
+		v1.POST("/jobs/start", handler_v1.PostJobStartHandler)
+		v1.POST("/jobs/stop", handler_v1.PostJobStopHandler)
+	}
 	return v1
 }

+ 9 - 0
internal/models/user_info.go

@@ -0,0 +1,9 @@
+package models
+
+import "gorm.io/gorm"
+
+type UserInfo struct {
+	gorm.Model
+	Username string `json:"username"` // 用户名
+	Password string `json:"password"` // 密码
+}

+ 5 - 0
internal/types/backend/reply_check_auth.go

@@ -0,0 +1,5 @@
+package backend
+
+type ReplyCheckAuth struct {
+	Message string `json:"message"`
+}

+ 5 - 0
internal/types/backend/reply_login.go

@@ -0,0 +1,5 @@
+package backend
+
+type ReplyLogin struct {
+	AccessToken string `json:"access_token"` // 登录成功后返回令牌
+}

+ 1 - 0
internal/types/backend/reply_system_info.go

@@ -0,0 +1 @@
+package backend

+ 1 - 0
internal/types/backend/reply_system_status.go

@@ -0,0 +1 @@
+package backend