Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4b5266eb
authored
Feb 22, 2024
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 优化令牌无效提示
parent
0ae99986
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
2 deletions
+6
-2
model/token.go
+6
-2
No files found.
model/token.go
View file @
4b5266eb
...
...
@@ -47,7 +47,9 @@ func ValidateUserToken(key string) (token *Token, err error) {
token
,
err
=
CacheGetTokenByKey
(
key
)
if
err
==
nil
{
if
token
.
Status
==
common
.
TokenStatusExhausted
{
return
nil
,
errors
.
New
(
"该令牌额度已用尽 token.Status == common.TokenStatusExhausted "
+
key
)
keyPrefix
:=
key
[
:
3
]
keySuffix
:=
key
[
len
(
key
)
-
3
:
]
return
nil
,
errors
.
New
(
"该令牌额度已用尽 TokenStatusExhausted[sk-"
+
keyPrefix
+
"***"
+
keySuffix
+
"]"
)
}
else
if
token
.
Status
==
common
.
TokenStatusExpired
{
return
nil
,
errors
.
New
(
"该令牌已过期"
)
}
...
...
@@ -73,7 +75,9 @@ func ValidateUserToken(key string) (token *Token, err error) {
common
.
SysError
(
"failed to update token status"
+
err
.
Error
())
}
}
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"%s 该令牌额度已用尽 !token.UnlimitedQuota && token.RemainQuota = %d"
,
token
.
Key
,
token
.
RemainQuota
))
keyPrefix
:=
key
[
:
3
]
keySuffix
:=
key
[
len
(
key
)
-
3
:
]
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"[sk-%s***%s] 该令牌额度已用尽 !token.UnlimitedQuota && token.RemainQuota = %d"
,
keyPrefix
,
keySuffix
,
token
.
RemainQuota
))
}
return
token
,
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment