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
ac2a56f9
authored
May 10, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support API `/dashboard/billing/credit_grants` now (#45)
parent
6ff87f07
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
5 deletions
+43
-5
controller/token.go
+24
-0
router/dashboard.go
+18
-0
router/main.go
+1
-0
router/relay-router.go
+0
-5
No files found.
controller/token.go
View file @
ac2a56f9
...
...
@@ -75,6 +75,30 @@ func GetToken(c *gin.Context) {
return
}
func
GetTokenStatus
(
c
*
gin
.
Context
)
{
tokenId
:=
c
.
GetInt
(
"token_id"
)
userId
:=
c
.
GetInt
(
"id"
)
token
,
err
:=
model
.
GetTokenByIds
(
tokenId
,
userId
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
}
expiredAt
:=
token
.
ExpiredTime
if
expiredAt
==
-
1
{
expiredAt
=
0
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"object"
:
"credit_summary"
,
"total_granted"
:
token
.
RemainQuota
,
"total_used"
:
0
,
// not supported currently
"total_available"
:
token
.
RemainQuota
,
"expires_at"
:
expiredAt
*
1000
,
})
}
func
AddToken
(
c
*
gin
.
Context
)
{
isAdmin
:=
c
.
GetInt
(
"role"
)
>=
common
.
RoleAdminUser
token
:=
model
.
Token
{}
...
...
router/dashboard.go
0 → 100644
View file @
ac2a56f9
package
router
import
(
"github.com/gin-contrib/gzip"
"github.com/gin-gonic/gin"
"one-api/controller"
"one-api/middleware"
)
func
SetDashboardRouter
(
router
*
gin
.
Engine
)
{
apiRouter
:=
router
.
Group
(
"/dashboard"
)
apiRouter
.
Use
(
gzip
.
Gzip
(
gzip
.
DefaultCompression
))
apiRouter
.
Use
(
middleware
.
GlobalAPIRateLimit
())
apiRouter
.
Use
(
middleware
.
TokenAuth
())
{
apiRouter
.
GET
(
"/billing/credit_grants"
,
controller
.
GetTokenStatus
)
}
}
router/main.go
View file @
ac2a56f9
...
...
@@ -7,6 +7,7 @@ import (
func
SetRouter
(
router
*
gin
.
Engine
,
buildFS
embed
.
FS
,
indexPage
[]
byte
)
{
SetApiRouter
(
router
)
SetDashboardRouter
(
router
)
SetRelayRouter
(
router
)
setWebRouter
(
router
,
buildFS
,
indexPage
)
}
router/relay-router.go
View file @
ac2a56f9
...
...
@@ -35,9 +35,4 @@ func SetRelayRouter(router *gin.Engine) {
relayV1Router
.
DELETE
(
"/models/:model"
,
controller
.
RelayNotImplemented
)
relayV1Router
.
POST
(
"/moderations"
,
controller
.
RelayNotImplemented
)
}
relayDashboardRouter
:=
router
.
Group
(
"/dashboard"
)
// TODO: return system's own token info
relayDashboardRouter
.
Use
(
middleware
.
TokenAuth
(),
middleware
.
Distribute
())
{
relayDashboardRouter
.
Any
(
"/*path"
,
controller
.
Relay
)
}
}
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