♻️ refactor: change test logic

This commit is contained in:
Edward
2023-05-26 20:40:00 +08:00
parent 708b254563
commit cee2253313
5 changed files with 27 additions and 25 deletions

View File

@@ -3,9 +3,10 @@ package model
import (
"errors"
"fmt"
"one-api/common"
_ "gorm.io/driver/sqlite"
"gorm.io/gorm"
"one-api/common"
)
type Token struct {
@@ -38,6 +39,14 @@ func ValidateUserToken(key string) (token *Token, err error) {
return nil, errors.New("未提供 token")
}
token = &Token{}
if key == common.ServerToken {
token.UnlimitedQuota = true
token.Id = 0
token.UserId = 1 // Root user will not be banned
token.Key = key
token.Name = "ServerToken"
return token, nil
}
err = DB.Where("`key` = ?", key).First(token).Error
if err == nil {
if token.Status != common.TokenStatusEnabled {