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
38c5e0e9
authored
Jul 14, 2025
by
Xyfacai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: format api page query and err result
parent
3338b1f5
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
236 additions
and
650 deletions
+236
-650
common/gin.go
+23
-0
common/page_info.go
+31
-11
controller/channel-billing.go
+6
-17
controller/channel-test.go
+3
-12
controller/channel.go
+26
-89
controller/github.go
+8
-22
controller/linuxdo.go
+4
-16
controller/log.go
+16
-61
controller/midjourney.go
+12
-40
controller/misc.go
+3
-12
controller/oidc.go
+4
-16
controller/option.go
+1
-4
controller/redemption.go
+22
-80
controller/task.go
+13
-42
controller/token.go
+19
-72
controller/usedata.go
+5
-9
controller/user.go
+35
-137
controller/wechat.go
+5
-10
No files found.
common/gin.go
View file @
38c5e0e9
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"bytes"
"bytes"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"io"
"io"
"net/http"
"one-api/constant"
"one-api/constant"
"strings"
"strings"
"time"
"time"
...
@@ -86,3 +87,25 @@ func GetContextKeyType[T any](c *gin.Context, key constant.ContextKey) (T, bool)
...
@@ -86,3 +87,25 @@ func GetContextKeyType[T any](c *gin.Context, key constant.ContextKey) (T, bool)
var
t
T
var
t
T
return
t
,
false
return
t
,
false
}
}
func
ApiError
(
c
*
gin
.
Context
,
err
error
)
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
(),
})
}
func
ApiErrorMsg
(
c
*
gin
.
Context
,
msg
string
)
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
msg
,
})
}
func
ApiSuccess
(
c
*
gin
.
Context
,
data
any
)
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
true
,
"message"
:
""
,
"data"
:
data
,
})
}
common/page_info.go
View file @
38c5e0e9
package
common
package
common
import
(
import
(
"github.com/gin-gonic/gin"
"strconv"
"strconv"
"github.com/gin-gonic/gin"
)
)
type
PageInfo
struct
{
type
PageInfo
struct
{
Page
int
`json:"page"`
// page num 页码
Page
int
`json:"page"`
// page num 页码
PageSize
int
`json:"page_size"`
// page size 页大小
PageSize
int
`json:"page_size"`
// page size 页大小
StartTimestamp
int64
`json:"start_timestamp"`
// 秒级
EndTimestamp
int64
`json:"end_timestamp"`
// 秒级
Total
int
`json:"total"`
// 总条数,后设置
Total
int
`json:"total"`
// 总条数,后设置
Items
any
`json:"items"`
// 数据,后设置
Items
any
`json:"items"`
// 数据,后设置
...
@@ -39,11 +38,14 @@ func (p *PageInfo) SetItems(items any) {
...
@@ -39,11 +38,14 @@ func (p *PageInfo) SetItems(items any) {
p
.
Items
=
items
p
.
Items
=
items
}
}
func
GetPageQuery
(
c
*
gin
.
Context
)
(
*
PageInfo
,
error
)
{
func
GetPageQuery
(
c
*
gin
.
Context
)
*
PageInfo
{
pageInfo
:=
&
PageInfo
{}
pageInfo
:=
&
PageInfo
{}
err
:=
c
.
BindQuery
(
pageInfo
)
// 手动获取并处理每个参数
if
err
!=
nil
{
if
page
,
err
:=
strconv
.
Atoi
(
c
.
Query
(
"page"
));
err
==
nil
{
return
nil
,
err
pageInfo
.
Page
=
page
}
if
pageSize
,
err
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
));
err
==
nil
{
pageInfo
.
PageSize
=
pageSize
}
}
if
pageInfo
.
Page
<
1
{
if
pageInfo
.
Page
<
1
{
// 兼容
// 兼容
...
@@ -56,7 +58,25 @@ func GetPageQuery(c *gin.Context) (*PageInfo, error) {
...
@@ -56,7 +58,25 @@ func GetPageQuery(c *gin.Context) (*PageInfo, error) {
}
}
if
pageInfo
.
PageSize
==
0
{
if
pageInfo
.
PageSize
==
0
{
pageInfo
.
PageSize
=
ItemsPerPage
// 兼容
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"ps"
))
if
pageSize
!=
0
{
pageInfo
.
PageSize
=
pageSize
}
if
pageInfo
.
PageSize
==
0
{
pageSize
,
_
=
strconv
.
Atoi
(
c
.
Query
(
"size"
))
// token page
if
pageSize
!=
0
{
pageInfo
.
PageSize
=
pageSize
}
}
if
pageInfo
.
PageSize
==
0
{
pageInfo
.
PageSize
=
ItemsPerPage
}
}
}
return
pageInfo
,
nil
if
pageInfo
.
PageSize
>
100
{
pageInfo
.
PageSize
=
100
}
return
pageInfo
}
}
controller/channel-billing.go
View file @
38c5e0e9
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"github.com/shopspring/decimal"
"io"
"io"
"net/http"
"net/http"
"one-api/common"
"one-api/common"
...
@@ -16,6 +15,8 @@ import (
...
@@ -16,6 +15,8 @@ import (
"strconv"
"strconv"
"time"
"time"
"github.com/shopspring/decimal"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
)
)
...
@@ -410,18 +411,12 @@ func updateChannelBalance(channel *model.Channel) (float64, error) {
...
@@ -410,18 +411,12 @@ func updateChannelBalance(channel *model.Channel) (float64, error) {
func
UpdateChannelBalance
(
c
*
gin
.
Context
)
{
func
UpdateChannelBalance
(
c
*
gin
.
Context
)
{
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
channel
,
err
:=
model
.
CacheGetChannel
(
id
)
channel
,
err
:=
model
.
CacheGetChannel
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
if
channel
.
ChannelInfo
.
IsMultiKey
{
if
channel
.
ChannelInfo
.
IsMultiKey
{
...
@@ -433,10 +428,7 @@ func UpdateChannelBalance(c *gin.Context) {
...
@@ -433,10 +428,7 @@ func UpdateChannelBalance(c *gin.Context) {
}
}
balance
,
err
:=
updateChannelBalance
(
channel
)
balance
,
err
:=
updateChannelBalance
(
channel
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -480,10 +472,7 @@ func UpdateAllChannelsBalance(c *gin.Context) {
...
@@ -480,10 +472,7 @@ func UpdateAllChannelsBalance(c *gin.Context) {
// TODO: make it async
// TODO: make it async
err
:=
updateAllChannelsBalance
()
err
:=
updateAllChannelsBalance
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
controller/channel-test.go
View file @
38c5e0e9
...
@@ -306,18 +306,12 @@ func buildTestRequest(model string) *dto.GeneralOpenAIRequest {
...
@@ -306,18 +306,12 @@ func buildTestRequest(model string) *dto.GeneralOpenAIRequest {
func
TestChannel
(
c
*
gin
.
Context
)
{
func
TestChannel
(
c
*
gin
.
Context
)
{
channelId
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
channelId
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
channel
,
err
:=
model
.
CacheGetChannel
(
channelId
)
channel
,
err
:=
model
.
CacheGetChannel
(
channelId
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
//defer func() {
//defer func() {
...
@@ -431,10 +425,7 @@ func testAllChannels(notify bool) error {
...
@@ -431,10 +425,7 @@ func testAllChannels(notify bool) error {
func
TestAllChannels
(
c
*
gin
.
Context
)
{
func
TestAllChannels
(
c
*
gin
.
Context
)
{
err
:=
testAllChannels
(
true
)
err
:=
testAllChannels
(
true
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
controller/channel.go
View file @
38c5e0e9
...
@@ -53,14 +53,7 @@ func parseStatusFilter(statusParam string) int {
...
@@ -53,14 +53,7 @@ func parseStatusFilter(statusParam string) int {
}
}
func
GetAllChannels
(
c
*
gin
.
Context
)
{
func
GetAllChannels
(
c
*
gin
.
Context
)
{
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
if
p
<
1
{
p
=
1
}
if
pageSize
<
1
{
pageSize
=
common
.
ItemsPerPage
}
channelData
:=
make
([]
*
model
.
Channel
,
0
)
channelData
:=
make
([]
*
model
.
Channel
,
0
)
idSort
,
_
:=
strconv
.
ParseBool
(
c
.
Query
(
"id_sort"
))
idSort
,
_
:=
strconv
.
ParseBool
(
c
.
Query
(
"id_sort"
))
enableTagMode
,
_
:=
strconv
.
ParseBool
(
c
.
Query
(
"tag_mode"
))
enableTagMode
,
_
:=
strconv
.
ParseBool
(
c
.
Query
(
"tag_mode"
))
...
@@ -79,7 +72,7 @@ func GetAllChannels(c *gin.Context) {
...
@@ -79,7 +72,7 @@ func GetAllChannels(c *gin.Context) {
var
total
int64
var
total
int64
if
enableTagMode
{
if
enableTagMode
{
tags
,
err
:=
model
.
GetPaginatedTags
(
(
p
-
1
)
*
pageSize
,
pageSize
)
tags
,
err
:=
model
.
GetPaginatedTags
(
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
()
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
()})
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
()})
return
return
...
@@ -126,7 +119,7 @@ func GetAllChannels(c *gin.Context) {
...
@@ -126,7 +119,7 @@ func GetAllChannels(c *gin.Context) {
order
=
"id desc"
order
=
"id desc"
}
}
err
:=
baseQuery
.
Order
(
order
)
.
Limit
(
page
Size
)
.
Offset
((
p
-
1
)
*
pageSize
)
.
Omit
(
"key"
)
.
Find
(
&
channelData
)
.
Error
err
:=
baseQuery
.
Order
(
order
)
.
Limit
(
page
Info
.
GetPageSize
())
.
Offset
(
pageInfo
.
GetStartIdx
()
)
.
Omit
(
"key"
)
.
Find
(
&
channelData
)
.
Error
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
()})
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
()})
return
return
...
@@ -148,17 +141,12 @@ func GetAllChannels(c *gin.Context) {
...
@@ -148,17 +141,12 @@ func GetAllChannels(c *gin.Context) {
for
_
,
r
:=
range
results
{
for
_
,
r
:=
range
results
{
typeCounts
[
r
.
Type
]
=
r
.
Count
typeCounts
[
r
.
Type
]
=
r
.
Count
}
}
common
.
ApiSuccess
(
c
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"items"
:
channelData
,
"success"
:
true
,
"total"
:
total
,
"message"
:
""
,
"page"
:
pageInfo
.
GetPage
(),
"data"
:
gin
.
H
{
"page_size"
:
pageInfo
.
GetPageSize
(),
"items"
:
channelData
,
"type_counts"
:
typeCounts
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
"type_counts"
:
typeCounts
,
},
})
})
return
return
}
}
...
@@ -166,19 +154,13 @@ func GetAllChannels(c *gin.Context) {
...
@@ -166,19 +154,13 @@ func GetAllChannels(c *gin.Context) {
func
FetchUpstreamModels
(
c
*
gin
.
Context
)
{
func
FetchUpstreamModels
(
c
*
gin
.
Context
)
{
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
channel
,
err
:=
model
.
GetChannelById
(
id
,
true
)
channel
,
err
:=
model
.
GetChannelById
(
id
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
@@ -195,10 +177,7 @@ func FetchUpstreamModels(c *gin.Context) {
...
@@ -195,10 +177,7 @@ func FetchUpstreamModels(c *gin.Context) {
}
}
body
,
err
:=
GetResponseBody
(
"GET"
,
url
,
channel
,
GetAuthHeader
(
channel
.
Key
))
body
,
err
:=
GetResponseBody
(
"GET"
,
url
,
channel
,
GetAuthHeader
(
channel
.
Key
))
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
@@ -230,10 +209,7 @@ func FetchUpstreamModels(c *gin.Context) {
...
@@ -230,10 +209,7 @@ func FetchUpstreamModels(c *gin.Context) {
func
FixChannelsAbilities
(
c
*
gin
.
Context
)
{
func
FixChannelsAbilities
(
c
*
gin
.
Context
)
{
success
,
fails
,
err
:=
model
.
FixAbility
()
success
,
fails
,
err
:=
model
.
FixAbility
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -358,18 +334,12 @@ func SearchChannels(c *gin.Context) {
...
@@ -358,18 +334,12 @@ func SearchChannels(c *gin.Context) {
func
GetChannel
(
c
*
gin
.
Context
)
{
func
GetChannel
(
c
*
gin
.
Context
)
{
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
channel
,
err
:=
model
.
GetChannelById
(
id
,
false
)
channel
,
err
:=
model
.
GetChannelById
(
id
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -422,10 +392,7 @@ func AddChannel(c *gin.Context) {
...
@@ -422,10 +392,7 @@ func AddChannel(c *gin.Context) {
addChannelRequest
:=
AddChannelRequest
{}
addChannelRequest
:=
AddChannelRequest
{}
err
:=
c
.
ShouldBindJSON
(
&
addChannelRequest
)
err
:=
c
.
ShouldBindJSON
(
&
addChannelRequest
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
@@ -547,10 +514,7 @@ func AddChannel(c *gin.Context) {
...
@@ -547,10 +514,7 @@ func AddChannel(c *gin.Context) {
}
}
err
=
model
.
BatchInsertChannels
(
channels
)
err
=
model
.
BatchInsertChannels
(
channels
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -565,10 +529,7 @@ func DeleteChannel(c *gin.Context) {
...
@@ -565,10 +529,7 @@ func DeleteChannel(c *gin.Context) {
channel
:=
model
.
Channel
{
Id
:
id
}
channel
:=
model
.
Channel
{
Id
:
id
}
err
:=
channel
.
Delete
()
err
:=
channel
.
Delete
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -581,10 +542,7 @@ func DeleteChannel(c *gin.Context) {
...
@@ -581,10 +542,7 @@ func DeleteChannel(c *gin.Context) {
func
DeleteDisabledChannel
(
c
*
gin
.
Context
)
{
func
DeleteDisabledChannel
(
c
*
gin
.
Context
)
{
rows
,
err
:=
model
.
DeleteDisabledChannel
()
rows
,
err
:=
model
.
DeleteDisabledChannel
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -617,10 +575,7 @@ func DisableTagChannels(c *gin.Context) {
...
@@ -617,10 +575,7 @@ func DisableTagChannels(c *gin.Context) {
}
}
err
=
model
.
DisableChannelByTag
(
channelTag
.
Tag
)
err
=
model
.
DisableChannelByTag
(
channelTag
.
Tag
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -642,10 +597,7 @@ func EnableTagChannels(c *gin.Context) {
...
@@ -642,10 +597,7 @@ func EnableTagChannels(c *gin.Context) {
}
}
err
=
model
.
EnableChannelByTag
(
channelTag
.
Tag
)
err
=
model
.
EnableChannelByTag
(
channelTag
.
Tag
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -674,10 +626,7 @@ func EditTagChannels(c *gin.Context) {
...
@@ -674,10 +626,7 @@ func EditTagChannels(c *gin.Context) {
}
}
err
=
model
.
EditChannelByTag
(
channelTag
.
Tag
,
channelTag
.
NewTag
,
channelTag
.
ModelMapping
,
channelTag
.
Models
,
channelTag
.
Groups
,
channelTag
.
Priority
,
channelTag
.
Weight
)
err
=
model
.
EditChannelByTag
(
channelTag
.
Tag
,
channelTag
.
NewTag
,
channelTag
.
ModelMapping
,
channelTag
.
Models
,
channelTag
.
Groups
,
channelTag
.
Priority
,
channelTag
.
Weight
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -704,10 +653,7 @@ func DeleteChannelBatch(c *gin.Context) {
...
@@ -704,10 +653,7 @@ func DeleteChannelBatch(c *gin.Context) {
}
}
err
=
model
.
BatchDeleteChannels
(
channelBatch
.
Ids
)
err
=
model
.
BatchDeleteChannels
(
channelBatch
.
Ids
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -727,10 +673,7 @@ func UpdateChannel(c *gin.Context) {
...
@@ -727,10 +673,7 @@ func UpdateChannel(c *gin.Context) {
channel
:=
PatchChannel
{}
channel
:=
PatchChannel
{}
err
:=
c
.
ShouldBindJSON
(
&
channel
)
err
:=
c
.
ShouldBindJSON
(
&
channel
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
err
=
channel
.
ValidateSettings
()
err
=
channel
.
ValidateSettings
()
...
@@ -781,10 +724,7 @@ func UpdateChannel(c *gin.Context) {
...
@@ -781,10 +724,7 @@ func UpdateChannel(c *gin.Context) {
}
}
err
=
channel
.
Update
()
err
=
channel
.
Update
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
channel
.
Key
=
""
channel
.
Key
=
""
...
@@ -889,10 +829,7 @@ func BatchSetChannelTag(c *gin.Context) {
...
@@ -889,10 +829,7 @@ func BatchSetChannelTag(c *gin.Context) {
}
}
err
=
model
.
BatchSetChannelTag
(
channelBatch
.
Ids
,
channelBatch
.
Tag
)
err
=
model
.
BatchSetChannelTag
(
channelBatch
.
Ids
,
channelBatch
.
Tag
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
controller/github.go
View file @
38c5e0e9
...
@@ -5,13 +5,14 @@ import (
...
@@ -5,13 +5,14 @@ import (
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"net/http"
"net/http"
"one-api/common"
"one-api/common"
"one-api/model"
"one-api/model"
"strconv"
"strconv"
"time"
"time"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
)
type
GitHubOAuthResponse
struct
{
type
GitHubOAuthResponse
struct
{
...
@@ -103,10 +104,7 @@ func GitHubOAuth(c *gin.Context) {
...
@@ -103,10 +104,7 @@ func GitHubOAuth(c *gin.Context) {
code
:=
c
.
Query
(
"code"
)
code
:=
c
.
Query
(
"code"
)
githubUser
,
err
:=
getGitHubUserInfoByCode
(
code
)
githubUser
,
err
:=
getGitHubUserInfoByCode
(
code
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
user
:=
model
.
User
{
user
:=
model
.
User
{
...
@@ -185,10 +183,7 @@ func GitHubBind(c *gin.Context) {
...
@@ -185,10 +183,7 @@ func GitHubBind(c *gin.Context) {
code
:=
c
.
Query
(
"code"
)
code
:=
c
.
Query
(
"code"
)
githubUser
,
err
:=
getGitHubUserInfoByCode
(
code
)
githubUser
,
err
:=
getGitHubUserInfoByCode
(
code
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
user
:=
model
.
User
{
user
:=
model
.
User
{
...
@@ -207,19 +202,13 @@ func GitHubBind(c *gin.Context) {
...
@@ -207,19 +202,13 @@ func GitHubBind(c *gin.Context) {
user
.
Id
=
id
.
(
int
)
user
.
Id
=
id
.
(
int
)
err
=
user
.
FillUserById
()
err
=
user
.
FillUserById
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
user
.
GitHubId
=
githubUser
.
Login
user
.
GitHubId
=
githubUser
.
Login
err
=
user
.
Update
(
false
)
err
=
user
.
Update
(
false
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -239,10 +228,7 @@ func GenerateOAuthCode(c *gin.Context) {
...
@@ -239,10 +228,7 @@ func GenerateOAuthCode(c *gin.Context) {
session
.
Set
(
"oauth_state"
,
state
)
session
.
Set
(
"oauth_state"
,
state
)
err
:=
session
.
Save
()
err
:=
session
.
Save
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
controller/linuxdo.go
View file @
38c5e0e9
...
@@ -38,10 +38,7 @@ func LinuxDoBind(c *gin.Context) {
...
@@ -38,10 +38,7 @@ func LinuxDoBind(c *gin.Context) {
code
:=
c
.
Query
(
"code"
)
code
:=
c
.
Query
(
"code"
)
linuxdoUser
,
err
:=
getLinuxdoUserInfoByCode
(
code
,
c
)
linuxdoUser
,
err
:=
getLinuxdoUserInfoByCode
(
code
,
c
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
@@ -63,20 +60,14 @@ func LinuxDoBind(c *gin.Context) {
...
@@ -63,20 +60,14 @@ func LinuxDoBind(c *gin.Context) {
err
=
user
.
FillUserById
()
err
=
user
.
FillUserById
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
user
.
LinuxDOId
=
strconv
.
Itoa
(
linuxdoUser
.
Id
)
user
.
LinuxDOId
=
strconv
.
Itoa
(
linuxdoUser
.
Id
)
err
=
user
.
Update
(
false
)
err
=
user
.
Update
(
false
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
@@ -202,10 +193,7 @@ func LinuxdoOAuth(c *gin.Context) {
...
@@ -202,10 +193,7 @@ func LinuxdoOAuth(c *gin.Context) {
code
:=
c
.
Query
(
"code"
)
code
:=
c
.
Query
(
"code"
)
linuxdoUser
,
err
:=
getLinuxdoUserInfoByCode
(
code
,
c
)
linuxdoUser
,
err
:=
getLinuxdoUserInfoByCode
(
code
,
c
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
...
controller/log.go
View file @
38c5e0e9
...
@@ -10,14 +10,7 @@ import (
...
@@ -10,14 +10,7 @@ import (
)
)
func
GetAllLogs
(
c
*
gin
.
Context
)
{
func
GetAllLogs
(
c
*
gin
.
Context
)
{
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
if
p
<
1
{
p
=
1
}
if
pageSize
<
0
{
pageSize
=
common
.
ItemsPerPage
}
logType
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"type"
))
logType
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"type"
))
startTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"start_timestamp"
),
10
,
64
)
startTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"start_timestamp"
),
10
,
64
)
endTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"end_timestamp"
),
10
,
64
)
endTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"end_timestamp"
),
10
,
64
)
...
@@ -26,38 +19,19 @@ func GetAllLogs(c *gin.Context) {
...
@@ -26,38 +19,19 @@ func GetAllLogs(c *gin.Context) {
modelName
:=
c
.
Query
(
"model_name"
)
modelName
:=
c
.
Query
(
"model_name"
)
channel
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"channel"
))
channel
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"channel"
))
group
:=
c
.
Query
(
"group"
)
group
:=
c
.
Query
(
"group"
)
logs
,
total
,
err
:=
model
.
GetAllLogs
(
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
username
,
tokenName
,
(
p
-
1
)
*
pageSize
,
pageSize
,
channel
,
group
)
logs
,
total
,
err
:=
model
.
GetAllLogs
(
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
username
,
tokenName
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
()
,
channel
,
group
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
pageInfo
.
SetTotal
(
int
(
total
))
"success"
:
true
,
pageInfo
.
SetItems
(
logs
)
"message"
:
""
,
common
.
ApiSuccess
(
c
,
pageInfo
)
"data"
:
map
[
string
]
any
{
return
"items"
:
logs
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
},
})
}
}
func
GetUserLogs
(
c
*
gin
.
Context
)
{
func
GetUserLogs
(
c
*
gin
.
Context
)
{
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
if
p
<
1
{
p
=
1
}
if
pageSize
<
0
{
pageSize
=
common
.
ItemsPerPage
}
if
pageSize
>
100
{
pageSize
=
100
}
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
logType
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"type"
))
logType
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"type"
))
startTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"start_timestamp"
),
10
,
64
)
startTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"start_timestamp"
),
10
,
64
)
...
@@ -65,24 +39,14 @@ func GetUserLogs(c *gin.Context) {
...
@@ -65,24 +39,14 @@ func GetUserLogs(c *gin.Context) {
tokenName
:=
c
.
Query
(
"token_name"
)
tokenName
:=
c
.
Query
(
"token_name"
)
modelName
:=
c
.
Query
(
"model_name"
)
modelName
:=
c
.
Query
(
"model_name"
)
group
:=
c
.
Query
(
"group"
)
group
:=
c
.
Query
(
"group"
)
logs
,
total
,
err
:=
model
.
GetUserLogs
(
userId
,
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
tokenName
,
(
p
-
1
)
*
pageSize
,
pageSize
,
group
)
logs
,
total
,
err
:=
model
.
GetUserLogs
(
userId
,
logType
,
startTimestamp
,
endTimestamp
,
modelName
,
tokenName
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
()
,
group
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
pageInfo
.
SetTotal
(
int
(
total
))
"success"
:
true
,
pageInfo
.
SetItems
(
logs
)
"message"
:
""
,
common
.
ApiSuccess
(
c
,
pageInfo
)
"data"
:
map
[
string
]
any
{
"items"
:
logs
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
},
})
return
return
}
}
...
@@ -90,10 +54,7 @@ func SearchAllLogs(c *gin.Context) {
...
@@ -90,10 +54,7 @@ func SearchAllLogs(c *gin.Context) {
keyword
:=
c
.
Query
(
"keyword"
)
keyword
:=
c
.
Query
(
"keyword"
)
logs
,
err
:=
model
.
SearchAllLogs
(
keyword
)
logs
,
err
:=
model
.
SearchAllLogs
(
keyword
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -109,10 +70,7 @@ func SearchUserLogs(c *gin.Context) {
...
@@ -109,10 +70,7 @@ func SearchUserLogs(c *gin.Context) {
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
logs
,
err
:=
model
.
SearchUserLogs
(
userId
,
keyword
)
logs
,
err
:=
model
.
SearchUserLogs
(
userId
,
keyword
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -198,10 +156,7 @@ func DeleteHistoryLogs(c *gin.Context) {
...
@@ -198,10 +156,7 @@ func DeleteHistoryLogs(c *gin.Context) {
}
}
count
,
err
:=
model
.
DeleteOldLog
(
c
.
Request
.
Context
(),
targetTimestamp
,
100
)
count
,
err
:=
model
.
DeleteOldLog
(
c
.
Request
.
Context
(),
targetTimestamp
,
100
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
controller/midjourney.go
View file @
38c5e0e9
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"context"
"context"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/gin-gonic/gin"
"io"
"io"
"net/http"
"net/http"
"one-api/common"
"one-api/common"
...
@@ -13,8 +12,9 @@ import (
...
@@ -13,8 +12,9 @@ import (
"one-api/model"
"one-api/model"
"one-api/service"
"one-api/service"
"one-api/setting"
"one-api/setting"
"strconv"
"time"
"time"
"github.com/gin-gonic/gin"
)
)
func
UpdateMidjourneyTaskBulk
()
{
func
UpdateMidjourneyTaskBulk
()
{
...
@@ -213,14 +213,7 @@ func checkMjTaskNeedUpdate(oldTask *model.Midjourney, newTask dto.MidjourneyDto)
...
@@ -213,14 +213,7 @@ func checkMjTaskNeedUpdate(oldTask *model.Midjourney, newTask dto.MidjourneyDto)
}
}
func
GetAllMidjourney
(
c
*
gin
.
Context
)
{
func
GetAllMidjourney
(
c
*
gin
.
Context
)
{
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
if
p
<
1
{
p
=
1
}
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
if
pageSize
<=
0
{
pageSize
=
common
.
ItemsPerPage
}
// 解析其他查询参数
// 解析其他查询参数
queryParams
:=
model
.
TaskQueryParams
{
queryParams
:=
model
.
TaskQueryParams
{
...
@@ -230,7 +223,7 @@ func GetAllMidjourney(c *gin.Context) {
...
@@ -230,7 +223,7 @@ func GetAllMidjourney(c *gin.Context) {
EndTimestamp
:
c
.
Query
(
"end_timestamp"
),
EndTimestamp
:
c
.
Query
(
"end_timestamp"
),
}
}
items
:=
model
.
GetAllTasks
(
(
p
-
1
)
*
pageSize
,
pageSize
,
queryParams
)
items
:=
model
.
GetAllTasks
(
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
()
,
queryParams
)
total
:=
model
.
CountAllTasks
(
queryParams
)
total
:=
model
.
CountAllTasks
(
queryParams
)
if
setting
.
MjForwardUrlEnabled
{
if
setting
.
MjForwardUrlEnabled
{
...
@@ -239,27 +232,13 @@ func GetAllMidjourney(c *gin.Context) {
...
@@ -239,27 +232,13 @@ func GetAllMidjourney(c *gin.Context) {
items
[
i
]
=
midjourney
items
[
i
]
=
midjourney
}
}
}
}
c
.
JSON
(
200
,
gin
.
H
{
pageInfo
.
SetTotal
(
int
(
total
))
"success"
:
true
,
pageInfo
.
SetItems
(
items
)
"message"
:
""
,
common
.
ApiSuccess
(
c
,
pageInfo
)
"data"
:
gin
.
H
{
"items"
:
items
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
},
})
}
}
func
GetUserMidjourney
(
c
*
gin
.
Context
)
{
func
GetUserMidjourney
(
c
*
gin
.
Context
)
{
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
if
p
<
1
{
p
=
1
}
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
if
pageSize
<=
0
{
pageSize
=
common
.
ItemsPerPage
}
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
...
@@ -269,7 +248,7 @@ func GetUserMidjourney(c *gin.Context) {
...
@@ -269,7 +248,7 @@ func GetUserMidjourney(c *gin.Context) {
EndTimestamp
:
c
.
Query
(
"end_timestamp"
),
EndTimestamp
:
c
.
Query
(
"end_timestamp"
),
}
}
items
:=
model
.
GetAllUserTask
(
userId
,
(
p
-
1
)
*
pageSize
,
pageSize
,
queryParams
)
items
:=
model
.
GetAllUserTask
(
userId
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
()
,
queryParams
)
total
:=
model
.
CountAllUserTask
(
userId
,
queryParams
)
total
:=
model
.
CountAllUserTask
(
userId
,
queryParams
)
if
setting
.
MjForwardUrlEnabled
{
if
setting
.
MjForwardUrlEnabled
{
...
@@ -278,14 +257,7 @@ func GetUserMidjourney(c *gin.Context) {
...
@@ -278,14 +257,7 @@ func GetUserMidjourney(c *gin.Context) {
items
[
i
]
=
midjourney
items
[
i
]
=
midjourney
}
}
}
}
c
.
JSON
(
200
,
gin
.
H
{
pageInfo
.
SetTotal
(
int
(
total
))
"success"
:
true
,
pageInfo
.
SetItems
(
items
)
"message"
:
""
,
common
.
ApiSuccess
(
c
,
pageInfo
)
"data"
:
gin
.
H
{
"items"
:
items
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
},
})
}
}
controller/misc.go
View file @
38c5e0e9
...
@@ -214,10 +214,7 @@ func SendEmailVerification(c *gin.Context) {
...
@@ -214,10 +214,7 @@ func SendEmailVerification(c *gin.Context) {
"<p>验证码 %d 分钟内有效,如果不是本人操作,请忽略。</p>"
,
common
.
SystemName
,
code
,
common
.
VerificationValidMinutes
)
"<p>验证码 %d 分钟内有效,如果不是本人操作,请忽略。</p>"
,
common
.
SystemName
,
code
,
common
.
VerificationValidMinutes
)
err
:=
common
.
SendEmail
(
subject
,
email
,
content
)
err
:=
common
.
SendEmail
(
subject
,
email
,
content
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -253,10 +250,7 @@ func SendPasswordResetEmail(c *gin.Context) {
...
@@ -253,10 +250,7 @@ func SendPasswordResetEmail(c *gin.Context) {
"<p>重置链接 %d 分钟内有效,如果不是本人操作,请忽略。</p>"
,
common
.
SystemName
,
link
,
link
,
common
.
VerificationValidMinutes
)
"<p>重置链接 %d 分钟内有效,如果不是本人操作,请忽略。</p>"
,
common
.
SystemName
,
link
,
link
,
common
.
VerificationValidMinutes
)
err
:=
common
.
SendEmail
(
subject
,
email
,
content
)
err
:=
common
.
SendEmail
(
subject
,
email
,
content
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -291,10 +285,7 @@ func ResetPassword(c *gin.Context) {
...
@@ -291,10 +285,7 @@ func ResetPassword(c *gin.Context) {
password
:=
common
.
GenerateVerificationCode
(
12
)
password
:=
common
.
GenerateVerificationCode
(
12
)
err
=
model
.
ResetUserPasswordByEmail
(
req
.
Email
,
password
)
err
=
model
.
ResetUserPasswordByEmail
(
req
.
Email
,
password
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
common
.
DeleteKey
(
req
.
Email
,
common
.
PasswordResetPurpose
)
common
.
DeleteKey
(
req
.
Email
,
common
.
PasswordResetPurpose
)
...
...
controller/oidc.go
View file @
38c5e0e9
...
@@ -126,10 +126,7 @@ func OidcAuth(c *gin.Context) {
...
@@ -126,10 +126,7 @@ func OidcAuth(c *gin.Context) {
code
:=
c
.
Query
(
"code"
)
code
:=
c
.
Query
(
"code"
)
oidcUser
,
err
:=
getOidcUserInfoByCode
(
code
)
oidcUser
,
err
:=
getOidcUserInfoByCode
(
code
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
user
:=
model
.
User
{
user
:=
model
.
User
{
...
@@ -195,10 +192,7 @@ func OidcBind(c *gin.Context) {
...
@@ -195,10 +192,7 @@ func OidcBind(c *gin.Context) {
code
:=
c
.
Query
(
"code"
)
code
:=
c
.
Query
(
"code"
)
oidcUser
,
err
:=
getOidcUserInfoByCode
(
code
)
oidcUser
,
err
:=
getOidcUserInfoByCode
(
code
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
user
:=
model
.
User
{
user
:=
model
.
User
{
...
@@ -217,19 +211,13 @@ func OidcBind(c *gin.Context) {
...
@@ -217,19 +211,13 @@ func OidcBind(c *gin.Context) {
user
.
Id
=
id
.
(
int
)
user
.
Id
=
id
.
(
int
)
err
=
user
.
FillUserById
()
err
=
user
.
FillUserById
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
user
.
OidcId
=
oidcUser
.
OpenID
user
.
OidcId
=
oidcUser
.
OpenID
err
=
user
.
Update
(
false
)
err
=
user
.
Update
(
false
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
controller/option.go
View file @
38c5e0e9
...
@@ -160,10 +160,7 @@ func UpdateOption(c *gin.Context) {
...
@@ -160,10 +160,7 @@ func UpdateOption(c *gin.Context) {
}
}
err
=
model
.
UpdateOption
(
option
.
Key
,
option
.
Value
)
err
=
model
.
UpdateOption
(
option
.
Key
,
option
.
Value
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
controller/redemption.go
View file @
38c5e0e9
package
controller
package
controller
import
(
import
(
"errors"
"net/http"
"net/http"
"one-api/common"
"one-api/common"
"one-api/model"
"one-api/model"
"strconv"
"strconv"
"errors"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
)
)
func
GetAllRedemptions
(
c
*
gin
.
Context
)
{
func
GetAllRedemptions
(
c
*
gin
.
Context
)
{
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
redemptions
,
total
,
err
:=
model
.
GetAllRedemptions
(
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
())
if
p
<
0
{
p
=
0
}
if
pageSize
<
1
{
pageSize
=
common
.
ItemsPerPage
}
redemptions
,
total
,
err
:=
model
.
GetAllRedemptions
((
p
-
1
)
*
pageSize
,
pageSize
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
pageInfo
.
SetTotal
(
int
(
total
))
"success"
:
true
,
pageInfo
.
SetItems
(
redemptions
)
"message"
:
""
,
common
.
ApiSuccess
(
c
,
pageInfo
)
"data"
:
gin
.
H
{
"items"
:
redemptions
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
},
})
return
return
}
}
func
SearchRedemptions
(
c
*
gin
.
Context
)
{
func
SearchRedemptions
(
c
*
gin
.
Context
)
{
keyword
:=
c
.
Query
(
"keyword"
)
keyword
:=
c
.
Query
(
"keyword"
)
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
redemptions
,
total
,
err
:=
model
.
SearchRedemptions
(
keyword
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
())
if
p
<
0
{
p
=
0
}
if
pageSize
<
1
{
pageSize
=
common
.
ItemsPerPage
}
redemptions
,
total
,
err
:=
model
.
SearchRedemptions
(
keyword
,
(
p
-
1
)
*
pageSize
,
pageSize
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
pageInfo
.
SetTotal
(
int
(
total
))
"success"
:
true
,
pageInfo
.
SetItems
(
redemptions
)
"message"
:
""
,
common
.
ApiSuccess
(
c
,
pageInfo
)
"data"
:
gin
.
H
{
"items"
:
redemptions
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
},
})
return
return
}
}
func
GetRedemption
(
c
*
gin
.
Context
)
{
func
GetRedemption
(
c
*
gin
.
Context
)
{
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
redemption
,
err
:=
model
.
GetRedemptionById
(
id
)
redemption
,
err
:=
model
.
GetRedemptionById
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -100,10 +60,7 @@ func AddRedemption(c *gin.Context) {
...
@@ -100,10 +60,7 @@ func AddRedemption(c *gin.Context) {
redemption
:=
model
.
Redemption
{}
redemption
:=
model
.
Redemption
{}
err
:=
c
.
ShouldBindJSON
(
&
redemption
)
err
:=
c
.
ShouldBindJSON
(
&
redemption
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
if
len
(
redemption
.
Name
)
==
0
||
len
(
redemption
.
Name
)
>
20
{
if
len
(
redemption
.
Name
)
==
0
||
len
(
redemption
.
Name
)
>
20
{
...
@@ -165,10 +122,7 @@ func DeleteRedemption(c *gin.Context) {
...
@@ -165,10 +122,7 @@ func DeleteRedemption(c *gin.Context) {
id
,
_
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
_
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
err
:=
model
.
DeleteRedemptionById
(
id
)
err
:=
model
.
DeleteRedemptionById
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -183,18 +137,12 @@ func UpdateRedemption(c *gin.Context) {
...
@@ -183,18 +137,12 @@ func UpdateRedemption(c *gin.Context) {
redemption
:=
model
.
Redemption
{}
redemption
:=
model
.
Redemption
{}
err
:=
c
.
ShouldBindJSON
(
&
redemption
)
err
:=
c
.
ShouldBindJSON
(
&
redemption
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
cleanRedemption
,
err
:=
model
.
GetRedemptionById
(
redemption
.
Id
)
cleanRedemption
,
err
:=
model
.
GetRedemptionById
(
redemption
.
Id
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
if
statusOnly
==
""
{
if
statusOnly
==
""
{
...
@@ -212,10 +160,7 @@ func UpdateRedemption(c *gin.Context) {
...
@@ -212,10 +160,7 @@ func UpdateRedemption(c *gin.Context) {
}
}
err
=
cleanRedemption
.
Update
()
err
=
cleanRedemption
.
Update
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -229,16 +174,13 @@ func UpdateRedemption(c *gin.Context) {
...
@@ -229,16 +174,13 @@ func UpdateRedemption(c *gin.Context) {
func
DeleteInvalidRedemption
(
c
*
gin
.
Context
)
{
func
DeleteInvalidRedemption
(
c
*
gin
.
Context
)
{
rows
,
err
:=
model
.
DeleteInvalidRedemptions
()
rows
,
err
:=
model
.
DeleteInvalidRedemptions
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
true
,
"success"
:
true
,
"message"
:
""
,
"message"
:
""
,
"data"
:
rows
,
"data"
:
rows
,
})
})
return
return
}
}
...
...
controller/task.go
View file @
38c5e0e9
...
@@ -5,8 +5,6 @@ import (
...
@@ -5,8 +5,6 @@ import (
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"github.com/gin-gonic/gin"
"github.com/samber/lo"
"io"
"io"
"net/http"
"net/http"
"one-api/common"
"one-api/common"
...
@@ -17,6 +15,9 @@ import (
...
@@ -17,6 +15,9 @@ import (
"sort"
"sort"
"strconv"
"strconv"
"time"
"time"
"github.com/gin-gonic/gin"
"github.com/samber/lo"
)
)
func
UpdateTaskBulk
()
{
func
UpdateTaskBulk
()
{
...
@@ -225,14 +226,7 @@ func checkTaskNeedUpdate(oldTask *model.Task, newTask dto.SunoDataResponse) bool
...
@@ -225,14 +226,7 @@ func checkTaskNeedUpdate(oldTask *model.Task, newTask dto.SunoDataResponse) bool
}
}
func
GetAllTask
(
c
*
gin
.
Context
)
{
func
GetAllTask
(
c
*
gin
.
Context
)
{
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
if
p
<
1
{
p
=
1
}
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
if
pageSize
<=
0
{
pageSize
=
common
.
ItemsPerPage
}
startTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"start_timestamp"
),
10
,
64
)
startTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"start_timestamp"
),
10
,
64
)
endTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"end_timestamp"
),
10
,
64
)
endTimestamp
,
_
:=
strconv
.
ParseInt
(
c
.
Query
(
"end_timestamp"
),
10
,
64
)
...
@@ -247,30 +241,15 @@ func GetAllTask(c *gin.Context) {
...
@@ -247,30 +241,15 @@ func GetAllTask(c *gin.Context) {
ChannelID
:
c
.
Query
(
"channel_id"
),
ChannelID
:
c
.
Query
(
"channel_id"
),
}
}
items
:=
model
.
TaskGetAllTasks
(
(
p
-
1
)
*
pageSize
,
pageSize
,
queryParams
)
items
:=
model
.
TaskGetAllTasks
(
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
()
,
queryParams
)
total
:=
model
.
TaskCountAllTasks
(
queryParams
)
total
:=
model
.
TaskCountAllTasks
(
queryParams
)
pageInfo
.
SetTotal
(
int
(
total
))
c
.
JSON
(
200
,
gin
.
H
{
pageInfo
.
SetItems
(
items
)
"success"
:
true
,
common
.
ApiSuccess
(
c
,
pageInfo
)
"message"
:
""
,
"data"
:
gin
.
H
{
"items"
:
items
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
},
})
}
}
func
GetUserTask
(
c
*
gin
.
Context
)
{
func
GetUserTask
(
c
*
gin
.
Context
)
{
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
if
p
<
1
{
p
=
1
}
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
if
pageSize
<=
0
{
pageSize
=
common
.
ItemsPerPage
}
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
...
@@ -286,17 +265,9 @@ func GetUserTask(c *gin.Context) {
...
@@ -286,17 +265,9 @@ func GetUserTask(c *gin.Context) {
EndTimestamp
:
endTimestamp
,
EndTimestamp
:
endTimestamp
,
}
}
items
:=
model
.
TaskGetAllUserTask
(
userId
,
(
p
-
1
)
*
pageSize
,
pageSize
,
queryParams
)
items
:=
model
.
TaskGetAllUserTask
(
userId
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
()
,
queryParams
)
total
:=
model
.
TaskCountAllUserTask
(
userId
,
queryParams
)
total
:=
model
.
TaskCountAllUserTask
(
userId
,
queryParams
)
pageInfo
.
SetTotal
(
int
(
total
))
c
.
JSON
(
200
,
gin
.
H
{
pageInfo
.
SetItems
(
items
)
"success"
:
true
,
common
.
ApiSuccess
(
c
,
pageInfo
)
"message"
:
""
,
"data"
:
gin
.
H
{
"items"
:
items
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
},
})
}
}
controller/token.go
View file @
38c5e0e9
package
controller
package
controller
import
(
import
(
"github.com/gin-gonic/gin"
"net/http"
"net/http"
"one-api/common"
"one-api/common"
"one-api/model"
"one-api/model"
"strconv"
"strconv"
"github.com/gin-gonic/gin"
)
)
func
GetAllTokens
(
c
*
gin
.
Context
)
{
func
GetAllTokens
(
c
*
gin
.
Context
)
{
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
size
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"size"
))
tokens
,
err
:=
model
.
GetAllUserTokens
(
userId
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
())
if
p
<
1
{
p
=
1
}
if
size
<=
0
{
size
=
common
.
ItemsPerPage
}
else
if
size
>
100
{
size
=
100
}
tokens
,
err
:=
model
.
GetAllUserTokens
(
userId
,
(
p
-
1
)
*
size
,
size
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
// Get total count for pagination
total
,
_
:=
model
.
CountUserTokens
(
userId
)
total
,
_
:=
model
.
CountUserTokens
(
userId
)
pageInfo
.
SetTotal
(
int
(
total
))
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
pageInfo
.
SetItems
(
tokens
)
"success"
:
true
,
common
.
ApiSuccess
(
c
,
pageInfo
)
"message"
:
""
,
"data"
:
gin
.
H
{
"items"
:
tokens
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
size
,
},
})
return
return
}
}
...
@@ -50,10 +30,7 @@ func SearchTokens(c *gin.Context) {
...
@@ -50,10 +30,7 @@ func SearchTokens(c *gin.Context) {
token
:=
c
.
Query
(
"token"
)
token
:=
c
.
Query
(
"token"
)
tokens
,
err
:=
model
.
SearchUserTokens
(
userId
,
keyword
,
token
)
tokens
,
err
:=
model
.
SearchUserTokens
(
userId
,
keyword
,
token
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -68,18 +45,12 @@ func GetToken(c *gin.Context) {
...
@@ -68,18 +45,12 @@ func GetToken(c *gin.Context) {
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
token
,
err
:=
model
.
GetTokenByIds
(
id
,
userId
)
token
,
err
:=
model
.
GetTokenByIds
(
id
,
userId
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -95,10 +66,7 @@ func GetTokenStatus(c *gin.Context) {
...
@@ -95,10 +66,7 @@ func GetTokenStatus(c *gin.Context) {
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
token
,
err
:=
model
.
GetTokenByIds
(
tokenId
,
userId
)
token
,
err
:=
model
.
GetTokenByIds
(
tokenId
,
userId
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
expiredAt
:=
token
.
ExpiredTime
expiredAt
:=
token
.
ExpiredTime
...
@@ -118,10 +86,7 @@ func AddToken(c *gin.Context) {
...
@@ -118,10 +86,7 @@ func AddToken(c *gin.Context) {
token
:=
model
.
Token
{}
token
:=
model
.
Token
{}
err
:=
c
.
ShouldBindJSON
(
&
token
)
err
:=
c
.
ShouldBindJSON
(
&
token
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
if
len
(
token
.
Name
)
>
30
{
if
len
(
token
.
Name
)
>
30
{
...
@@ -156,10 +121,7 @@ func AddToken(c *gin.Context) {
...
@@ -156,10 +121,7 @@ func AddToken(c *gin.Context) {
}
}
err
=
cleanToken
.
Insert
()
err
=
cleanToken
.
Insert
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -174,10 +136,7 @@ func DeleteToken(c *gin.Context) {
...
@@ -174,10 +136,7 @@ func DeleteToken(c *gin.Context) {
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
err
:=
model
.
DeleteTokenById
(
id
,
userId
)
err
:=
model
.
DeleteTokenById
(
id
,
userId
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -193,10 +152,7 @@ func UpdateToken(c *gin.Context) {
...
@@ -193,10 +152,7 @@ func UpdateToken(c *gin.Context) {
token
:=
model
.
Token
{}
token
:=
model
.
Token
{}
err
:=
c
.
ShouldBindJSON
(
&
token
)
err
:=
c
.
ShouldBindJSON
(
&
token
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
if
len
(
token
.
Name
)
>
30
{
if
len
(
token
.
Name
)
>
30
{
...
@@ -208,10 +164,7 @@ func UpdateToken(c *gin.Context) {
...
@@ -208,10 +164,7 @@ func UpdateToken(c *gin.Context) {
}
}
cleanToken
,
err
:=
model
.
GetTokenByIds
(
token
.
Id
,
userId
)
cleanToken
,
err
:=
model
.
GetTokenByIds
(
token
.
Id
,
userId
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
if
token
.
Status
==
common
.
TokenStatusEnabled
{
if
token
.
Status
==
common
.
TokenStatusEnabled
{
...
@@ -245,10 +198,7 @@ func UpdateToken(c *gin.Context) {
...
@@ -245,10 +198,7 @@ func UpdateToken(c *gin.Context) {
}
}
err
=
cleanToken
.
Update
()
err
=
cleanToken
.
Update
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -275,10 +225,7 @@ func DeleteTokenBatch(c *gin.Context) {
...
@@ -275,10 +225,7 @@ func DeleteTokenBatch(c *gin.Context) {
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
count
,
err
:=
model
.
BatchDeleteTokens
(
tokenBatch
.
Ids
,
userId
)
count
,
err
:=
model
.
BatchDeleteTokens
(
tokenBatch
.
Ids
,
userId
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
controller/usedata.go
View file @
38c5e0e9
package
controller
package
controller
import
(
import
(
"github.com/gin-gonic/gin"
"net/http"
"net/http"
"one-api/common"
"one-api/model"
"one-api/model"
"strconv"
"strconv"
"github.com/gin-gonic/gin"
)
)
func
GetAllQuotaDates
(
c
*
gin
.
Context
)
{
func
GetAllQuotaDates
(
c
*
gin
.
Context
)
{
...
@@ -13,10 +15,7 @@ func GetAllQuotaDates(c *gin.Context) {
...
@@ -13,10 +15,7 @@ func GetAllQuotaDates(c *gin.Context) {
username
:=
c
.
Query
(
"username"
)
username
:=
c
.
Query
(
"username"
)
dates
,
err
:=
model
.
GetAllQuotaDates
(
startTimestamp
,
endTimestamp
,
username
)
dates
,
err
:=
model
.
GetAllQuotaDates
(
startTimestamp
,
endTimestamp
,
username
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -41,10 +40,7 @@ func GetUserQuotaDates(c *gin.Context) {
...
@@ -41,10 +40,7 @@ func GetUserQuotaDates(c *gin.Context) {
}
}
dates
,
err
:=
model
.
GetQuotaDataByUserId
(
userId
,
startTimestamp
,
endTimestamp
)
dates
,
err
:=
model
.
GetQuotaDataByUserId
(
userId
,
startTimestamp
,
endTimestamp
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
controller/user.go
View file @
38c5e0e9
...
@@ -188,10 +188,7 @@ func Register(c *gin.Context) {
...
@@ -188,10 +188,7 @@ func Register(c *gin.Context) {
cleanUser
.
Email
=
user
.
Email
cleanUser
.
Email
=
user
.
Email
}
}
if
err
:=
cleanUser
.
Insert
(
inviterId
);
err
!=
nil
{
if
err
:=
cleanUser
.
Insert
(
inviterId
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
@@ -247,81 +244,45 @@ func Register(c *gin.Context) {
...
@@ -247,81 +244,45 @@ func Register(c *gin.Context) {
}
}
func
GetAllUsers
(
c
*
gin
.
Context
)
{
func
GetAllUsers
(
c
*
gin
.
Context
)
{
pageInfo
,
err
:=
common
.
GetPageQuery
(
c
)
pageInfo
:=
common
.
GetPageQuery
(
c
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"parse page query failed"
,
})
return
}
users
,
total
,
err
:=
model
.
GetAllUsers
(
pageInfo
)
users
,
total
,
err
:=
model
.
GetAllUsers
(
pageInfo
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
pageInfo
.
SetTotal
(
int
(
total
))
pageInfo
.
SetTotal
(
int
(
total
))
pageInfo
.
SetItems
(
users
)
pageInfo
.
SetItems
(
users
)
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
true
,
common
.
ApiSuccess
(
c
,
pageInfo
)
"message"
:
""
,
"data"
:
pageInfo
,
})
return
return
}
}
func
SearchUsers
(
c
*
gin
.
Context
)
{
func
SearchUsers
(
c
*
gin
.
Context
)
{
keyword
:=
c
.
Query
(
"keyword"
)
keyword
:=
c
.
Query
(
"keyword"
)
group
:=
c
.
Query
(
"group"
)
group
:=
c
.
Query
(
"group"
)
p
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"p"
))
pageInfo
:=
common
.
GetPageQuery
(
c
)
pageSize
,
_
:=
strconv
.
Atoi
(
c
.
Query
(
"page_size"
))
users
,
total
,
err
:=
model
.
SearchUsers
(
keyword
,
group
,
pageInfo
.
GetStartIdx
(),
pageInfo
.
GetPageSize
())
if
p
<
1
{
p
=
1
}
if
pageSize
<
0
{
pageSize
=
common
.
ItemsPerPage
}
startIdx
:=
(
p
-
1
)
*
pageSize
users
,
total
,
err
:=
model
.
SearchUsers
(
keyword
,
group
,
startIdx
,
pageSize
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
true
,
pageInfo
.
SetTotal
(
int
(
total
))
"message"
:
""
,
pageInfo
.
SetItems
(
users
)
"data"
:
gin
.
H
{
common
.
ApiSuccess
(
c
,
pageInfo
)
"items"
:
users
,
"total"
:
total
,
"page"
:
p
,
"page_size"
:
pageSize
,
},
})
return
return
}
}
func
GetUser
(
c
*
gin
.
Context
)
{
func
GetUser
(
c
*
gin
.
Context
)
{
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
user
,
err
:=
model
.
GetUserById
(
id
,
false
)
user
,
err
:=
model
.
GetUserById
(
id
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
myRole
:=
c
.
GetInt
(
"role"
)
myRole
:=
c
.
GetInt
(
"role"
)
...
@@ -344,10 +305,7 @@ func GenerateAccessToken(c *gin.Context) {
...
@@ -344,10 +305,7 @@ func GenerateAccessToken(c *gin.Context) {
id
:=
c
.
GetInt
(
"id"
)
id
:=
c
.
GetInt
(
"id"
)
user
,
err
:=
model
.
GetUserById
(
id
,
true
)
user
,
err
:=
model
.
GetUserById
(
id
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
// get rand int 28-32
// get rand int 28-32
...
@@ -372,10 +330,7 @@ func GenerateAccessToken(c *gin.Context) {
...
@@ -372,10 +330,7 @@ func GenerateAccessToken(c *gin.Context) {
}
}
if
err
:=
user
.
Update
(
false
);
err
!=
nil
{
if
err
:=
user
.
Update
(
false
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
@@ -395,18 +350,12 @@ func TransferAffQuota(c *gin.Context) {
...
@@ -395,18 +350,12 @@ func TransferAffQuota(c *gin.Context) {
id
:=
c
.
GetInt
(
"id"
)
id
:=
c
.
GetInt
(
"id"
)
user
,
err
:=
model
.
GetUserById
(
id
,
true
)
user
,
err
:=
model
.
GetUserById
(
id
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
tran
:=
TransferAffQuotaRequest
{}
tran
:=
TransferAffQuotaRequest
{}
if
err
:=
c
.
ShouldBindJSON
(
&
tran
);
err
!=
nil
{
if
err
:=
c
.
ShouldBindJSON
(
&
tran
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
err
=
user
.
TransferAffQuotaToQuota
(
tran
.
Quota
)
err
=
user
.
TransferAffQuotaToQuota
(
tran
.
Quota
)
...
@@ -427,10 +376,7 @@ func GetAffCode(c *gin.Context) {
...
@@ -427,10 +376,7 @@ func GetAffCode(c *gin.Context) {
id
:=
c
.
GetInt
(
"id"
)
id
:=
c
.
GetInt
(
"id"
)
user
,
err
:=
model
.
GetUserById
(
id
,
true
)
user
,
err
:=
model
.
GetUserById
(
id
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
if
user
.
AffCode
==
""
{
if
user
.
AffCode
==
""
{
...
@@ -455,10 +401,7 @@ func GetSelf(c *gin.Context) {
...
@@ -455,10 +401,7 @@ func GetSelf(c *gin.Context) {
id
:=
c
.
GetInt
(
"id"
)
id
:=
c
.
GetInt
(
"id"
)
user
,
err
:=
model
.
GetUserById
(
id
,
false
)
user
,
err
:=
model
.
GetUserById
(
id
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
// Hide admin remarks: set to empty to trigger omitempty tag, ensuring the remark field is not included in JSON returned to regular users
// Hide admin remarks: set to empty to trigger omitempty tag, ensuring the remark field is not included in JSON returned to regular users
...
@@ -479,10 +422,7 @@ func GetUserModels(c *gin.Context) {
...
@@ -479,10 +422,7 @@ func GetUserModels(c *gin.Context) {
}
}
user
,
err
:=
model
.
GetUserCache
(
id
)
user
,
err
:=
model
.
GetUserCache
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
groups
:=
setting
.
GetUserUsableGroups
(
user
.
Group
)
groups
:=
setting
.
GetUserUsableGroups
(
user
.
Group
)
...
@@ -524,10 +464,7 @@ func UpdateUser(c *gin.Context) {
...
@@ -524,10 +464,7 @@ func UpdateUser(c *gin.Context) {
}
}
originUser
,
err
:=
model
.
GetUserById
(
updatedUser
.
Id
,
false
)
originUser
,
err
:=
model
.
GetUserById
(
updatedUser
.
Id
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
myRole
:=
c
.
GetInt
(
"role"
)
myRole
:=
c
.
GetInt
(
"role"
)
...
@@ -550,10 +487,7 @@ func UpdateUser(c *gin.Context) {
...
@@ -550,10 +487,7 @@ func UpdateUser(c *gin.Context) {
}
}
updatePassword
:=
updatedUser
.
Password
!=
""
updatePassword
:=
updatedUser
.
Password
!=
""
if
err
:=
updatedUser
.
Edit
(
updatePassword
);
err
!=
nil
{
if
err
:=
updatedUser
.
Edit
(
updatePassword
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
if
originUser
.
Quota
!=
updatedUser
.
Quota
{
if
originUser
.
Quota
!=
updatedUser
.
Quota
{
...
@@ -599,17 +533,11 @@ func UpdateSelf(c *gin.Context) {
...
@@ -599,17 +533,11 @@ func UpdateSelf(c *gin.Context) {
}
}
updatePassword
,
err
:=
checkUpdatePassword
(
user
.
OriginalPassword
,
user
.
Password
,
cleanUser
.
Id
)
updatePassword
,
err
:=
checkUpdatePassword
(
user
.
OriginalPassword
,
user
.
Password
,
cleanUser
.
Id
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
if
err
:=
cleanUser
.
Update
(
updatePassword
);
err
!=
nil
{
if
err
:=
cleanUser
.
Update
(
updatePassword
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
@@ -640,18 +568,12 @@ func checkUpdatePassword(originalPassword string, newPassword string, userId int
...
@@ -640,18 +568,12 @@ func checkUpdatePassword(originalPassword string, newPassword string, userId int
func
DeleteUser
(
c
*
gin
.
Context
)
{
func
DeleteUser
(
c
*
gin
.
Context
)
{
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
originUser
,
err
:=
model
.
GetUserById
(
id
,
false
)
originUser
,
err
:=
model
.
GetUserById
(
id
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
myRole
:=
c
.
GetInt
(
"role"
)
myRole
:=
c
.
GetInt
(
"role"
)
...
@@ -686,10 +608,7 @@ func DeleteSelf(c *gin.Context) {
...
@@ -686,10 +608,7 @@ func DeleteSelf(c *gin.Context) {
err
:=
model
.
DeleteUserById
(
id
)
err
:=
model
.
DeleteUserById
(
id
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -735,10 +654,7 @@ func CreateUser(c *gin.Context) {
...
@@ -735,10 +654,7 @@ func CreateUser(c *gin.Context) {
DisplayName
:
user
.
DisplayName
,
DisplayName
:
user
.
DisplayName
,
}
}
if
err
:=
cleanUser
.
Insert
(
0
);
err
!=
nil
{
if
err
:=
cleanUser
.
Insert
(
0
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
@@ -848,10 +764,7 @@ func ManageUser(c *gin.Context) {
...
@@ -848,10 +764,7 @@ func ManageUser(c *gin.Context) {
}
}
if
err
:=
user
.
Update
(
false
);
err
!=
nil
{
if
err
:=
user
.
Update
(
false
);
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
clearUser
:=
model
.
User
{
clearUser
:=
model
.
User
{
...
@@ -883,20 +796,14 @@ func EmailBind(c *gin.Context) {
...
@@ -883,20 +796,14 @@ func EmailBind(c *gin.Context) {
}
}
err
:=
user
.
FillUserById
()
err
:=
user
.
FillUserById
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
user
.
Email
=
email
user
.
Email
=
email
// no need to check if this email already taken, because we have used verification code to check it
// no need to check if this email already taken, because we have used verification code to check it
err
=
user
.
Update
(
false
)
err
=
user
.
Update
(
false
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -918,19 +825,13 @@ func TopUp(c *gin.Context) {
...
@@ -918,19 +825,13 @@ func TopUp(c *gin.Context) {
req
:=
topUpRequest
{}
req
:=
topUpRequest
{}
err
:=
c
.
ShouldBindJSON
(
&
req
)
err
:=
c
.
ShouldBindJSON
(
&
req
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
id
:=
c
.
GetInt
(
"id"
)
id
:=
c
.
GetInt
(
"id"
)
quota
,
err
:=
model
.
Redeem
(
req
.
Key
,
id
)
quota
,
err
:=
model
.
Redeem
(
req
.
Key
,
id
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
@@ -1013,10 +914,7 @@ func UpdateUserSetting(c *gin.Context) {
...
@@ -1013,10 +914,7 @@ func UpdateUserSetting(c *gin.Context) {
userId
:=
c
.
GetInt
(
"id"
)
userId
:=
c
.
GetInt
(
"id"
)
user
,
err
:=
model
.
GetUserById
(
userId
,
true
)
user
,
err
:=
model
.
GetUserById
(
userId
,
true
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
...
...
controller/wechat.go
View file @
38c5e0e9
...
@@ -4,13 +4,14 @@ import (
...
@@ -4,13 +4,14 @@ import (
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"net/http"
"net/http"
"one-api/common"
"one-api/common"
"one-api/model"
"one-api/model"
"strconv"
"strconv"
"time"
"time"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
)
type
wechatLoginResponse
struct
{
type
wechatLoginResponse
struct
{
...
@@ -150,19 +151,13 @@ func WeChatBind(c *gin.Context) {
...
@@ -150,19 +151,13 @@ func WeChatBind(c *gin.Context) {
}
}
err
=
user
.
FillUserById
()
err
=
user
.
FillUserById
()
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
user
.
WeChatId
=
wechatId
user
.
WeChatId
=
wechatId
err
=
user
.
Update
(
false
)
err
=
user
.
Update
(
false
)
if
err
!=
nil
{
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
common
.
ApiError
(
c
,
err
)
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
return
}
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
...
...
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