kefu/middleware/kefu_expire.go

36 lines
940 B
Go
Raw Permalink Normal View History

2024-12-10 02:50:12 +00:00
package middleware
import (
"fmt"
"github.com/gin-gonic/gin"
"kefu/models"
"kefu/types"
"time"
)
//获取个人设置的OpenAI KEY中间件
func CheckKefuExpireByEntid(c *gin.Context) {
entId := c.Param("entId")
kefuInfo := models.FindUserByUid(entId)
if kefuInfo.ID == 0 {
c.JSON(200, gin.H{
"code": types.ApiCode.ACCOUNT_NO_EXIST,
"msg": types.ApiCode.GetMessage(types.ApiCode.ACCOUNT_NO_EXIST),
})
c.Abort()
return
}
nowSecond := time.Now().Unix()
expireSecond := kefuInfo.ExpiredAt.Unix()
if models.FindConfig("KefuExpired") == "on" && expireSecond < nowSecond {
logContent := fmt.Sprintf("'%s'账户过期:%d,访问时间:%d", kefuInfo.Name, expireSecond, nowSecond)
go models.CreateFlyLog(kefuInfo.EntId, c.ClientIP(), logContent, "user")
c.JSON(200, gin.H{
"code": types.ApiCode.ACCOUNT_EXPIRED,
"msg": types.ApiCode.GetMessage(types.ApiCode.ACCOUNT_EXPIRED),
})
c.Abort()
return
}
}