e6956aa001
- React frontend with route-level code splitting - Backend rebranded from Baihu to TaskPool - DB brand migration script and local compatibility
41 lines
892 B
Go
41 lines
892 B
Go
package middleware
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/engigu/taskpool/internal/constant"
|
|
"github.com/engigu/taskpool/internal/services"
|
|
"github.com/engigu/taskpool/internal/utils"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// NotifyTokenAuth 通知 Token 认证中间件
|
|
func NotifyTokenAuth() gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
token := c.GetHeader("notify-token")
|
|
if token == "" {
|
|
utils.Unauthorized(c, "缺少通知 Token")
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
// 从 settings 表读取配置的通知 Token
|
|
settingsService := services.NewSettingsService()
|
|
savedToken := settingsService.Get(constant.SectionNotify, constant.KeyNotifyToken)
|
|
|
|
if savedToken == "" {
|
|
utils.Unauthorized(c, "通知 Token 未配置")
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
if !strings.EqualFold(token, savedToken) {
|
|
utils.Unauthorized(c, "通知 Token 无效")
|
|
c.Abort()
|
|
return
|
|
}
|
|
|
|
c.Next()
|
|
}
|
|
}
|