feat(server): implement server management handlers and database schema
This commit is contained in:
parent
1ccbdc18b1
commit
ad4f3df74e
@ -21,6 +21,149 @@ type (
|
|||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
List []MessageLog `json:"list"`
|
List []MessageLog `json:"list"`
|
||||||
}
|
}
|
||||||
|
FilterLogParams {
|
||||||
|
Page int `form:"page"`
|
||||||
|
Size int `form:"size"`
|
||||||
|
Date string `form:"date,optional"`
|
||||||
|
Search string `form:"search,optional"`
|
||||||
|
}
|
||||||
|
FilterEmailLogResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []MessageLog `json:"list"`
|
||||||
|
}
|
||||||
|
FilterMobileLogResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []MessageLog `json:"list"`
|
||||||
|
}
|
||||||
|
SubscribeLog {
|
||||||
|
UserId int64 `json:"user_id"`
|
||||||
|
Token string `json:"token"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
ClientIP string `json:"client_ip"`
|
||||||
|
UserSubscribeId int64 `json:"user_subscribe_id"`
|
||||||
|
SubscribedAt int64 `json:"subscribed_at"`
|
||||||
|
}
|
||||||
|
FilterSubscribeLogRequest {
|
||||||
|
FilterLogParams
|
||||||
|
UserId int64 `form:"user_id,optional"`
|
||||||
|
}
|
||||||
|
FilterSubscribeLogResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []SubscribeLog `json:"list"`
|
||||||
|
}
|
||||||
|
LoginLog {
|
||||||
|
UserId int64 `json:"user_id"`
|
||||||
|
Method string `json:"method"`
|
||||||
|
LoginIP string `json:"login_ip"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
Success bool `json:"success"`
|
||||||
|
LoginTime int64 `json:"login_time"`
|
||||||
|
}
|
||||||
|
FilterLoginLogRequest {
|
||||||
|
FilterLogParams
|
||||||
|
UserId int64 `form:"user_id,optional"`
|
||||||
|
}
|
||||||
|
FilterLoginLogResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []LoginLog `json:"list"`
|
||||||
|
}
|
||||||
|
RegisterLog {
|
||||||
|
UserId int64 `json:"user_id"`
|
||||||
|
AuthMethod string `json:"auth_method"`
|
||||||
|
Identifier string `json:"identifier"`
|
||||||
|
RegisterIP string `json:"register_ip"`
|
||||||
|
UserAgent string `json:"user_agent"`
|
||||||
|
RegisterTime int64 `json:"register_time"`
|
||||||
|
}
|
||||||
|
FilterRegisterLogRequest {
|
||||||
|
FilterLogParams
|
||||||
|
UserId int64 `form:"user_id,optional"`
|
||||||
|
}
|
||||||
|
FilterRegisterLogResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []RegisterLog `json:"list"`
|
||||||
|
}
|
||||||
|
ResetSubscribeLog {
|
||||||
|
Type uint16 `json:"type"`
|
||||||
|
UserId int64 `json:"user_id"`
|
||||||
|
UserSubscribeId int64 `json:"user_subscribe_id"`
|
||||||
|
OrderNo string `json:"order_no,omitempty"`
|
||||||
|
ResetAt int64 `json:"reset_at"`
|
||||||
|
}
|
||||||
|
FilterResetSubscribeLogRequest {
|
||||||
|
FilterLogParams
|
||||||
|
UserSubscribeId int64 `form:"user_subscribe_id,optional"`
|
||||||
|
}
|
||||||
|
FilterResetSubscribeLogResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []ResetSubscribeLog `json:"list"`
|
||||||
|
}
|
||||||
|
UserSubscribeTrafficLog {
|
||||||
|
SubscribeId int64 `json:"subscribe_id"` // Subscribe ID
|
||||||
|
UserId int64 `json:"user_id"` // User ID
|
||||||
|
Upload int64 `json:"upload"` // Upload traffic in bytes
|
||||||
|
Download int64 `json:"download"` // Download traffic in bytes
|
||||||
|
Total int64 `json:"total"` // Total traffic in bytes (Upload + Download)
|
||||||
|
Date string `json:"date"` // Date in YYYY-MM-DD format
|
||||||
|
}
|
||||||
|
FilterSubscribeTrafficRequest {
|
||||||
|
FilterLogParams
|
||||||
|
UserId int64 `form:"user_id,optional"`
|
||||||
|
UserSubscribeId int64 `form:"user_subscribe_id,optional"`
|
||||||
|
}
|
||||||
|
FilterSubscribeTrafficResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []UserSubscribeTrafficLog `json:"list"`
|
||||||
|
}
|
||||||
|
ServerTrafficLog {
|
||||||
|
ServerId int64 `json:"server_id"` // Server ID
|
||||||
|
Upload int64 `json:"upload"` // Upload traffic in bytes
|
||||||
|
Download int64 `json:"download"` // Download traffic in bytes
|
||||||
|
Total int64 `json:"total"` // Total traffic in bytes (Upload + Download)
|
||||||
|
Date string `json:"date"` // Date in YYYY-MM-DD format
|
||||||
|
}
|
||||||
|
FilterServerTrafficLogRequest {
|
||||||
|
FilterLogParams
|
||||||
|
ServerId int64 `form:"server_id,optional"`
|
||||||
|
}
|
||||||
|
FilterServerTrafficLogResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []ServerTrafficLog `json:"list"`
|
||||||
|
}
|
||||||
|
FilterBalanceLogRequest {
|
||||||
|
FilterLogParams
|
||||||
|
UserId int64 `form:"user_id,optional"`
|
||||||
|
}
|
||||||
|
FilterBalanceLogResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []BalanceLog `json:"list"`
|
||||||
|
}
|
||||||
|
FilterCommissionLogRequest {
|
||||||
|
FilterLogParams
|
||||||
|
UserId int64 `form:"user_id,optional"`
|
||||||
|
}
|
||||||
|
FilterCommissionLogResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []CommissionLog `json:"list"`
|
||||||
|
}
|
||||||
|
GiftLog {
|
||||||
|
Type uint16 `json:"type"`
|
||||||
|
userId int64 `json:"user_id"`
|
||||||
|
OrderNo string `json:"order_no"`
|
||||||
|
SubscribeId int64 `json:"subscribe_id"`
|
||||||
|
Amount int64 `json:"amount"`
|
||||||
|
Balance int64 `json:"balance"`
|
||||||
|
Remark string `json:"remark,omitempty"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
}
|
||||||
|
FilterGiftLogRequest {
|
||||||
|
FilterLogParams
|
||||||
|
UserId int64 `form:"user_id,optional"`
|
||||||
|
}
|
||||||
|
FilterGiftLogResponse {
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
List []GiftLog `json:"list"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@server (
|
@server (
|
||||||
@ -32,5 +175,49 @@ service ppanel {
|
|||||||
@doc "Get message log list"
|
@doc "Get message log list"
|
||||||
@handler GetMessageLogList
|
@handler GetMessageLogList
|
||||||
get /message/list (GetMessageLogListRequest) returns (GetMessageLogListResponse)
|
get /message/list (GetMessageLogListRequest) returns (GetMessageLogListResponse)
|
||||||
|
|
||||||
|
@doc "Filter email log"
|
||||||
|
@handler FilterEmailLog
|
||||||
|
get /email/list (FilterLogParams) returns (FilterEmailLogResponse)
|
||||||
|
|
||||||
|
@doc "Filter mobile log"
|
||||||
|
@handler FilterMobileLog
|
||||||
|
get /mobile/list (FilterLogParams) returns (FilterMobileLogResponse)
|
||||||
|
|
||||||
|
@doc "Filter subscribe log"
|
||||||
|
@handler FilterSubscribeLog
|
||||||
|
get /subscribe/list (FilterSubscribeLogRequest) returns (FilterSubscribeLogResponse)
|
||||||
|
|
||||||
|
@doc "Filter login log"
|
||||||
|
@handler FilterLoginLog
|
||||||
|
get /login/list (FilterLoginLogRequest) returns (FilterLoginLogResponse)
|
||||||
|
|
||||||
|
@doc "Filter register log"
|
||||||
|
@handler FilterRegisterLog
|
||||||
|
get /register/list (FilterRegisterLogRequest) returns (FilterRegisterLogResponse)
|
||||||
|
|
||||||
|
@doc "Filter reset subscribe log"
|
||||||
|
@handler FilterResetSubscribeLog
|
||||||
|
get /subscribe/reset/list (FilterResetSubscribeLogRequest) returns (FilterResetSubscribeLogResponse)
|
||||||
|
|
||||||
|
@doc "Filter user subscribe traffic log"
|
||||||
|
@handler FilterUserSubscribeTrafficLog
|
||||||
|
get /subscribe/traffic/list (FilterSubscribeTrafficRequest) returns (FilterSubscribeTrafficResponse)
|
||||||
|
|
||||||
|
@doc "Filter server traffic log"
|
||||||
|
@handler FilterServerTrafficLog
|
||||||
|
get /server/traffic/list (FilterServerTrafficLogRequest) returns (FilterServerTrafficLogResponse)
|
||||||
|
|
||||||
|
@doc "Filter balance log"
|
||||||
|
@handler FilterBalanceLog
|
||||||
|
get /balance/list (FilterBalanceLogRequest) returns (FilterBalanceLogResponse)
|
||||||
|
|
||||||
|
@doc "Filter commission log"
|
||||||
|
@handler FilterCommissionLog
|
||||||
|
get /commission/list (FilterCommissionLogRequest) returns (FilterCommissionLogResponse)
|
||||||
|
|
||||||
|
@doc "Filter gift log"
|
||||||
|
@handler FilterGiftLog
|
||||||
|
get /gift/list (FilterGiftLogRequest) returns (FilterGiftLogResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,7 @@ type (
|
|||||||
}
|
}
|
||||||
Protocol {
|
Protocol {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
Port uint16 `json:"port"`
|
||||||
Security string `json:"security,omitempty"`
|
Security string `json:"security,omitempty"`
|
||||||
SNI string `json:"sni,omitempty"`
|
SNI string `json:"sni,omitempty"`
|
||||||
AllowInsecure bool `json:"allow_insecure,omitempty"`
|
AllowInsecure bool `json:"allow_insecure,omitempty"`
|
||||||
@ -105,30 +106,37 @@ type (
|
|||||||
Node {
|
Node {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Tags string `json:"tags"`
|
Tags []string `json:"tags"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
ServerId int64 `json:"server_id"`
|
ServerId int64 `json:"server_id"`
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
|
Enabled *bool `json:"enabled"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
}
|
}
|
||||||
CreateNodeRequest {
|
CreateNodeRequest {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Tags string `json:"tags,omitempty"`
|
Tags []string `json:"tags,omitempty"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
ServerId int64 `json:"server_id"`
|
ServerId int64 `json:"server_id"`
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
|
Enabled *bool `json:"enabled"`
|
||||||
}
|
}
|
||||||
UpdateNodeRequest {
|
UpdateNodeRequest {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Tags string `json:"tags,omitempty"`
|
Tags []string `json:"tags,omitempty"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
ServerId int64 `json:"server_id"`
|
ServerId int64 `json:"server_id"`
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
|
Enabled *bool `json:"enabled"`
|
||||||
|
}
|
||||||
|
ToggleNodeStatusRequest {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Enable *bool `json:"enable"`
|
||||||
}
|
}
|
||||||
DeleteNodeRequest {
|
DeleteNodeRequest {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
@ -185,5 +193,9 @@ service ppanel {
|
|||||||
@doc "Filter Node List"
|
@doc "Filter Node List"
|
||||||
@handler FilterNodeList
|
@handler FilterNodeList
|
||||||
get /node/list (FilterNodeListRequest) returns (FilterNodeListResponse)
|
get /node/list (FilterNodeListRequest) returns (FilterNodeListResponse)
|
||||||
|
|
||||||
|
@doc "Toggle Node Status"
|
||||||
|
@handler ToggleNodeStatus
|
||||||
|
post /node/status/toggle (ToggleNodeStatusRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -25,16 +25,9 @@ type (
|
|||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
}
|
}
|
||||||
QueryUserBalanceLogListResponse {
|
QueryUserBalanceLogListResponse {
|
||||||
List []UserBalanceLog `json:"list"`
|
List []BalanceLog `json:"list"`
|
||||||
Total int64 `json:"total"`
|
Total int64 `json:"total"`
|
||||||
}
|
}
|
||||||
CommissionLog {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
UserId int64 `json:"user_id"`
|
|
||||||
OrderNo string `json:"order_no"`
|
|
||||||
Amount int64 `json:"amount"`
|
|
||||||
CreatedAt int64 `json:"created_at"`
|
|
||||||
}
|
|
||||||
QueryUserCommissionLogListRequest {
|
QueryUserCommissionLogListRequest {
|
||||||
Page int `form:"page"`
|
Page int `form:"page"`
|
||||||
Size int `form:"size"`
|
Size int `form:"size"`
|
||||||
|
|||||||
@ -446,15 +446,6 @@ type (
|
|||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
UpdatedAt int64 `json:"updated_at"`
|
UpdatedAt int64 `json:"updated_at"`
|
||||||
}
|
}
|
||||||
UserBalanceLog {
|
|
||||||
Id int64 `json:"id"`
|
|
||||||
UserId int64 `json:"user_id"`
|
|
||||||
Amount int64 `json:"amount"`
|
|
||||||
Type uint8 `json:"type"`
|
|
||||||
OrderId int64 `json:"order_id"`
|
|
||||||
Balance int64 `json:"balance"`
|
|
||||||
CreatedAt int64 `json:"created_at"`
|
|
||||||
}
|
|
||||||
UserAffiliate {
|
UserAffiliate {
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
Identifier string `json:"identifier"`
|
Identifier string `json:"identifier"`
|
||||||
@ -756,10 +747,25 @@ type (
|
|||||||
}
|
}
|
||||||
ResetSubscribeTrafficLog {
|
ResetSubscribeTrafficLog {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
Type uint8 `json:"type"`
|
Type uint16 `json:"type"`
|
||||||
UserSubscribeId int64 `json:"user_subscribe_id"`
|
UserSubscribeId int64 `json:"user_subscribe_id"`
|
||||||
OrderNo string `json:"order_no,omitempty"`
|
OrderNo string `json:"order_no,omitempty"`
|
||||||
ResetAt int64 `json:"reset_at"`
|
ResetAt int64 `json:"reset_at"`
|
||||||
}
|
}
|
||||||
|
BalanceLog {
|
||||||
|
Type uint16 `json:"type"`
|
||||||
|
UserId int64 `json:"user_id"`
|
||||||
|
Amount int64 `json:"amount"`
|
||||||
|
OrderId int64 `json:"order_id,omitempty"`
|
||||||
|
Balance int64 `json:"balance"`
|
||||||
|
Timestamp int64 `json:"timestamp"`
|
||||||
|
}
|
||||||
|
CommissionLog {
|
||||||
|
Type uint16 `json:"type"`
|
||||||
|
UserId int64 `json:"user_id"`
|
||||||
|
Amount int64 `json:"amount"`
|
||||||
|
OrderNo string `json:"order_no"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
1
initialize/migrate/database/02105_node.down.sql
Normal file
1
initialize/migrate/database/02105_node.down.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS `servers`;
|
||||||
14
initialize/migrate/database/02105_node.up.sql
Normal file
14
initialize/migrate/database/02105_node.up.sql
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `servers` (
|
||||||
|
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Server Name',
|
||||||
|
`country` varchar(128) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Country',
|
||||||
|
`city` varchar(128) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'City',
|
||||||
|
`ratio` decimal(4,2) NOT NULL DEFAULT '0.00' COMMENT 'Traffic Ratio',
|
||||||
|
`address` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'Server Address',
|
||||||
|
`sort` bigint NOT NULL DEFAULT '0' COMMENT 'Sort',
|
||||||
|
`protocols` text COLLATE utf8mb4_general_ci COMMENT 'Protocol',
|
||||||
|
`last_reported_at` datetime(3) DEFAULT NULL COMMENT 'Last Reported Time',
|
||||||
|
`created_at` datetime(3) DEFAULT NULL COMMENT 'Creation Time',
|
||||||
|
`updated_at` datetime(3) DEFAULT NULL COMMENT 'Update Time',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
26
internal/handler/admin/log/filterBalanceLogHandler.go
Normal file
26
internal/handler/admin/log/filterBalanceLogHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter balance log
|
||||||
|
func FilterBalanceLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterBalanceLogRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterBalanceLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterBalanceLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/log/filterCommissionLogHandler.go
Normal file
26
internal/handler/admin/log/filterCommissionLogHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter commission log
|
||||||
|
func FilterCommissionLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterCommissionLogRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterCommissionLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterCommissionLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/log/filterEmailLogHandler.go
Normal file
26
internal/handler/admin/log/filterEmailLogHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter email log
|
||||||
|
func FilterEmailLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterLogParams
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterEmailLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterEmailLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/log/filterGiftLogHandler.go
Normal file
26
internal/handler/admin/log/filterGiftLogHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter gift log
|
||||||
|
func FilterGiftLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterGiftLogRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterGiftLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterGiftLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/log/filterLoginLogHandler.go
Normal file
26
internal/handler/admin/log/filterLoginLogHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter login log
|
||||||
|
func FilterLoginLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterLoginLogRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterLoginLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterLoginLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/log/filterMobileLogHandler.go
Normal file
26
internal/handler/admin/log/filterMobileLogHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter mobile log
|
||||||
|
func FilterMobileLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterLogParams
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterMobileLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterMobileLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/log/filterRegisterLogHandler.go
Normal file
26
internal/handler/admin/log/filterRegisterLogHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter register log
|
||||||
|
func FilterRegisterLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterRegisterLogRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterRegisterLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterRegisterLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/log/filterResetSubscribeLogHandler.go
Normal file
26
internal/handler/admin/log/filterResetSubscribeLogHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter reset subscribe log
|
||||||
|
func FilterResetSubscribeLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterResetSubscribeLogRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterResetSubscribeLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterResetSubscribeLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/log/filterServerTrafficLogHandler.go
Normal file
26
internal/handler/admin/log/filterServerTrafficLogHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter server traffic log
|
||||||
|
func FilterServerTrafficLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterSubscribeTrafficRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterServerTrafficLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterServerTrafficLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/log/filterSubscribeLogHandler.go
Normal file
26
internal/handler/admin/log/filterSubscribeLogHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter subscribe log
|
||||||
|
func FilterSubscribeLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterSubscribeLogRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterSubscribeLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterSubscribeLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter user subscribe traffic log
|
||||||
|
func FilterUserSubscribeTrafficLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterSubscribeTrafficRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := log.NewFilterUserSubscribeTrafficLogLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterUserSubscribeTrafficLog(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create node
|
// Create Node
|
||||||
func CreateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
func CreateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
var req types.CreateNodeRequest
|
var req types.CreateNodeRequest
|
||||||
|
|||||||
26
internal/handler/admin/server/createServerHandler.go
Normal file
26
internal/handler/admin/server/createServerHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CreateServerHandler Create Server
|
||||||
|
func CreateServerHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.CreateServerRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := server.NewCreateServerLogic(c.Request.Context(), svcCtx)
|
||||||
|
err := l.CreateServer(&req)
|
||||||
|
result.HttpResult(c, nil, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Delete node
|
// Delete Node
|
||||||
func DeleteNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
func DeleteNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
var req types.DeleteNodeRequest
|
var req types.DeleteNodeRequest
|
||||||
|
|||||||
26
internal/handler/admin/server/deleteServerHandler.go
Normal file
26
internal/handler/admin/server/deleteServerHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete Server
|
||||||
|
func DeleteServerHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.DeleteServerRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := server.NewDeleteServerLogic(c.Request.Context(), svcCtx)
|
||||||
|
err := l.DeleteServer(&req)
|
||||||
|
result.HttpResult(c, nil, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/server/filterNodeListHandler.go
Normal file
26
internal/handler/admin/server/filterNodeListHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Filter Node List
|
||||||
|
func FilterNodeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterNodeListRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := server.NewFilterNodeListLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterNodeList(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/server/filterServerListHandler.go
Normal file
26
internal/handler/admin/server/filterServerListHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// FilterServerListHandler Filter Server List
|
||||||
|
func FilterServerListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.FilterServerListRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := server.NewFilterServerListLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.FilterServerList(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/server/getServerProtocolsHandler.go
Normal file
26
internal/handler/admin/server/getServerProtocolsHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get Server Protocols
|
||||||
|
func GetServerProtocolsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.GetServerProtocolsRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := server.NewGetServerProtocolsLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.GetServerProtocols(&req)
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
26
internal/handler/admin/server/toggleNodeStatusHandler.go
Normal file
26
internal/handler/admin/server/toggleNodeStatusHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Toggle Node Status
|
||||||
|
func ToggleNodeStatusHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.ToggleNodeStatusRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := server.NewToggleNodeStatusLogic(c.Request.Context(), svcCtx)
|
||||||
|
err := l.ToggleNodeStatus(&req)
|
||||||
|
result.HttpResult(c, nil, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Update node
|
// Update Node
|
||||||
func UpdateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
func UpdateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
var req types.UpdateNodeRequest
|
var req types.UpdateNodeRequest
|
||||||
|
|||||||
26
internal/handler/admin/server/updateServerHandler.go
Normal file
26
internal/handler/admin/server/updateServerHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Update Server
|
||||||
|
func UpdateServerHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.UpdateServerRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := server.NewUpdateServerLogic(c.Request.Context(), svcCtx)
|
||||||
|
err := l.UpdateServer(&req)
|
||||||
|
result.HttpResult(c, nil, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func BatchDeleteNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewBatchDeleteNodeGroupLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewBatchDeleteNodeGroupLogic(c.Request.Context(), svcCtx)
|
||||||
err := l.BatchDeleteNodeGroup(&req)
|
err := l.BatchDeleteNodeGroup(&req)
|
||||||
result.HttpResult(c, nil, err)
|
result.HttpResult(c, nil, err)
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func BatchDeleteNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewBatchDeleteNodeLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewBatchDeleteNodeLogic(c.Request.Context(), svcCtx)
|
||||||
err := l.BatchDeleteNode(&req)
|
err := l.BatchDeleteNode(&req)
|
||||||
result.HttpResult(c, nil, err)
|
result.HttpResult(c, nil, err)
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func CreateNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewCreateNodeGroupLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewCreateNodeGroupLogic(c.Request.Context(), svcCtx)
|
||||||
err := l.CreateNodeGroup(&req)
|
err := l.CreateNodeGroup(&req)
|
||||||
result.HttpResult(c, nil, err)
|
result.HttpResult(c, nil, err)
|
||||||
}
|
}
|
||||||
26
internal/handler/admin/server_bak/createNodeHandler.go
Normal file
26
internal/handler/admin/server_bak/createNodeHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package server_bak
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Create node
|
||||||
|
func CreateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.CreateNodeRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := server_bak.NewCreateNodeLogic(c.Request.Context(), svcCtx)
|
||||||
|
err := l.CreateNode(&req)
|
||||||
|
result.HttpResult(c, nil, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func CreateRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewCreateRuleGroupLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewCreateRuleGroupLogic(c.Request.Context(), svcCtx)
|
||||||
err := l.CreateRuleGroup(&req)
|
err := l.CreateRuleGroup(&req)
|
||||||
result.HttpResult(c, nil, err)
|
result.HttpResult(c, nil, err)
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func DeleteNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewDeleteNodeGroupLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewDeleteNodeGroupLogic(c.Request.Context(), svcCtx)
|
||||||
err := l.DeleteNodeGroup(&req)
|
err := l.DeleteNodeGroup(&req)
|
||||||
result.HttpResult(c, nil, err)
|
result.HttpResult(c, nil, err)
|
||||||
}
|
}
|
||||||
26
internal/handler/admin/server_bak/deleteNodeHandler.go
Normal file
26
internal/handler/admin/server_bak/deleteNodeHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package server_bak
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Delete node
|
||||||
|
func DeleteNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.DeleteNodeRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := server_bak.NewDeleteNodeLogic(c.Request.Context(), svcCtx)
|
||||||
|
err := l.DeleteNode(&req)
|
||||||
|
result.HttpResult(c, nil, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func DeleteRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewDeleteRuleGroupLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewDeleteRuleGroupLogic(c.Request.Context(), svcCtx)
|
||||||
err := l.DeleteRuleGroup(&req)
|
err := l.DeleteRuleGroup(&req)
|
||||||
result.HttpResult(c, nil, err)
|
result.HttpResult(c, nil, err)
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func GetNodeDetailHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewGetNodeDetailLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewGetNodeDetailLogic(c.Request.Context(), svcCtx)
|
||||||
resp, err := l.GetNodeDetail(&req)
|
resp, err := l.GetNodeDetail(&req)
|
||||||
result.HttpResult(c, resp, err)
|
result.HttpResult(c, resp, err)
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
)
|
)
|
||||||
@ -11,7 +11,7 @@ import (
|
|||||||
func GetNodeGroupListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
func GetNodeGroupListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
|
||||||
l := server.NewGetNodeGroupListLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewGetNodeGroupListLogic(c.Request.Context(), svcCtx)
|
||||||
resp, err := l.GetNodeGroupList()
|
resp, err := l.GetNodeGroupList()
|
||||||
result.HttpResult(c, resp, err)
|
result.HttpResult(c, resp, err)
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func GetNodeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewGetNodeListLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewGetNodeListLogic(c.Request.Context(), svcCtx)
|
||||||
resp, err := l.GetNodeList(&req)
|
resp, err := l.GetNodeList(&req)
|
||||||
result.HttpResult(c, resp, err)
|
result.HttpResult(c, resp, err)
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
)
|
)
|
||||||
@ -11,7 +11,7 @@ import (
|
|||||||
func GetNodeTagListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
func GetNodeTagListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
|
||||||
l := server.NewGetNodeTagListLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewGetNodeTagListLogic(c.Request.Context(), svcCtx)
|
||||||
resp, err := l.GetNodeTagList()
|
resp, err := l.GetNodeTagList()
|
||||||
result.HttpResult(c, resp, err)
|
result.HttpResult(c, resp, err)
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
)
|
)
|
||||||
@ -11,7 +11,7 @@ import (
|
|||||||
func GetRuleGroupListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
func GetRuleGroupListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
|
|
||||||
l := server.NewGetRuleGroupListLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewGetRuleGroupListLogic(c.Request.Context(), svcCtx)
|
||||||
resp, err := l.GetRuleGroupList()
|
resp, err := l.GetRuleGroupList()
|
||||||
result.HttpResult(c, resp, err)
|
result.HttpResult(c, resp, err)
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func NodeSortHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewNodeSortLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewNodeSortLogic(c.Request.Context(), svcCtx)
|
||||||
err := l.NodeSort(&req)
|
err := l.NodeSort(&req)
|
||||||
result.HttpResult(c, nil, err)
|
result.HttpResult(c, nil, err)
|
||||||
}
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func UpdateNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewUpdateNodeGroupLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewUpdateNodeGroupLogic(c.Request.Context(), svcCtx)
|
||||||
err := l.UpdateNodeGroup(&req)
|
err := l.UpdateNodeGroup(&req)
|
||||||
result.HttpResult(c, nil, err)
|
result.HttpResult(c, nil, err)
|
||||||
}
|
}
|
||||||
26
internal/handler/admin/server_bak/updateNodeHandler.go
Normal file
26
internal/handler/admin/server_bak/updateNodeHandler.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package server_bak
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Update node
|
||||||
|
func UpdateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
var req types.UpdateNodeRequest
|
||||||
|
_ = c.ShouldBind(&req)
|
||||||
|
validateErr := svcCtx.Validate(&req)
|
||||||
|
if validateErr != nil {
|
||||||
|
result.ParamErrorResult(c, validateErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := server_bak.NewUpdateNodeLogic(c.Request.Context(), svcCtx)
|
||||||
|
err := l.UpdateNode(&req)
|
||||||
|
result.HttpResult(c, nil, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,8 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/perfect-panel/server/internal/logic/admin/server"
|
"github.com/perfect-panel/server/internal/logic/admin/server_bak"
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/result"
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
@ -19,7 +19,7 @@ func UpdateRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l := server.NewUpdateRuleGroupLogic(c.Request.Context(), svcCtx)
|
l := server_bak.NewUpdateRuleGroupLogic(c.Request.Context(), svcCtx)
|
||||||
err := l.UpdateRuleGroup(&req)
|
err := l.UpdateRuleGroup(&req)
|
||||||
result.HttpResult(c, nil, err)
|
result.HttpResult(c, nil, err)
|
||||||
}
|
}
|
||||||
@ -189,8 +189,41 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
|||||||
adminLogGroupRouter.Use(middleware.AuthMiddleware(serverCtx))
|
adminLogGroupRouter.Use(middleware.AuthMiddleware(serverCtx))
|
||||||
|
|
||||||
{
|
{
|
||||||
|
// Filter balance log
|
||||||
|
adminLogGroupRouter.GET("/balance/list", adminLog.FilterBalanceLogHandler(serverCtx))
|
||||||
|
|
||||||
|
// Filter commission log
|
||||||
|
adminLogGroupRouter.GET("/commission/list", adminLog.FilterCommissionLogHandler(serverCtx))
|
||||||
|
|
||||||
|
// Filter email log
|
||||||
|
adminLogGroupRouter.GET("/email/list", adminLog.FilterEmailLogHandler(serverCtx))
|
||||||
|
|
||||||
|
// Filter gift log
|
||||||
|
adminLogGroupRouter.GET("/gift/list", adminLog.FilterGiftLogHandler(serverCtx))
|
||||||
|
|
||||||
|
// Filter login log
|
||||||
|
adminLogGroupRouter.GET("/login/list", adminLog.FilterLoginLogHandler(serverCtx))
|
||||||
|
|
||||||
// Get message log list
|
// Get message log list
|
||||||
adminLogGroupRouter.GET("/message/list", adminLog.GetMessageLogListHandler(serverCtx))
|
adminLogGroupRouter.GET("/message/list", adminLog.GetMessageLogListHandler(serverCtx))
|
||||||
|
|
||||||
|
// Filter mobile log
|
||||||
|
adminLogGroupRouter.GET("/mobile/list", adminLog.FilterMobileLogHandler(serverCtx))
|
||||||
|
|
||||||
|
// Filter register log
|
||||||
|
adminLogGroupRouter.GET("/register/list", adminLog.FilterRegisterLogHandler(serverCtx))
|
||||||
|
|
||||||
|
// Filter server traffic log
|
||||||
|
adminLogGroupRouter.GET("/server/traffic/list", adminLog.FilterServerTrafficLogHandler(serverCtx))
|
||||||
|
|
||||||
|
// Filter subscribe log
|
||||||
|
adminLogGroupRouter.GET("/subscribe/list", adminLog.FilterSubscribeLogHandler(serverCtx))
|
||||||
|
|
||||||
|
// Filter reset subscribe log
|
||||||
|
adminLogGroupRouter.GET("/subscribe/reset/list", adminLog.FilterResetSubscribeLogHandler(serverCtx))
|
||||||
|
|
||||||
|
// Filter user subscribe traffic log
|
||||||
|
adminLogGroupRouter.GET("/subscribe/traffic/list", adminLog.FilterUserSubscribeTrafficLogHandler(serverCtx))
|
||||||
}
|
}
|
||||||
|
|
||||||
adminMarketingGroupRouter := router.Group("/v1/admin/marketing")
|
adminMarketingGroupRouter := router.Group("/v1/admin/marketing")
|
||||||
@ -251,56 +284,35 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
|||||||
adminServerGroupRouter.Use(middleware.AuthMiddleware(serverCtx))
|
adminServerGroupRouter.Use(middleware.AuthMiddleware(serverCtx))
|
||||||
|
|
||||||
{
|
{
|
||||||
// Update node
|
// Create Server
|
||||||
adminServerGroupRouter.PUT("/", adminServer.UpdateNodeHandler(serverCtx))
|
adminServerGroupRouter.POST("/create", adminServer.CreateServerHandler(serverCtx))
|
||||||
|
|
||||||
// Create node
|
// Delete Server
|
||||||
adminServerGroupRouter.POST("/", adminServer.CreateNodeHandler(serverCtx))
|
adminServerGroupRouter.POST("/delete", adminServer.DeleteServerHandler(serverCtx))
|
||||||
|
|
||||||
// Delete node
|
// Filter Server List
|
||||||
adminServerGroupRouter.DELETE("/", adminServer.DeleteNodeHandler(serverCtx))
|
adminServerGroupRouter.GET("/list", adminServer.FilterServerListHandler(serverCtx))
|
||||||
|
|
||||||
// Batch delete node
|
// Create Node
|
||||||
adminServerGroupRouter.DELETE("/batch", adminServer.BatchDeleteNodeHandler(serverCtx))
|
adminServerGroupRouter.POST("/node/create", adminServer.CreateNodeHandler(serverCtx))
|
||||||
|
|
||||||
// Get node detail
|
// Delete Node
|
||||||
adminServerGroupRouter.GET("/detail", adminServer.GetNodeDetailHandler(serverCtx))
|
adminServerGroupRouter.POST("/node/delete", adminServer.DeleteNodeHandler(serverCtx))
|
||||||
|
|
||||||
// Create node group
|
// Filter Node List
|
||||||
adminServerGroupRouter.POST("/group", adminServer.CreateNodeGroupHandler(serverCtx))
|
adminServerGroupRouter.GET("/node/list", adminServer.FilterNodeListHandler(serverCtx))
|
||||||
|
|
||||||
// Update node group
|
// Toggle Node Status
|
||||||
adminServerGroupRouter.PUT("/group", adminServer.UpdateNodeGroupHandler(serverCtx))
|
adminServerGroupRouter.POST("/node/status/toggle", adminServer.ToggleNodeStatusHandler(serverCtx))
|
||||||
|
|
||||||
// Delete node group
|
// Update Node
|
||||||
adminServerGroupRouter.DELETE("/group", adminServer.DeleteNodeGroupHandler(serverCtx))
|
adminServerGroupRouter.POST("/node/update", adminServer.UpdateNodeHandler(serverCtx))
|
||||||
|
|
||||||
// Batch delete node group
|
// Get Server Protocols
|
||||||
adminServerGroupRouter.DELETE("/group/batch", adminServer.BatchDeleteNodeGroupHandler(serverCtx))
|
adminServerGroupRouter.GET("/protocols", adminServer.GetServerProtocolsHandler(serverCtx))
|
||||||
|
|
||||||
// Get node group list
|
// Update Server
|
||||||
adminServerGroupRouter.GET("/group/list", adminServer.GetNodeGroupListHandler(serverCtx))
|
adminServerGroupRouter.POST("/update", adminServer.UpdateServerHandler(serverCtx))
|
||||||
|
|
||||||
// Get node list
|
|
||||||
adminServerGroupRouter.GET("/list", adminServer.GetNodeListHandler(serverCtx))
|
|
||||||
|
|
||||||
// Create rule group
|
|
||||||
adminServerGroupRouter.POST("/rule_group", adminServer.CreateRuleGroupHandler(serverCtx))
|
|
||||||
|
|
||||||
// Update rule group
|
|
||||||
adminServerGroupRouter.PUT("/rule_group", adminServer.UpdateRuleGroupHandler(serverCtx))
|
|
||||||
|
|
||||||
// Delete rule group
|
|
||||||
adminServerGroupRouter.DELETE("/rule_group", adminServer.DeleteRuleGroupHandler(serverCtx))
|
|
||||||
|
|
||||||
// Get rule group list
|
|
||||||
adminServerGroupRouter.GET("/rule_group_list", adminServer.GetRuleGroupListHandler(serverCtx))
|
|
||||||
|
|
||||||
// Node sort
|
|
||||||
adminServerGroupRouter.POST("/sort", adminServer.NodeSortHandler(serverCtx))
|
|
||||||
|
|
||||||
// Get node tag list
|
|
||||||
adminServerGroupRouter.GET("/tag/list", adminServer.GetNodeTagListHandler(serverCtx))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
adminSubscribeGroupRouter := router.Group("/v1/admin/subscribe")
|
adminSubscribeGroupRouter := router.Group("/v1/admin/subscribe")
|
||||||
|
|||||||
@ -6,12 +6,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/perfect-panel/server/pkg/xerr"
|
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/logger"
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type QueryServerTotalDataLogic struct {
|
type QueryServerTotalDataLogic struct {
|
||||||
@ -42,121 +39,6 @@ func (l *QueryServerTotalDataLogic) QueryServerTotalData() (resp *types.ServerTo
|
|||||||
UserTrafficRankingYesterday: make([]types.UserTrafficData, 0),
|
UserTrafficRankingYesterday: make([]types.UserTrafficData, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query node server status
|
|
||||||
servers, err := l.svcCtx.ServerModel.FindAllServer(l.ctx)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] FindAllServer error", logger.Field("error", err.Error()))
|
|
||||||
return nil, errors.Wrapf(err, "FindAllServer error: %v", err)
|
|
||||||
}
|
|
||||||
onlineServers, err := l.svcCtx.NodeCache.GetOnlineNodeStatusCount(l.ctx)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] GetOnlineNodeStatusCount error", logger.Field("error", err.Error()))
|
|
||||||
return nil, errors.Wrapf(err, "GetOnlineNodeStatusCount error: %v", err)
|
|
||||||
}
|
|
||||||
resp.OnlineServers = onlineServers
|
|
||||||
resp.OfflineServers = int64(len(servers) - int(onlineServers))
|
|
||||||
|
|
||||||
// 获取所有节点在线用户
|
|
||||||
allNodeOnlineUser, err := l.svcCtx.NodeCache.GetAllNodeOnlineUser(l.ctx)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] Get all node online user failed", logger.Field("error", err.Error()))
|
|
||||||
}
|
|
||||||
resp.OnlineUserIPs = int64(len(allNodeOnlineUser))
|
|
||||||
|
|
||||||
// 获取所有节点今日上传下载流量
|
|
||||||
allNodeUploadTraffic, err := l.svcCtx.NodeCache.GetAllNodeUploadTraffic(l.ctx)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] Get all node upload traffic failed", logger.Field("error", err.Error()))
|
|
||||||
}
|
|
||||||
resp.TodayUpload = allNodeUploadTraffic
|
|
||||||
allNodeDownloadTraffic, err := l.svcCtx.NodeCache.GetAllNodeDownloadTraffic(l.ctx)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] Get all node download traffic failed", logger.Field("error", err.Error()))
|
|
||||||
}
|
|
||||||
resp.TodayDownload = allNodeDownloadTraffic
|
|
||||||
// 获取节点流量排行榜 前10
|
|
||||||
nodeTrafficRankingToday, err := l.svcCtx.NodeCache.GetNodeTodayTotalTrafficRank(l.ctx, 10)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] Get node today total traffic rank failed", logger.Field("error", err.Error()))
|
|
||||||
}
|
|
||||||
if len(nodeTrafficRankingToday) > 0 {
|
|
||||||
var serverTrafficData []types.ServerTrafficData
|
|
||||||
for _, rank := range nodeTrafficRankingToday {
|
|
||||||
serverInfo, err := l.svcCtx.ServerModel.FindOne(l.ctx, rank.ID)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] FindOne error", logger.Field("error", err))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
serverTrafficData = append(serverTrafficData, types.ServerTrafficData{
|
|
||||||
ServerId: rank.ID,
|
|
||||||
Name: serverInfo.Name,
|
|
||||||
Upload: rank.Upload,
|
|
||||||
Download: rank.Download,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
resp.ServerTrafficRankingToday = serverTrafficData
|
|
||||||
}
|
|
||||||
// 获取用户流量排行榜 前10
|
|
||||||
userTrafficRankingToday, err := l.svcCtx.NodeCache.GetUserTodayTotalTrafficRank(l.ctx, 10)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] Get user today total traffic rank failed", logger.Field("error", err.Error()))
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(userTrafficRankingToday) > 0 {
|
|
||||||
var userTrafficData []types.UserTrafficData
|
|
||||||
for _, rank := range userTrafficRankingToday {
|
|
||||||
userTrafficData = append(userTrafficData, types.UserTrafficData{
|
|
||||||
SID: rank.SID,
|
|
||||||
Upload: rank.Upload,
|
|
||||||
Download: rank.Download,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
resp.UserTrafficRankingToday = userTrafficData
|
|
||||||
}
|
|
||||||
// 获取昨日节点流量排行榜 前10
|
|
||||||
nodeTrafficRankingYesterday, err := l.svcCtx.NodeCache.GetYesterdayNodeTotalTrafficRank(l.ctx)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] Get yesterday node total traffic rank failed", logger.Field("error", err.Error()))
|
|
||||||
}
|
|
||||||
if len(nodeTrafficRankingYesterday) > 0 {
|
|
||||||
var serverTrafficData []types.ServerTrafficData
|
|
||||||
for _, rank := range nodeTrafficRankingYesterday {
|
|
||||||
serverTrafficData = append(serverTrafficData, types.ServerTrafficData{
|
|
||||||
ServerId: rank.ID,
|
|
||||||
Name: rank.Name,
|
|
||||||
Upload: rank.Upload,
|
|
||||||
Download: rank.Download,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
resp.ServerTrafficRankingYesterday = serverTrafficData
|
|
||||||
}
|
|
||||||
// 获取昨日用户流量排行榜 前10
|
|
||||||
userTrafficRankingYesterday, err := l.svcCtx.NodeCache.GetYesterdayUserTotalTrafficRank(l.ctx)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] Get yesterday user total traffic rank failed", logger.Field("error", err.Error()))
|
|
||||||
}
|
|
||||||
if len(userTrafficRankingYesterday) > 0 {
|
|
||||||
var userTrafficData []types.UserTrafficData
|
|
||||||
for _, rank := range userTrafficRankingYesterday {
|
|
||||||
userTrafficData = append(userTrafficData, types.UserTrafficData{
|
|
||||||
SID: rank.SID,
|
|
||||||
Upload: rank.Upload,
|
|
||||||
Download: rank.Download,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
resp.UserTrafficRankingYesterday = userTrafficData
|
|
||||||
}
|
|
||||||
|
|
||||||
// Query node traffic by monthly
|
|
||||||
nodeTraffic, err := l.svcCtx.TrafficLogModel.QueryTrafficByMonthly(l.ctx, time.Now())
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[QueryServerTotalDataLogic] QueryTrafficByMonthly error", logger.Field("error", err.Error()))
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "QueryTrafficByMonthly error: %v", err.Error())
|
|
||||||
}
|
|
||||||
resp.MonthlyUpload = nodeTraffic.Upload
|
|
||||||
resp.MonthlyDownload = nodeTraffic.Download
|
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
64
internal/logic/admin/log/filterBalanceLogLogic.go
Normal file
64
internal/logic/admin/log/filterBalanceLogLogic.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterBalanceLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFilterBalanceLogLogic Filter balance log
|
||||||
|
func NewFilterBalanceLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterBalanceLogLogic {
|
||||||
|
return &FilterBalanceLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterBalanceLogLogic) FilterBalanceLog(req *types.FilterBalanceLogRequest) (resp *types.FilterBalanceLogResponse, err error) {
|
||||||
|
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Type: log.TypeBalance.Uint8(),
|
||||||
|
Data: req.Date,
|
||||||
|
ObjectID: req.UserId,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[FilterBalanceLog] Query User Balance Log Error:", logger.Field("error", err.Error()))
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Query User Balance Log Error")
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]types.BalanceLog, 0)
|
||||||
|
for _, datum := range data {
|
||||||
|
var content log.Balance
|
||||||
|
if err = content.Unmarshal([]byte(datum.Content)); err != nil {
|
||||||
|
l.Errorf("[QueryUserBalanceLog] unmarshal balance log content failed: %v", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, types.BalanceLog{
|
||||||
|
UserId: datum.ObjectID,
|
||||||
|
Amount: content.Amount,
|
||||||
|
Type: content.Type,
|
||||||
|
OrderId: content.OrderId,
|
||||||
|
Balance: content.Balance,
|
||||||
|
Timestamp: content.Timestamp,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.FilterBalanceLogResponse{
|
||||||
|
Total: total,
|
||||||
|
List: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
61
internal/logic/admin/log/filterCommissionLogLogic.go
Normal file
61
internal/logic/admin/log/filterCommissionLogLogic.go
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterCommissionLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFilterCommissionLogLogic Filter commission log
|
||||||
|
func NewFilterCommissionLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterCommissionLogLogic {
|
||||||
|
return &FilterCommissionLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterCommissionLogLogic) FilterCommissionLog(req *types.FilterCommissionLogRequest) (resp *types.FilterCommissionLogResponse, err error) {
|
||||||
|
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Data: req.Date,
|
||||||
|
Type: log.TypeCommission.Uint8(),
|
||||||
|
ObjectID: req.UserId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("Query User Commission Log failed", logger.Field("error", err.Error()))
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Query User Commission Log failed")
|
||||||
|
}
|
||||||
|
var list []types.CommissionLog
|
||||||
|
|
||||||
|
for _, datum := range data {
|
||||||
|
var content log.Commission
|
||||||
|
if err = content.Unmarshal([]byte(datum.Content)); err != nil {
|
||||||
|
l.Errorf("unmarshal commission log content failed: %v", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, types.CommissionLog{
|
||||||
|
UserId: datum.ObjectID,
|
||||||
|
Type: content.Type,
|
||||||
|
Amount: content.Amount,
|
||||||
|
OrderNo: content.OrderNo,
|
||||||
|
CreatedAt: content.CreatedAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &types.FilterCommissionLogResponse{
|
||||||
|
Total: total,
|
||||||
|
List: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
68
internal/logic/admin/log/filterEmailLogLogic.go
Normal file
68
internal/logic/admin/log/filterEmailLogLogic.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterEmailLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFilterEmailLogLogic Filter email log
|
||||||
|
func NewFilterEmailLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterEmailLogLogic {
|
||||||
|
return &FilterEmailLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterEmailLogLogic) FilterEmailLog(req *types.FilterLogParams) (resp *types.FilterEmailLogResponse, err error) {
|
||||||
|
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Type: log.TypeEmailMessage.Uint8(),
|
||||||
|
Data: req.Date,
|
||||||
|
Search: req.Search,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterEmailLog] failed to filter system log: %v", err.Error())
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []types.MessageLog
|
||||||
|
|
||||||
|
for _, datum := range data {
|
||||||
|
var content log.Message
|
||||||
|
err = content.Unmarshal([]byte(datum.Content))
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterEmailLog] failed to unmarshal content: %v", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, types.MessageLog{
|
||||||
|
Id: datum.Id,
|
||||||
|
Type: datum.Type,
|
||||||
|
Platform: content.Platform,
|
||||||
|
To: content.To,
|
||||||
|
Subject: content.Subject,
|
||||||
|
Content: content.Content,
|
||||||
|
Status: content.Status,
|
||||||
|
CreatedAt: datum.CreatedAt.UnixMilli(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.FilterEmailLogResponse{
|
||||||
|
Total: total,
|
||||||
|
List: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
68
internal/logic/admin/log/filterGiftLogLogic.go
Normal file
68
internal/logic/admin/log/filterGiftLogLogic.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterGiftLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter gift log
|
||||||
|
func NewFilterGiftLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterGiftLogLogic {
|
||||||
|
return &FilterGiftLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterGiftLogLogic) FilterGiftLog(req *types.FilterGiftLogRequest) (resp *types.FilterGiftLogResponse, err error) {
|
||||||
|
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Type: log.TypeGift.Uint8(),
|
||||||
|
ObjectID: req.UserId,
|
||||||
|
Data: req.Date,
|
||||||
|
Search: req.Search,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterGiftLog] failed to filter system log: %v", err.Error())
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []types.GiftLog
|
||||||
|
for _, datum := range data {
|
||||||
|
var content log.Gift
|
||||||
|
err = content.Unmarshal([]byte(datum.Content))
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterGiftLog] failed to unmarshal content: %v", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, types.GiftLog{
|
||||||
|
Type: content.Type,
|
||||||
|
UserId: datum.ObjectID,
|
||||||
|
OrderNo: content.OrderNo,
|
||||||
|
SubscribeId: content.SubscribeId,
|
||||||
|
Amount: content.Amount,
|
||||||
|
Balance: content.Balance,
|
||||||
|
Remark: content.Remark,
|
||||||
|
CreatedAt: content.CreatedAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.FilterGiftLogResponse{
|
||||||
|
Total: total,
|
||||||
|
List: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
65
internal/logic/admin/log/filterLoginLogLogic.go
Normal file
65
internal/logic/admin/log/filterLoginLogLogic.go
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterLoginLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFilterLoginLogLogic Filter login log
|
||||||
|
func NewFilterLoginLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterLoginLogLogic {
|
||||||
|
return &FilterLoginLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterLoginLogLogic) FilterLoginLog(req *types.FilterLoginLogRequest) (resp *types.FilterLoginLogResponse, err error) {
|
||||||
|
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Type: log.TypeLogin.Uint8(),
|
||||||
|
ObjectID: req.UserId,
|
||||||
|
Data: req.Date,
|
||||||
|
Search: req.Search,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterLoginLog] failed to filter system log: %v", err.Error())
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
|
||||||
|
}
|
||||||
|
var list []types.LoginLog
|
||||||
|
for _, datum := range data {
|
||||||
|
var item log.Login
|
||||||
|
err = item.Unmarshal([]byte(datum.Content))
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterLoginLog] failed to unmarshal content: %v", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, types.LoginLog{
|
||||||
|
UserId: datum.ObjectID,
|
||||||
|
Method: item.Method,
|
||||||
|
LoginIP: item.LoginIP,
|
||||||
|
UserAgent: item.UserAgent,
|
||||||
|
Success: item.Success,
|
||||||
|
LoginTime: item.LoginTime,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.FilterLoginLogResponse{
|
||||||
|
Total: total,
|
||||||
|
List: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
68
internal/logic/admin/log/filterMobileLogLogic.go
Normal file
68
internal/logic/admin/log/filterMobileLogLogic.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterMobileLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter mobile log
|
||||||
|
func NewFilterMobileLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterMobileLogLogic {
|
||||||
|
return &FilterMobileLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterMobileLogLogic) FilterMobileLog(req *types.FilterLogParams) (resp *types.FilterMobileLogResponse, err error) {
|
||||||
|
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Type: log.TypeMobileMessage.Uint8(),
|
||||||
|
Data: req.Date,
|
||||||
|
Search: req.Search,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterMobileLog] failed to filter system log: %v", err.Error())
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []types.MessageLog
|
||||||
|
|
||||||
|
for _, datum := range data {
|
||||||
|
var content log.Message
|
||||||
|
err = content.Unmarshal([]byte(datum.Content))
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterMobileLog] failed to unmarshal content: %v", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, types.MessageLog{
|
||||||
|
Id: datum.Id,
|
||||||
|
Type: datum.Type,
|
||||||
|
Platform: content.Platform,
|
||||||
|
To: content.To,
|
||||||
|
Subject: content.Subject,
|
||||||
|
Content: content.Content,
|
||||||
|
Status: content.Status,
|
||||||
|
CreatedAt: datum.CreatedAt.UnixMilli(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.FilterMobileLogResponse{
|
||||||
|
Total: total,
|
||||||
|
List: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
66
internal/logic/admin/log/filterRegisterLogLogic.go
Normal file
66
internal/logic/admin/log/filterRegisterLogLogic.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterRegisterLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter register log
|
||||||
|
func NewFilterRegisterLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterRegisterLogLogic {
|
||||||
|
return &FilterRegisterLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterRegisterLogLogic) FilterRegisterLog(req *types.FilterRegisterLogRequest) (resp *types.FilterRegisterLogResponse, err error) {
|
||||||
|
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Type: log.TypeRegister.Uint8(),
|
||||||
|
ObjectID: req.UserId,
|
||||||
|
Data: req.Date,
|
||||||
|
Search: req.Search,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterRegisterLog] failed to filter system log: %v", err.Error())
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []types.RegisterLog
|
||||||
|
for _, datum := range data {
|
||||||
|
var item log.Register
|
||||||
|
err = item.Unmarshal([]byte(datum.Content))
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterLoginLog] failed to unmarshal content: %v", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, types.RegisterLog{
|
||||||
|
UserId: datum.ObjectID,
|
||||||
|
AuthMethod: item.AuthMethod,
|
||||||
|
Identifier: item.Identifier,
|
||||||
|
RegisterIP: item.RegisterIP,
|
||||||
|
UserAgent: item.UserAgent,
|
||||||
|
RegisterTime: item.RegisterTime,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.FilterRegisterLogResponse{
|
||||||
|
List: list,
|
||||||
|
Total: total,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
66
internal/logic/admin/log/filterResetSubscribeLogLogic.go
Normal file
66
internal/logic/admin/log/filterResetSubscribeLogLogic.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterResetSubscribeLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFilterResetSubscribeLogLogic Filter reset subscribe log
|
||||||
|
func NewFilterResetSubscribeLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterResetSubscribeLogLogic {
|
||||||
|
return &FilterResetSubscribeLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterResetSubscribeLogLogic) FilterResetSubscribeLog(req *types.FilterResetSubscribeLogRequest) (resp *types.FilterResetSubscribeLogResponse, err error) {
|
||||||
|
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Type: log.TypeRegister.Uint8(),
|
||||||
|
ObjectID: req.UserSubscribeId,
|
||||||
|
Data: req.Date,
|
||||||
|
Search: req.Search,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterResetSubscribeLog] failed to filter system log: %v", err.Error())
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []types.ResetSubscribeLog
|
||||||
|
|
||||||
|
for _, item := range data {
|
||||||
|
var content log.ResetSubscribe
|
||||||
|
err = content.Unmarshal([]byte(item.Content))
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterResetSubscribeLog] failed to unmarshal content: %v", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, types.ResetSubscribeLog{
|
||||||
|
Type: content.Type,
|
||||||
|
UserId: content.UserId,
|
||||||
|
UserSubscribeId: item.ObjectID,
|
||||||
|
OrderNo: content.OrderNo,
|
||||||
|
ResetAt: content.ResetAt,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.FilterResetSubscribeLogResponse{
|
||||||
|
List: list,
|
||||||
|
Total: total,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
43
internal/logic/admin/log/filterServerTrafficLogLogic.go
Normal file
43
internal/logic/admin/log/filterServerTrafficLogLogic.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterServerTrafficLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFilterServerTrafficLogLogic Filter server traffic log
|
||||||
|
func NewFilterServerTrafficLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterServerTrafficLogLogic {
|
||||||
|
return &FilterServerTrafficLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterServerTrafficLogLogic) FilterServerTrafficLog(req *types.FilterServerTrafficLogRequest) (resp *types.FilterServerTrafficLogResponse, err error) {
|
||||||
|
today := time.Now().Format("2006-01-02")
|
||||||
|
if req.Date == "" || req.Date == today {
|
||||||
|
return l.handlerToday(req)
|
||||||
|
} else {
|
||||||
|
return l.handlerSpecify(req)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterServerTrafficLogLogic) handlerToday(req *types.FilterServerTrafficLogRequest) (resp *types.FilterServerTrafficLogResponse, err error) {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterServerTrafficLogLogic) handlerSpecify(req *types.FilterServerTrafficLogRequest) (resp *types.FilterServerTrafficLogResponse, err error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
64
internal/logic/admin/log/filterSubscribeLogLogic.go
Normal file
64
internal/logic/admin/log/filterSubscribeLogLogic.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/log"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterSubscribeLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter subscribe log
|
||||||
|
func NewFilterSubscribeLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterSubscribeLogLogic {
|
||||||
|
return &FilterSubscribeLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterSubscribeLogLogic) FilterSubscribeLog(req *types.FilterSubscribeLogRequest) (resp *types.FilterSubscribeLogResponse, err error) {
|
||||||
|
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Type: log.TypeSubscribe.Uint8(),
|
||||||
|
Data: req.Date,
|
||||||
|
ObjectID: req.UserId,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterSubscribeLog] failed to filter system log: %v", err.Error())
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "failed to filter system log")
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []types.SubscribeLog
|
||||||
|
for _, datum := range data {
|
||||||
|
var content log.Subscribe
|
||||||
|
err = content.Unmarshal([]byte(datum.Content))
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterSubscribeLog] failed to unmarshal content: %v", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
list = append(list, types.SubscribeLog{
|
||||||
|
UserId: datum.ObjectID,
|
||||||
|
Token: content.Token,
|
||||||
|
UserAgent: content.UserAgent,
|
||||||
|
ClientIP: content.ClientIP,
|
||||||
|
UserSubscribeId: content.UserSubscribeId,
|
||||||
|
SubscribedAt: datum.CreatedAt.UnixMilli(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.FilterSubscribeLogResponse{
|
||||||
|
Total: total,
|
||||||
|
List: list,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterUserSubscribeTrafficLogLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFilterUserSubscribeTrafficLogLogic Filter user subscribe traffic log
|
||||||
|
func NewFilterUserSubscribeTrafficLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterUserSubscribeTrafficLogLogic {
|
||||||
|
return &FilterUserSubscribeTrafficLogLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterUserSubscribeTrafficLogLogic) FilterUserSubscribeTrafficLog(req *types.FilterSubscribeTrafficRequest) (resp *types.FilterSubscribeTrafficResponse, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
@ -2,18 +2,13 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/perfect-panel/server/internal/model/node"
|
||||||
"github.com/perfect-panel/server/internal/model/server"
|
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/logger"
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
"github.com/perfect-panel/server/pkg/tool"
|
"github.com/perfect-panel/server/pkg/tool"
|
||||||
"github.com/perfect-panel/server/pkg/xerr"
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
queue "github.com/perfect-panel/server/queue/types"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,6 +18,7 @@ type CreateNodeLogic struct {
|
|||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCreateNodeLogic Create Node
|
||||||
func NewCreateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateNodeLogic {
|
func NewCreateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateNodeLogic {
|
||||||
return &CreateNodeLogic{
|
return &CreateNodeLogic{
|
||||||
Logger: logger.WithContext(ctx),
|
Logger: logger.WithContext(ctx),
|
||||||
@ -32,97 +28,18 @@ func NewCreateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *CreateNodeLogic) CreateNode(req *types.CreateNodeRequest) error {
|
func (l *CreateNodeLogic) CreateNode(req *types.CreateNodeRequest) error {
|
||||||
config, err := json.Marshal(req.Config)
|
data := node.Node{
|
||||||
if err != nil {
|
Name: req.Name,
|
||||||
return err
|
Tags: tool.StringSliceToString(req.Tags),
|
||||||
|
Port: req.Port,
|
||||||
|
Address: req.Address,
|
||||||
|
ServerId: req.ServerId,
|
||||||
|
Protocol: req.Protocol,
|
||||||
}
|
}
|
||||||
var serverInfo server.Server
|
err := l.svcCtx.NodeModel.InsertNode(l.ctx, &data)
|
||||||
tool.DeepCopy(&serverInfo, req)
|
|
||||||
serverInfo.Config = string(config)
|
|
||||||
nodeRelay, err := json.Marshal(req.RelayNode)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[UpdateNode] Marshal RelayNode Error: ", logger.Field("error", err.Error()))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(req.Tags) > 0 {
|
|
||||||
serverInfo.Tags = strings.Join(req.Tags, ",")
|
|
||||||
}
|
|
||||||
|
|
||||||
serverInfo.LastReportedAt = time.UnixMicro(1218124800)
|
|
||||||
|
|
||||||
serverInfo.City = req.City
|
|
||||||
serverInfo.Country = req.Country
|
|
||||||
|
|
||||||
serverInfo.RelayNode = string(nodeRelay)
|
|
||||||
if req.Protocol == "vless" {
|
|
||||||
var cfg types.Vless
|
|
||||||
if err = json.Unmarshal(config, &cfg); err != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
|
|
||||||
}
|
|
||||||
if cfg.Security == "reality" && cfg.SecurityConfig.RealityPublicKey == "" {
|
|
||||||
public, private, err := tool.Curve25519Genkey(false, "")
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate curve25519 key error")
|
|
||||||
}
|
|
||||||
cfg.SecurityConfig.RealityPublicKey = public
|
|
||||||
cfg.SecurityConfig.RealityPrivateKey = private
|
|
||||||
cfg.SecurityConfig.RealityShortId = tool.GenerateShortID(private)
|
|
||||||
}
|
|
||||||
if cfg.SecurityConfig.RealityServerAddr == "" {
|
|
||||||
cfg.SecurityConfig.RealityServerAddr = cfg.SecurityConfig.SNI
|
|
||||||
}
|
|
||||||
if cfg.SecurityConfig.RealityServerPort == 0 {
|
|
||||||
cfg.SecurityConfig.RealityServerPort = 443
|
|
||||||
}
|
|
||||||
config, _ = json.Marshal(cfg)
|
|
||||||
serverInfo.Config = string(config)
|
|
||||||
} else if req.Protocol == "shadowsocks" {
|
|
||||||
var cfg types.Shadowsocks
|
|
||||||
if err = json.Unmarshal(config, &cfg); err != nil {
|
|
||||||
l.Errorf("[CreateNode] Unmarshal Shadowsocks Config Error: %v", err.Error())
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
|
|
||||||
}
|
|
||||||
if strings.Contains(cfg.Method, "2022") {
|
|
||||||
var length int
|
|
||||||
switch cfg.Method {
|
|
||||||
case "2022-blake3-aes-128-gcm":
|
|
||||||
length = 16
|
|
||||||
default:
|
|
||||||
length = 32
|
|
||||||
}
|
|
||||||
if len(cfg.ServerKey) != length {
|
|
||||||
cfg.ServerKey = tool.GenerateCipher(cfg.ServerKey, length)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
config, _ = json.Marshal(cfg)
|
|
||||||
serverInfo.Config = string(config)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = l.svcCtx.ServerModel.Insert(l.ctx, &serverInfo)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Errorw("[CreateNode] Insert Database Error: ", logger.Field("error", err.Error()))
|
l.Errorw("[CreateNode] Insert Database Error: ", logger.Field("error", err.Error()))
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create server error: %v", err)
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "[CreateNode] Insert Database Error")
|
||||||
}
|
|
||||||
|
|
||||||
if req.City == "" || req.Country == "" {
|
|
||||||
// Marshal the task payload
|
|
||||||
payload, err := json.Marshal(queue.GetNodeCountry{
|
|
||||||
Protocol: serverInfo.Protocol,
|
|
||||||
ServerAddr: serverInfo.ServerAddr,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[GetNodeCountry]: Marshal Error", logger.Field("error", err.Error()))
|
|
||||||
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to marshal task payload")
|
|
||||||
}
|
|
||||||
// Create a queue task
|
|
||||||
task := asynq.NewTask(queue.ForthwithGetCountry, payload)
|
|
||||||
// Enqueue the task
|
|
||||||
taskInfo, err := l.svcCtx.Queue.Enqueue(task)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[GetNodeCountry]: Enqueue Error", logger.Field("error", err.Error()), logger.Field("payload", string(payload)))
|
|
||||||
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to enqueue task")
|
|
||||||
}
|
|
||||||
l.Infow("[GetNodeCountry]: Enqueue Success", logger.Field("taskID", taskInfo.ID), logger.Field("payload", string(payload)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
111
internal/logic/admin/server/createServerLogic.go
Normal file
111
internal/logic/admin/server/createServerLogic.go
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/node"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/ip"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/tool"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreateServerLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCreateServerLogic Create Server
|
||||||
|
func NewCreateServerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateServerLogic {
|
||||||
|
return &CreateServerLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *CreateServerLogic) CreateServer(req *types.CreateServerRequest) error {
|
||||||
|
data := node.Server{
|
||||||
|
Name: req.Name,
|
||||||
|
Country: req.Country,
|
||||||
|
City: req.City,
|
||||||
|
Ratio: req.Ratio,
|
||||||
|
Address: req.Address,
|
||||||
|
Sort: req.Sort,
|
||||||
|
Protocols: "",
|
||||||
|
}
|
||||||
|
protocols := make([]node.Protocol, 0)
|
||||||
|
for _, item := range req.Protocols {
|
||||||
|
if item.Type == "" {
|
||||||
|
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.InvalidParams, "protocols type is empty"), "protocols type is empty")
|
||||||
|
}
|
||||||
|
var protocol node.Protocol
|
||||||
|
tool.DeepCopy(&protocol, item)
|
||||||
|
|
||||||
|
// VLESS Reality Key Generation
|
||||||
|
if protocol.Type == "vless" {
|
||||||
|
if protocol.Security == "reality" {
|
||||||
|
if protocol.RealityPublicKey == "" {
|
||||||
|
public, private, err := tool.Curve25519Genkey(false, "")
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[CreateServer] Generate Reality Key Error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate reality key error: %v", err)
|
||||||
|
}
|
||||||
|
protocol.RealityPublicKey = public
|
||||||
|
protocol.RealityPrivateKey = private
|
||||||
|
protocol.RealityShortId = tool.GenerateShortID(private)
|
||||||
|
}
|
||||||
|
if protocol.RealityServerAddr == "" {
|
||||||
|
protocol.RealityServerAddr = protocol.SNI
|
||||||
|
}
|
||||||
|
if protocol.RealityServerPort == 0 {
|
||||||
|
protocol.RealityServerPort = 443
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// ShadowSocks 2022 Key Generation
|
||||||
|
if protocol.Type == "shadowsocks" {
|
||||||
|
if strings.Contains(protocol.Cipher, "2022") {
|
||||||
|
var length int
|
||||||
|
switch protocol.Cipher {
|
||||||
|
case "2022-blake3-aes-128-gcm":
|
||||||
|
length = 16
|
||||||
|
default:
|
||||||
|
length = 32
|
||||||
|
}
|
||||||
|
if len(protocol.ServerKey) != length {
|
||||||
|
protocol.ServerKey = tool.GenerateCipher(protocol.ServerKey, length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protocols = append(protocols, protocol)
|
||||||
|
}
|
||||||
|
|
||||||
|
err := data.MarshalProtocols(protocols)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[CreateServer] Marshal Protocols Error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.InvalidParams, "protocols marshal error"), "protocols marshal error: %v", err)
|
||||||
|
}
|
||||||
|
if data.City == "" && data.Country == "" {
|
||||||
|
// query server ip location
|
||||||
|
result, err := ip.GetRegionByIp(req.Address)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[CreateServer] GetRegionByIp Error: %v", err.Error())
|
||||||
|
} else {
|
||||||
|
data.City = result.City
|
||||||
|
data.Country = result.Country
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = l.svcCtx.NodeModel.InsertServer(l.ctx, &data)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[CreateServer] Insert Server error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "insert server error: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -2,14 +2,12 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/perfect-panel/server/pkg/tool"
|
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
"github.com/perfect-panel/server/pkg/logger"
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
"github.com/perfect-panel/server/pkg/xerr"
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DeleteNodeLogic struct {
|
type DeleteNodeLogic struct {
|
||||||
@ -18,6 +16,7 @@ type DeleteNodeLogic struct {
|
|||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDeleteNodeLogic Delete Node
|
||||||
func NewDeleteNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteNodeLogic {
|
func NewDeleteNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteNodeLogic {
|
||||||
return &DeleteNodeLogic{
|
return &DeleteNodeLogic{
|
||||||
Logger: logger.WithContext(ctx),
|
Logger: logger.WithContext(ctx),
|
||||||
@ -27,33 +26,10 @@ func NewDeleteNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *DeleteNodeLogic) DeleteNode(req *types.DeleteNodeRequest) error {
|
func (l *DeleteNodeLogic) DeleteNode(req *types.DeleteNodeRequest) error {
|
||||||
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
|
err := l.svcCtx.NodeModel.DeleteNode(l.ctx, req.Id)
|
||||||
// Delete server
|
|
||||||
err := l.svcCtx.ServerModel.Delete(l.ctx, req.Id, tx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Delete server to subscribe
|
|
||||||
subs, err := l.svcCtx.SubscribeModel.QuerySubscribeIdsByServerIdAndServerGroupId(l.ctx, req.Id, 0)
|
|
||||||
if err != nil {
|
|
||||||
l.Logger.Errorf("[DeleteNode] QuerySubscribeIdsByServerIdAndServerGroupId error: %v", err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, sub := range subs {
|
|
||||||
servers := tool.StringToInt64Slice(sub.Server)
|
|
||||||
newServers := tool.RemoveElementBySlice(servers, req.Id)
|
|
||||||
sub.Server = tool.Int64SliceToString(newServers)
|
|
||||||
if err = l.svcCtx.SubscribeModel.Update(l.ctx, sub, tx); err != nil {
|
|
||||||
l.Logger.Errorf("[DeleteNode] UpdateSubscribe error: %v", err.Error())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Errorw("[DeleteNode] Delete Database Error: ", logger.Field("error", err.Error()))
|
l.Errorw("[DeleteNode] Delete Database Error: ", logger.Field("error", err.Error()))
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseDeletedError), "delete server error: %v", err)
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseDeletedError), "[DeleteNode] Delete Database Error")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
30
internal/logic/admin/server/deleteServerLogic.go
Normal file
30
internal/logic/admin/server/deleteServerLogic.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DeleteServerLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDeleteServerLogic Delete Server
|
||||||
|
func NewDeleteServerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteServerLogic {
|
||||||
|
return &DeleteServerLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *DeleteServerLogic) DeleteServer(req *types.DeleteServerRequest) error {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
49
internal/logic/admin/server/filterNodeListLogic.go
Normal file
49
internal/logic/admin/server/filterNodeListLogic.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/node"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/tool"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterNodeListLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFilterNodeListLogic Filter Node List
|
||||||
|
func NewFilterNodeListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterNodeListLogic {
|
||||||
|
return &FilterNodeListLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterNodeListLogic) FilterNodeList(req *types.FilterNodeListRequest) (resp *types.FilterNodeListResponse, err error) {
|
||||||
|
total, data, err := l.svcCtx.NodeModel.FilterNodeList(l.ctx, &node.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Search: req.Search,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[FilterNodeList] Query Database Error: ", logger.Field("error", err.Error()))
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[FilterNodeList] Query Database Error")
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]types.Node, 0)
|
||||||
|
tool.DeepCopy(&list, data)
|
||||||
|
|
||||||
|
return &types.FilterNodeListResponse{
|
||||||
|
List: list,
|
||||||
|
Total: total,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
119
internal/logic/admin/server/filterServerListLogic.go
Normal file
119
internal/logic/admin/server/filterServerListLogic.go
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/node"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/tool"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FilterServerListLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFilterServerListLogic Filter Server List
|
||||||
|
func NewFilterServerListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterServerListLogic {
|
||||||
|
return &FilterServerListLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterServerListLogic) FilterServerList(req *types.FilterServerListRequest) (resp *types.FilterServerListResponse, err error) {
|
||||||
|
total, data, err := l.svcCtx.NodeModel.FilterServerList(l.ctx, &node.FilterParams{
|
||||||
|
Page: req.Page,
|
||||||
|
Size: req.Size,
|
||||||
|
Search: req.Search,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[FilterServerList] Query Database Error: ", logger.Field("error", err.Error()))
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[FilterServerList] Query Database Error")
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]types.Server, 0)
|
||||||
|
|
||||||
|
for _, datum := range data {
|
||||||
|
var server types.Server
|
||||||
|
tool.DeepCopy(&server, datum)
|
||||||
|
|
||||||
|
// handler protocols
|
||||||
|
var protocols []types.Protocol
|
||||||
|
dst, err := datum.UnmarshalProtocols()
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[FilterServerList] UnmarshalProtocols Error: %s", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tool.DeepCopy(&protocols, dst)
|
||||||
|
server.Protocols = protocols
|
||||||
|
// handler status
|
||||||
|
server.Status = l.handlerServerStatus(datum.Id)
|
||||||
|
list = append(list, server)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.FilterServerListResponse{
|
||||||
|
List: list,
|
||||||
|
Total: total,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *FilterServerListLogic) handlerServerStatus(id int64) types.ServerStatus {
|
||||||
|
var result types.ServerStatus
|
||||||
|
nodeStatus, err := l.svcCtx.NodeCache.GetNodeStatus(l.ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[handlerServerStatus] GetNodeStatus Error: ", logger.Field("error", err.Error()), logger.Field("node_id", id))
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
result = types.ServerStatus{
|
||||||
|
Mem: nodeStatus.Mem,
|
||||||
|
Cpu: nodeStatus.Cpu,
|
||||||
|
Disk: nodeStatus.Disk,
|
||||||
|
Online: make([]types.ServerOnlineUser, 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse online users
|
||||||
|
onlineUser, err := l.svcCtx.NodeCache.GetNodeOnlineUser(l.ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[handlerServerStatus] GetNodeOnlineUser Error: ", logger.Field("error", err.Error()), logger.Field("node_id", id))
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
var onlineList []types.ServerOnlineUser
|
||||||
|
var onlineMap = make(map[int64]types.ServerOnlineUser)
|
||||||
|
// group by user_id
|
||||||
|
for subId, info := range onlineUser {
|
||||||
|
data, err := l.svcCtx.UserModel.FindOneUserSubscribe(l.ctx, subId)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[handlerServerStatus] FindOneSubscribe Error: ", logger.Field("error", err.Error()))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if online, exist := onlineMap[data.UserId]; !exist {
|
||||||
|
onlineMap[data.UserId] = types.ServerOnlineUser{
|
||||||
|
IP: info,
|
||||||
|
UserId: data.UserId,
|
||||||
|
Subscribe: data.Subscribe.Name,
|
||||||
|
SubscribeId: data.SubscribeId,
|
||||||
|
Traffic: data.Traffic,
|
||||||
|
ExpiredAt: data.ExpireTime.UnixMilli(),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
online.IP = append(online.IP, info...)
|
||||||
|
onlineMap[data.UserId] = online
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, online := range onlineMap {
|
||||||
|
onlineList = append(onlineList, online)
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Online = onlineList
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
30
internal/logic/admin/server/getServerProtocolsLogic.go
Normal file
30
internal/logic/admin/server/getServerProtocolsLogic.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetServerProtocolsLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Server Protocols
|
||||||
|
func NewGetServerProtocolsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetServerProtocolsLogic {
|
||||||
|
return &GetServerProtocolsLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetServerProtocolsLogic) GetServerProtocols(req *types.GetServerProtocolsRequest) (resp *types.GetServerProtocolsResponse, err error) {
|
||||||
|
// todo: add your logic here and delete this line
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
43
internal/logic/admin/server/toggleNodeStatusLogic.go
Normal file
43
internal/logic/admin/server/toggleNodeStatusLogic.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ToggleNodeStatusLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewToggleNodeStatusLogic Toggle Node Status
|
||||||
|
func NewToggleNodeStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ToggleNodeStatusLogic {
|
||||||
|
return &ToggleNodeStatusLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ToggleNodeStatusLogic) ToggleNodeStatus(req *types.ToggleNodeStatusRequest) error {
|
||||||
|
data, err := l.svcCtx.NodeModel.FindOneNode(l.ctx, req.Id)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[ToggleNodeStatus] Query Database Error: ", logger.Field("error", err.Error()))
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[ToggleNodeStatus] Query Database Error")
|
||||||
|
}
|
||||||
|
data.Enabled = req.Enable
|
||||||
|
|
||||||
|
err = l.svcCtx.NodeModel.UpdateNode(l.ctx, data)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[ToggleNodeStatus] Update Database Error: ", logger.Field("error", err.Error()))
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "[ToggleNodeStatus] Update Database Error")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -2,12 +2,6 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
|
||||||
"github.com/perfect-panel/server/pkg/device"
|
|
||||||
queue "github.com/perfect-panel/server/queue/types"
|
|
||||||
|
|
||||||
"github.com/perfect-panel/server/internal/svc"
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
"github.com/perfect-panel/server/internal/types"
|
"github.com/perfect-panel/server/internal/types"
|
||||||
@ -23,6 +17,7 @@ type UpdateNodeLogic struct {
|
|||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewUpdateNodeLogic Update Node
|
||||||
func NewUpdateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateNodeLogic {
|
func NewUpdateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateNodeLogic {
|
||||||
return &UpdateNodeLogic{
|
return &UpdateNodeLogic{
|
||||||
Logger: logger.WithContext(ctx),
|
Logger: logger.WithContext(ctx),
|
||||||
@ -32,108 +27,20 @@ func NewUpdateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *UpdateNodeLogic) UpdateNode(req *types.UpdateNodeRequest) error {
|
func (l *UpdateNodeLogic) UpdateNode(req *types.UpdateNodeRequest) error {
|
||||||
// Check server exist
|
data, err := l.svcCtx.NodeModel.FindOneNode(l.ctx, req.Id)
|
||||||
nodeInfo, err := l.svcCtx.ServerModel.FindOne(l.ctx, req.Id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find server error: %v", err)
|
l.Errorw("[UpdateNode] Query Database Error: ", logger.Field("error", err.Error()))
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "[UpdateNode] Query Database Error")
|
||||||
}
|
}
|
||||||
tool.DeepCopy(nodeInfo, req, tool.CopyWithIgnoreEmpty(false))
|
data.Name = req.Name
|
||||||
config, err := json.Marshal(req.Config)
|
data.Tags = tool.StringSliceToString(req.Tags)
|
||||||
if err != nil {
|
data.Port = req.Port
|
||||||
return err
|
data.Address = req.Address
|
||||||
}
|
data.Protocol = req.Protocol
|
||||||
|
err = l.svcCtx.NodeModel.UpdateNode(l.ctx, data)
|
||||||
nodeInfo.Config = string(config)
|
|
||||||
nodeRelay, err := json.Marshal(req.RelayNode)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[UpdateNode] Marshal RelayNode Error: ", logger.Field("error", err.Error()))
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理Tags字段
|
|
||||||
switch {
|
|
||||||
case len(req.Tags) > 0:
|
|
||||||
// 有Tags,进行连接
|
|
||||||
nodeInfo.Tags = strings.Join(req.Tags, ",")
|
|
||||||
default:
|
|
||||||
// 空数组,清空Tags
|
|
||||||
nodeInfo.Tags = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeInfo.City = req.City
|
|
||||||
nodeInfo.Country = req.Country
|
|
||||||
|
|
||||||
nodeInfo.RelayNode = string(nodeRelay)
|
|
||||||
if req.Protocol == "vless" {
|
|
||||||
var cfg types.Vless
|
|
||||||
if err := json.Unmarshal(config, &cfg); err != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
|
|
||||||
}
|
|
||||||
if cfg.Security == "reality" && cfg.SecurityConfig.RealityPublicKey == "" {
|
|
||||||
public, private, err := tool.Curve25519Genkey(false, "")
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate curve25519 key error")
|
|
||||||
}
|
|
||||||
cfg.SecurityConfig.RealityPublicKey = public
|
|
||||||
cfg.SecurityConfig.RealityPrivateKey = private
|
|
||||||
cfg.SecurityConfig.RealityShortId = tool.GenerateShortID(private)
|
|
||||||
}
|
|
||||||
if cfg.SecurityConfig.RealityServerAddr == "" {
|
|
||||||
cfg.SecurityConfig.RealityServerAddr = cfg.SecurityConfig.SNI
|
|
||||||
}
|
|
||||||
if cfg.SecurityConfig.RealityServerPort == 0 {
|
|
||||||
cfg.SecurityConfig.RealityServerPort = 443
|
|
||||||
}
|
|
||||||
config, _ = json.Marshal(cfg)
|
|
||||||
nodeInfo.Config = string(config)
|
|
||||||
} else if req.Protocol == "shadowsocks" {
|
|
||||||
var cfg types.Shadowsocks
|
|
||||||
if err = json.Unmarshal(config, &cfg); err != nil {
|
|
||||||
l.Errorf("[CreateNode] Unmarshal Shadowsocks Config Error: %v", err.Error())
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
|
|
||||||
}
|
|
||||||
if strings.Contains(cfg.Method, "2022") {
|
|
||||||
var length int
|
|
||||||
switch cfg.Method {
|
|
||||||
case "2022-blake3-aes-128-gcm":
|
|
||||||
length = 16
|
|
||||||
default:
|
|
||||||
length = 32
|
|
||||||
}
|
|
||||||
if len(cfg.ServerKey) != length {
|
|
||||||
cfg.ServerKey = tool.GenerateCipher(cfg.ServerKey, length)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
config, _ = json.Marshal(cfg)
|
|
||||||
nodeInfo.Config = string(config)
|
|
||||||
}
|
|
||||||
err = l.svcCtx.ServerModel.Update(l.ctx, nodeInfo)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Errorw("[UpdateNode] Update Database Error: ", logger.Field("error", err.Error()))
|
l.Errorw("[UpdateNode] Update Database Error: ", logger.Field("error", err.Error()))
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create server error: %v", err)
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "[UpdateNode] Update Database Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.City == "" || req.Country == "" {
|
|
||||||
// Marshal the task payload
|
|
||||||
payload, err := json.Marshal(queue.GetNodeCountry{
|
|
||||||
Protocol: nodeInfo.Protocol,
|
|
||||||
ServerAddr: nodeInfo.ServerAddr,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[GetNodeCountry]: Marshal Error", logger.Field("error", err.Error()))
|
|
||||||
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to marshal task payload")
|
|
||||||
}
|
|
||||||
// Create a queue task
|
|
||||||
task := asynq.NewTask(queue.ForthwithGetCountry, payload)
|
|
||||||
// Enqueue the task
|
|
||||||
taskInfo, err := l.svcCtx.Queue.Enqueue(task)
|
|
||||||
if err != nil {
|
|
||||||
l.Errorw("[GetNodeCountry]: Enqueue Error", logger.Field("error", err.Error()), logger.Field("payload", string(payload)))
|
|
||||||
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to enqueue task")
|
|
||||||
}
|
|
||||||
l.Infow("[GetNodeCountry]: Enqueue Success", logger.Field("taskID", taskInfo.ID), logger.Field("payload", string(payload)))
|
|
||||||
}
|
|
||||||
|
|
||||||
l.svcCtx.DeviceManager.Broadcast(device.SubscribeUpdate)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
115
internal/logic/admin/server/updateServerLogic.go
Normal file
115
internal/logic/admin/server/updateServerLogic.go
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/model/node"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/ip"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/tool"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateServerLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUpdateServerLogic Update Server
|
||||||
|
func NewUpdateServerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateServerLogic {
|
||||||
|
return &UpdateServerLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UpdateServerLogic) UpdateServer(req *types.UpdateServerRequest) error {
|
||||||
|
data, err := l.svcCtx.NodeModel.FindOneServer(l.ctx, req.Id)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[UpdateServer] FindOneServer Error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find server error: %v", err.Error())
|
||||||
|
}
|
||||||
|
data.Name = req.Name
|
||||||
|
data.Country = req.Country
|
||||||
|
data.City = req.City
|
||||||
|
data.Ratio = req.Ratio
|
||||||
|
// only update address when it's different
|
||||||
|
if req.Address != data.Address {
|
||||||
|
// query server ip location
|
||||||
|
result, err := ip.GetRegionByIp(req.Address)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[UpdateServer] GetRegionByIp Error: %v", err.Error())
|
||||||
|
} else {
|
||||||
|
data.City = result.City
|
||||||
|
data.Country = result.Country
|
||||||
|
}
|
||||||
|
// update address
|
||||||
|
data.Address = req.Address
|
||||||
|
}
|
||||||
|
protocols := make([]node.Protocol, 0)
|
||||||
|
for _, item := range req.Protocols {
|
||||||
|
if item.Type == "" {
|
||||||
|
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.InvalidParams, "protocols type is empty"), "protocols type is empty")
|
||||||
|
}
|
||||||
|
var protocol node.Protocol
|
||||||
|
tool.DeepCopy(&protocol, item)
|
||||||
|
|
||||||
|
// VLESS Reality Key Generation
|
||||||
|
if protocol.Type == "vless" {
|
||||||
|
if protocol.Security == "reality" {
|
||||||
|
if protocol.RealityPublicKey == "" {
|
||||||
|
public, private, err := tool.Curve25519Genkey(false, "")
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[CreateServer] Generate Reality Key Error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate reality key error: %v", err)
|
||||||
|
}
|
||||||
|
protocol.RealityPublicKey = public
|
||||||
|
protocol.RealityPrivateKey = private
|
||||||
|
protocol.RealityShortId = tool.GenerateShortID(private)
|
||||||
|
}
|
||||||
|
if protocol.RealityServerAddr == "" {
|
||||||
|
protocol.RealityServerAddr = protocol.SNI
|
||||||
|
}
|
||||||
|
if protocol.RealityServerPort == 0 {
|
||||||
|
protocol.RealityServerPort = 443
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// ShadowSocks 2022 Key Generation
|
||||||
|
if protocol.Type == "shadowsocks" {
|
||||||
|
if strings.Contains(protocol.Cipher, "2022") {
|
||||||
|
var length int
|
||||||
|
switch protocol.Cipher {
|
||||||
|
case "2022-blake3-aes-128-gcm":
|
||||||
|
length = 16
|
||||||
|
default:
|
||||||
|
length = 32
|
||||||
|
}
|
||||||
|
if len(protocol.ServerKey) != length {
|
||||||
|
protocol.ServerKey = tool.GenerateCipher(protocol.ServerKey, length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protocols = append(protocols, protocol)
|
||||||
|
}
|
||||||
|
err = data.MarshalProtocols(protocols)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[UpdateServer] Marshal Protocols Error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCodeMsg(xerr.InvalidParams, "protocols marshal error"), "protocols marshal error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = l.svcCtx.NodeModel.UpdateServer(l.ctx, data)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorf("[UpdateServer] UpdateServer Error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "update server error: %v", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
129
internal/logic/admin/server_bak/createNodeLogic.go
Normal file
129
internal/logic/admin/server_bak/createNodeLogic.go
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
package server_bak
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/hibiken/asynq"
|
||||||
|
"github.com/perfect-panel/server/internal/model/server"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/tool"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
queue "github.com/perfect-panel/server/queue/types"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreateNodeLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCreateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateNodeLogic {
|
||||||
|
return &CreateNodeLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *CreateNodeLogic) CreateNode(req *types.CreateNodeRequest) error {
|
||||||
|
config, err := json.Marshal(req.Config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var serverInfo server.Server
|
||||||
|
tool.DeepCopy(&serverInfo, req)
|
||||||
|
serverInfo.Config = string(config)
|
||||||
|
nodeRelay, err := json.Marshal(req.RelayNode)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[UpdateNode] Marshal RelayNode Error: ", logger.Field("error", err.Error()))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(req.Tags) > 0 {
|
||||||
|
serverInfo.Tags = strings.Join(req.Tags, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
serverInfo.LastReportedAt = time.UnixMicro(1218124800)
|
||||||
|
|
||||||
|
serverInfo.City = req.City
|
||||||
|
serverInfo.Country = req.Country
|
||||||
|
|
||||||
|
serverInfo.RelayNode = string(nodeRelay)
|
||||||
|
if req.Protocol == "vless" {
|
||||||
|
var cfg types.Vless
|
||||||
|
if err = json.Unmarshal(config, &cfg); err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
|
||||||
|
}
|
||||||
|
if cfg.Security == "reality" && cfg.SecurityConfig.RealityPublicKey == "" {
|
||||||
|
public, private, err := tool.Curve25519Genkey(false, "")
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate curve25519 key error")
|
||||||
|
}
|
||||||
|
cfg.SecurityConfig.RealityPublicKey = public
|
||||||
|
cfg.SecurityConfig.RealityPrivateKey = private
|
||||||
|
cfg.SecurityConfig.RealityShortId = tool.GenerateShortID(private)
|
||||||
|
}
|
||||||
|
if cfg.SecurityConfig.RealityServerAddr == "" {
|
||||||
|
cfg.SecurityConfig.RealityServerAddr = cfg.SecurityConfig.SNI
|
||||||
|
}
|
||||||
|
if cfg.SecurityConfig.RealityServerPort == 0 {
|
||||||
|
cfg.SecurityConfig.RealityServerPort = 443
|
||||||
|
}
|
||||||
|
config, _ = json.Marshal(cfg)
|
||||||
|
serverInfo.Config = string(config)
|
||||||
|
} else if req.Protocol == "shadowsocks" {
|
||||||
|
var cfg types.Shadowsocks
|
||||||
|
if err = json.Unmarshal(config, &cfg); err != nil {
|
||||||
|
l.Errorf("[CreateNode] Unmarshal Shadowsocks Config Error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
|
||||||
|
}
|
||||||
|
if strings.Contains(cfg.Method, "2022") {
|
||||||
|
var length int
|
||||||
|
switch cfg.Method {
|
||||||
|
case "2022-blake3-aes-128-gcm":
|
||||||
|
length = 16
|
||||||
|
default:
|
||||||
|
length = 32
|
||||||
|
}
|
||||||
|
if len(cfg.ServerKey) != length {
|
||||||
|
cfg.ServerKey = tool.GenerateCipher(cfg.ServerKey, length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config, _ = json.Marshal(cfg)
|
||||||
|
serverInfo.Config = string(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = l.svcCtx.ServerModel.Insert(l.ctx, &serverInfo)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[CreateNode] Insert Database Error: ", logger.Field("error", err.Error()))
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create server error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.City == "" || req.Country == "" {
|
||||||
|
// Marshal the task payload
|
||||||
|
payload, err := json.Marshal(queue.GetNodeCountry{
|
||||||
|
Protocol: serverInfo.Protocol,
|
||||||
|
ServerAddr: serverInfo.ServerAddr,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[GetNodeCountry]: Marshal Error", logger.Field("error", err.Error()))
|
||||||
|
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to marshal task payload")
|
||||||
|
}
|
||||||
|
// Create a queue task
|
||||||
|
task := asynq.NewTask(queue.ForthwithGetCountry, payload)
|
||||||
|
// Enqueue the task
|
||||||
|
taskInfo, err := l.svcCtx.Queue.Enqueue(task)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[GetNodeCountry]: Enqueue Error", logger.Field("error", err.Error()), logger.Field("payload", string(payload)))
|
||||||
|
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to enqueue task")
|
||||||
|
}
|
||||||
|
l.Infow("[GetNodeCountry]: Enqueue Success", logger.Field("taskID", taskInfo.ID), logger.Field("payload", string(payload)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
59
internal/logic/admin/server_bak/deleteNodeLogic.go
Normal file
59
internal/logic/admin/server_bak/deleteNodeLogic.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package server_bak
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/perfect-panel/server/pkg/tool"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DeleteNodeLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDeleteNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteNodeLogic {
|
||||||
|
return &DeleteNodeLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *DeleteNodeLogic) DeleteNode(req *types.DeleteNodeRequest) error {
|
||||||
|
err := l.svcCtx.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
|
// Delete server
|
||||||
|
err := l.svcCtx.ServerModel.Delete(l.ctx, req.Id, tx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// Delete server to subscribe
|
||||||
|
subs, err := l.svcCtx.SubscribeModel.QuerySubscribeIdsByServerIdAndServerGroupId(l.ctx, req.Id, 0)
|
||||||
|
if err != nil {
|
||||||
|
l.Logger.Errorf("[DeleteNode] QuerySubscribeIdsByServerIdAndServerGroupId error: %v", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, sub := range subs {
|
||||||
|
servers := tool.StringToInt64Slice(sub.Server)
|
||||||
|
newServers := tool.RemoveElementBySlice(servers, req.Id)
|
||||||
|
sub.Server = tool.Int64SliceToString(newServers)
|
||||||
|
if err = l.svcCtx.SubscribeModel.Update(l.ctx, sub, tx); err != nil {
|
||||||
|
l.Logger.Errorf("[DeleteNode] UpdateSubscribe error: %v", err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[DeleteNode] Delete Database Error: ", logger.Field("error", err.Error()))
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseDeletedError), "delete server error: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
139
internal/logic/admin/server_bak/updateNodeLogic.go
Normal file
139
internal/logic/admin/server_bak/updateNodeLogic.go
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
package server_bak
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hibiken/asynq"
|
||||||
|
"github.com/perfect-panel/server/pkg/device"
|
||||||
|
queue "github.com/perfect-panel/server/queue/types"
|
||||||
|
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"github.com/perfect-panel/server/pkg/tool"
|
||||||
|
"github.com/perfect-panel/server/pkg/xerr"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UpdateNodeLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUpdateNodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateNodeLogic {
|
||||||
|
return &UpdateNodeLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *UpdateNodeLogic) UpdateNode(req *types.UpdateNodeRequest) error {
|
||||||
|
// Check server exist
|
||||||
|
nodeInfo, err := l.svcCtx.ServerModel.FindOne(l.ctx, req.Id)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find server error: %v", err)
|
||||||
|
}
|
||||||
|
tool.DeepCopy(nodeInfo, req, tool.CopyWithIgnoreEmpty(false))
|
||||||
|
config, err := json.Marshal(req.Config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeInfo.Config = string(config)
|
||||||
|
nodeRelay, err := json.Marshal(req.RelayNode)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[UpdateNode] Marshal RelayNode Error: ", logger.Field("error", err.Error()))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理Tags字段
|
||||||
|
switch {
|
||||||
|
case len(req.Tags) > 0:
|
||||||
|
// 有Tags,进行连接
|
||||||
|
nodeInfo.Tags = strings.Join(req.Tags, ",")
|
||||||
|
default:
|
||||||
|
// 空数组,清空Tags
|
||||||
|
nodeInfo.Tags = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeInfo.City = req.City
|
||||||
|
nodeInfo.Country = req.Country
|
||||||
|
|
||||||
|
nodeInfo.RelayNode = string(nodeRelay)
|
||||||
|
if req.Protocol == "vless" {
|
||||||
|
var cfg types.Vless
|
||||||
|
if err := json.Unmarshal(config, &cfg); err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
|
||||||
|
}
|
||||||
|
if cfg.Security == "reality" && cfg.SecurityConfig.RealityPublicKey == "" {
|
||||||
|
public, private, err := tool.Curve25519Genkey(false, "")
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "generate curve25519 key error")
|
||||||
|
}
|
||||||
|
cfg.SecurityConfig.RealityPublicKey = public
|
||||||
|
cfg.SecurityConfig.RealityPrivateKey = private
|
||||||
|
cfg.SecurityConfig.RealityShortId = tool.GenerateShortID(private)
|
||||||
|
}
|
||||||
|
if cfg.SecurityConfig.RealityServerAddr == "" {
|
||||||
|
cfg.SecurityConfig.RealityServerAddr = cfg.SecurityConfig.SNI
|
||||||
|
}
|
||||||
|
if cfg.SecurityConfig.RealityServerPort == 0 {
|
||||||
|
cfg.SecurityConfig.RealityServerPort = 443
|
||||||
|
}
|
||||||
|
config, _ = json.Marshal(cfg)
|
||||||
|
nodeInfo.Config = string(config)
|
||||||
|
} else if req.Protocol == "shadowsocks" {
|
||||||
|
var cfg types.Shadowsocks
|
||||||
|
if err = json.Unmarshal(config, &cfg); err != nil {
|
||||||
|
l.Errorf("[CreateNode] Unmarshal Shadowsocks Config Error: %v", err.Error())
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "json.Unmarshal error: %v", err.Error())
|
||||||
|
}
|
||||||
|
if strings.Contains(cfg.Method, "2022") {
|
||||||
|
var length int
|
||||||
|
switch cfg.Method {
|
||||||
|
case "2022-blake3-aes-128-gcm":
|
||||||
|
length = 16
|
||||||
|
default:
|
||||||
|
length = 32
|
||||||
|
}
|
||||||
|
if len(cfg.ServerKey) != length {
|
||||||
|
cfg.ServerKey = tool.GenerateCipher(cfg.ServerKey, length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config, _ = json.Marshal(cfg)
|
||||||
|
nodeInfo.Config = string(config)
|
||||||
|
}
|
||||||
|
err = l.svcCtx.ServerModel.Update(l.ctx, nodeInfo)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[UpdateNode] Update Database Error: ", logger.Field("error", err.Error()))
|
||||||
|
return errors.Wrapf(xerr.NewErrCode(xerr.DatabaseInsertError), "create server error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.City == "" || req.Country == "" {
|
||||||
|
// Marshal the task payload
|
||||||
|
payload, err := json.Marshal(queue.GetNodeCountry{
|
||||||
|
Protocol: nodeInfo.Protocol,
|
||||||
|
ServerAddr: nodeInfo.ServerAddr,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[GetNodeCountry]: Marshal Error", logger.Field("error", err.Error()))
|
||||||
|
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to marshal task payload")
|
||||||
|
}
|
||||||
|
// Create a queue task
|
||||||
|
task := asynq.NewTask(queue.ForthwithGetCountry, payload)
|
||||||
|
// Enqueue the task
|
||||||
|
taskInfo, err := l.svcCtx.Queue.Enqueue(task)
|
||||||
|
if err != nil {
|
||||||
|
l.Errorw("[GetNodeCountry]: Enqueue Error", logger.Field("error", err.Error()), logger.Field("payload", string(payload)))
|
||||||
|
return errors.Wrap(xerr.NewErrCode(xerr.ERROR), "Failed to enqueue task")
|
||||||
|
}
|
||||||
|
l.Infow("[GetNodeCountry]: Enqueue Success", logger.Field("taskID", taskInfo.ID), logger.Field("payload", string(payload)))
|
||||||
|
}
|
||||||
|
|
||||||
|
l.svcCtx.DeviceManager.Broadcast(device.SubscribeUpdate)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package server
|
package server_bak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@ -65,7 +65,7 @@ func (l *OAuthLoginGetTokenLogic) OAuthLoginGetToken(req *types.OAuthLoginGetTok
|
|||||||
)
|
)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
l.recordLoginStatus(loginStatus, userInfo, ip, userAgent, requestID)
|
l.recordLoginStatus(loginStatus, userInfo, ip, userAgent, requestID, req.Method)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
userInfo, err = l.handleOAuthProvider(req, requestID)
|
userInfo, err = l.handleOAuthProvider(req, requestID)
|
||||||
@ -487,10 +487,11 @@ func (l *OAuthLoginGetTokenLogic) createAuthMethod(db *gorm.DB, userID int64, au
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *OAuthLoginGetTokenLogic) recordLoginStatus(loginStatus bool, userInfo *user.User, ip, userAgent, requestID string) {
|
func (l *OAuthLoginGetTokenLogic) recordLoginStatus(loginStatus bool, userInfo *user.User, ip, userAgent, requestID, authType string) {
|
||||||
|
|
||||||
if userInfo != nil && userInfo.Id != 0 {
|
if userInfo != nil && userInfo.Id != 0 {
|
||||||
loginLog := log.Login{
|
loginLog := log.Login{
|
||||||
|
Method: authType,
|
||||||
LoginIP: ip,
|
LoginIP: ip,
|
||||||
UserAgent: userAgent,
|
UserAgent: userAgent,
|
||||||
Success: loginStatus,
|
Success: loginStatus,
|
||||||
|
|||||||
@ -45,6 +45,7 @@ func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (res
|
|||||||
defer func() {
|
defer func() {
|
||||||
if userInfo.Id != 0 && loginStatus {
|
if userInfo.Id != 0 && loginStatus {
|
||||||
loginLog := log.Login{
|
loginLog := log.Login{
|
||||||
|
Method: "email",
|
||||||
LoginIP: req.IP,
|
LoginIP: req.IP,
|
||||||
UserAgent: req.UserAgent,
|
UserAgent: req.UserAgent,
|
||||||
Success: loginStatus,
|
Success: loginStatus,
|
||||||
|
|||||||
@ -53,6 +53,7 @@ func (l *TelephoneLoginLogic) TelephoneLogin(req *types.TelephoneLoginRequest, r
|
|||||||
defer func(svcCtx *svc.ServiceContext) {
|
defer func(svcCtx *svc.ServiceContext) {
|
||||||
if userInfo.Id != 0 {
|
if userInfo.Id != 0 {
|
||||||
loginLog := log.Login{
|
loginLog := log.Login{
|
||||||
|
Method: "mobile",
|
||||||
LoginIP: ip,
|
LoginIP: ip,
|
||||||
UserAgent: r.UserAgent(),
|
UserAgent: r.UserAgent(),
|
||||||
Success: loginStatus,
|
Success: loginStatus,
|
||||||
|
|||||||
@ -104,6 +104,7 @@ func (l *TelephoneResetPasswordLogic) TelephoneResetPassword(req *types.Telephon
|
|||||||
defer func() {
|
defer func() {
|
||||||
if token != "" && userInfo.Id != 0 {
|
if token != "" && userInfo.Id != 0 {
|
||||||
loginLog := log.Login{
|
loginLog := log.Login{
|
||||||
|
Method: "mobile",
|
||||||
LoginIP: req.IP,
|
LoginIP: req.IP,
|
||||||
UserAgent: req.UserAgent,
|
UserAgent: req.UserAgent,
|
||||||
Success: token != "",
|
Success: token != "",
|
||||||
|
|||||||
@ -159,6 +159,7 @@ func (l *TelephoneUserRegisterLogic) TelephoneUserRegister(req *types.TelephoneR
|
|||||||
defer func() {
|
defer func() {
|
||||||
if token != "" && userInfo.Id != 0 {
|
if token != "" && userInfo.Id != 0 {
|
||||||
loginLog := log.Login{
|
loginLog := log.Login{
|
||||||
|
Method: "mobile",
|
||||||
LoginIP: req.IP,
|
LoginIP: req.IP,
|
||||||
UserAgent: req.UserAgent,
|
UserAgent: req.UserAgent,
|
||||||
Success: token != "",
|
Success: token != "",
|
||||||
|
|||||||
@ -43,6 +43,7 @@ func (l *UserLoginLogic) UserLogin(req *types.UserLoginRequest) (resp *types.Log
|
|||||||
defer func(svcCtx *svc.ServiceContext) {
|
defer func(svcCtx *svc.ServiceContext) {
|
||||||
if userInfo.Id != 0 {
|
if userInfo.Id != 0 {
|
||||||
loginLog := log.Login{
|
loginLog := log.Login{
|
||||||
|
Method: "email",
|
||||||
LoginIP: req.IP,
|
LoginIP: req.IP,
|
||||||
UserAgent: req.UserAgent,
|
UserAgent: req.UserAgent,
|
||||||
Success: loginStatus,
|
Success: loginStatus,
|
||||||
|
|||||||
@ -147,6 +147,7 @@ func (l *UserRegisterLogic) UserRegister(req *types.UserRegisterRequest) (resp *
|
|||||||
defer func() {
|
defer func() {
|
||||||
if token != "" && userInfo.Id != 0 {
|
if token != "" && userInfo.Id != 0 {
|
||||||
loginLog := log.Login{
|
loginLog := log.Login{
|
||||||
|
Method: "email",
|
||||||
LoginIP: req.IP,
|
LoginIP: req.IP,
|
||||||
UserAgent: req.UserAgent,
|
UserAgent: req.UserAgent,
|
||||||
Success: loginStatus,
|
Success: loginStatus,
|
||||||
|
|||||||
@ -20,7 +20,7 @@ type GetSubscribeLogLogic struct {
|
|||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Subscribe Log
|
// NewGetSubscribeLogLogic Get Subscribe Log
|
||||||
func NewGetSubscribeLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubscribeLogLogic {
|
func NewGetSubscribeLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubscribeLogLogic {
|
||||||
return &GetSubscribeLogLogic{
|
return &GetSubscribeLogLogic{
|
||||||
Logger: logger.WithContext(ctx),
|
Logger: logger.WithContext(ctx),
|
||||||
@ -39,7 +39,7 @@ func (l *GetSubscribeLogLogic) GetSubscribeLog(req *types.GetSubscribeLogRequest
|
|||||||
Page: req.Page,
|
Page: req.Page,
|
||||||
Size: req.Size,
|
Size: req.Size,
|
||||||
Type: log.TypeSubscribe.Uint8(),
|
Type: log.TypeSubscribe.Uint8(),
|
||||||
ObjectID: u.Id,
|
ObjectID: u.Id, // filter by current user id
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.Errorw("[GetUserSubscribeLogs] Get User Subscribe Logs Error:", logger.Field("err", err.Error()))
|
l.Errorw("[GetUserSubscribeLogs] Get User Subscribe Logs Error:", logger.Field("err", err.Error()))
|
||||||
@ -56,7 +56,7 @@ func (l *GetSubscribeLogLogic) GetSubscribeLog(req *types.GetSubscribeLogRequest
|
|||||||
list = append(list, types.UserSubscribeLog{
|
list = append(list, types.UserSubscribeLog{
|
||||||
Id: item.Id,
|
Id: item.Id,
|
||||||
UserId: item.ObjectID,
|
UserId: item.ObjectID,
|
||||||
UserSubscribeId: content.SubscribeId,
|
UserSubscribeId: content.UserSubscribeId,
|
||||||
Token: content.Token,
|
Token: content.Token,
|
||||||
IP: content.ClientIP,
|
IP: content.ClientIP,
|
||||||
UserAgent: content.UserAgent,
|
UserAgent: content.UserAgent,
|
||||||
|
|||||||
@ -20,7 +20,7 @@ type QueryUserBalanceLogLogic struct {
|
|||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query User Balance Log
|
// NewQueryUserBalanceLogLogic Query User Balance Log
|
||||||
func NewQueryUserBalanceLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryUserBalanceLogLogic {
|
func NewQueryUserBalanceLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryUserBalanceLogLogic {
|
||||||
return &QueryUserBalanceLogLogic{
|
return &QueryUserBalanceLogLogic{
|
||||||
Logger: logger.WithContext(ctx),
|
Logger: logger.WithContext(ctx),
|
||||||
@ -51,21 +51,20 @@ func (l *QueryUserBalanceLogLogic) QueryUserBalanceLog() (resp *types.QueryUserB
|
|||||||
Total: total,
|
Total: total,
|
||||||
}
|
}
|
||||||
|
|
||||||
list := make([]types.UserBalanceLog, 0)
|
list := make([]types.BalanceLog, 0)
|
||||||
for _, datum := range data {
|
for _, datum := range data {
|
||||||
var content log.Balance
|
var content log.Balance
|
||||||
if err = content.Unmarshal([]byte(datum.Content)); err != nil {
|
if err = content.Unmarshal([]byte(datum.Content)); err != nil {
|
||||||
l.Errorf("[QueryUserBalanceLog] unmarshal balance log content failed: %v", err.Error())
|
l.Errorf("[QueryUserBalanceLog] unmarshal balance log content failed: %v", err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
list = append(list, types.UserBalanceLog{
|
list = append(list, types.BalanceLog{
|
||||||
Id: datum.Id,
|
|
||||||
UserId: datum.ObjectID,
|
UserId: datum.ObjectID,
|
||||||
Amount: content.Amount,
|
Amount: content.Amount,
|
||||||
Type: content.Type,
|
Type: content.Type,
|
||||||
OrderId: content.OrderId,
|
OrderId: content.OrderId,
|
||||||
Balance: content.Balance,
|
Balance: content.Balance,
|
||||||
CreatedAt: datum.CreatedAt.UnixMilli(),
|
Timestamp: content.Timestamp,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -54,10 +54,10 @@ func (l *QueryUserCommissionLogLogic) QueryUserCommissionLog(req *types.QueryUse
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
list = append(list, types.CommissionLog{
|
list = append(list, types.CommissionLog{
|
||||||
Id: datum.Id,
|
|
||||||
UserId: datum.ObjectID,
|
UserId: datum.ObjectID,
|
||||||
OrderNo: content.OrderNo,
|
Type: content.Type,
|
||||||
Amount: content.Amount,
|
Amount: content.Amount,
|
||||||
|
OrderNo: content.OrderNo,
|
||||||
CreatedAt: content.CreatedAt,
|
CreatedAt: content.CreatedAt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -180,13 +180,14 @@ func (l *SubscribeLogic) logSubscribeActivity(subscribeStatus bool, userSub *use
|
|||||||
Token: req.Token,
|
Token: req.Token,
|
||||||
UserAgent: req.UA,
|
UserAgent: req.UA,
|
||||||
ClientIP: l.ctx.ClientIP(),
|
ClientIP: l.ctx.ClientIP(),
|
||||||
|
UserSubscribeId: userSub.Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
content, _ := subscribeLog.Marshal()
|
content, _ := subscribeLog.Marshal()
|
||||||
|
|
||||||
err := l.svc.LogModel.Insert(l.ctx.Request.Context(), &log.SystemLog{
|
err := l.svc.LogModel.Insert(l.ctx.Request.Context(), &log.SystemLog{
|
||||||
Type: log.TypeSubscribe.Uint8(),
|
Type: log.TypeSubscribe.Uint8(),
|
||||||
ObjectID: userSub.Id,
|
ObjectID: userSub.UserId, // log user id
|
||||||
Date: time.Now().Format(time.DateOnly),
|
Date: time.Now().Format(time.DateOnly),
|
||||||
Content: string(content),
|
Content: string(content),
|
||||||
})
|
})
|
||||||
|
|||||||
8
internal/model/cache/constant.go
vendored
8
internal/model/cache/constant.go
vendored
@ -39,14 +39,6 @@ const (
|
|||||||
AllNodeUploadTrafficCacheKey = "node:all_node_upload_traffic"
|
AllNodeUploadTrafficCacheKey = "node:all_node_upload_traffic"
|
||||||
// YesterdayTotalTrafficRank 昨日节点总流量排行榜
|
// YesterdayTotalTrafficRank 昨日节点总流量排行榜
|
||||||
YesterdayNodeTotalTrafficRank = "node:yesterday_total_traffic_rank"
|
YesterdayNodeTotalTrafficRank = "node:yesterday_total_traffic_rank"
|
||||||
// YesterdayUploadTrafficRank 昨日节点上传流量排行榜
|
|
||||||
YesterdayNodeUploadTrafficRank = "node:yesterday_upload_traffic_rank"
|
|
||||||
// YesterdayDownloadTrafficRank 昨日节点下载流量排行榜
|
|
||||||
YesterdayNodeDownloadTrafficRank = "node:yesterday_download_traffic_rank"
|
|
||||||
// YesterdayUserTotalTrafficRank 昨日用户总流量排行榜
|
// YesterdayUserTotalTrafficRank 昨日用户总流量排行榜
|
||||||
YesterdayUserTotalTrafficRank = "node:yesterday_user_total_traffic_rank"
|
YesterdayUserTotalTrafficRank = "node:yesterday_user_total_traffic_rank"
|
||||||
// YesterdayUserUploadTrafficRank 昨日用户上传流量排行榜
|
|
||||||
YesterdayUserUploadTrafficRank = "node:yesterday_user_upload_traffic_rank"
|
|
||||||
// YesterdayUserDownloadTrafficRank 昨日用户下载流量排行榜
|
|
||||||
YesterdayUserDownloadTrafficRank = "node:yesterday_user_download_traffic_rank"
|
|
||||||
)
|
)
|
||||||
|
|||||||
@ -7,20 +7,44 @@ import (
|
|||||||
|
|
||||||
type Type uint8
|
type Type uint8
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Log Types:
|
||||||
|
1X Message Logs
|
||||||
|
2X Subscription Logs
|
||||||
|
3X User Logs
|
||||||
|
4X Traffic Ranking Logs
|
||||||
|
*/
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TypeEmailMessage Type = iota + 1 // Message log
|
TypeEmailMessage Type = 10 // Message log
|
||||||
TypeMobileMessage // Mobile message log
|
TypeMobileMessage Type = 11 // Mobile message log
|
||||||
TypeSubscribe // Subscription log
|
TypeSubscribe Type = 20 // Subscription log
|
||||||
TypeSubscribeTraffic // Subscription traffic log
|
TypeSubscribeTraffic Type = 21 // Subscription traffic log
|
||||||
TypeServerTraffic // Server traffic log
|
TypeServerTraffic Type = 22 // Server traffic log
|
||||||
TypeLogin // Login log
|
TypeResetSubscribe Type = 23 // Reset subscription log
|
||||||
TypeRegister // Registration log
|
TypeLogin Type = 30 // Login log
|
||||||
TypeBalance // Balance log
|
TypeRegister Type = 31 // Registration log
|
||||||
TypeCommission // Commission log
|
TypeBalance Type = 32 // Balance log
|
||||||
TypeResetSubscribe // Reset subscription log
|
TypeCommission Type = 33 // Commission log
|
||||||
TypeGift // Gift log
|
TypeGift Type = 34 // Gift log
|
||||||
TypeUserTrafficRank // Top 10 User traffic rank log
|
TypeUserTrafficRank Type = 40 // Top 10 User traffic rank log
|
||||||
TypeServerTrafficRank // Top 10 Server traffic rank log
|
TypeServerTrafficRank Type = 41 // Top 10 Server traffic rank log
|
||||||
|
)
|
||||||
|
const (
|
||||||
|
ResetSubscribeTypeAuto uint16 = 231 // Auto reset
|
||||||
|
ResetSubscribeTypeAdvance uint16 = 232 // Advance reset
|
||||||
|
ResetSubscribeTypePaid uint16 = 233 // Paid reset
|
||||||
|
BalanceTypeRecharge uint16 = 321 // Recharge
|
||||||
|
BalanceTypeWithdraw uint16 = 322 // Withdraw
|
||||||
|
BalanceTypePayment uint16 = 323 // Payment
|
||||||
|
BalanceTypeRefund uint16 = 324 // Refund
|
||||||
|
BalanceTypeReward uint16 = 325 // Reward
|
||||||
|
CommissionTypePurchase uint16 = 331 // Purchase
|
||||||
|
CommissionTypeRenewal uint16 = 332 // Renewal
|
||||||
|
CommissionTypeRefund uint16 = 333 // Gift
|
||||||
|
GiftTypeIncrease uint16 = 341 // Increase
|
||||||
|
GiftTypeReduce uint16 = 342 // Reduce
|
||||||
)
|
)
|
||||||
|
|
||||||
// Uint8 converts Type to uint8.
|
// Uint8 converts Type to uint8.
|
||||||
@ -95,6 +119,7 @@ func (s *Traffic) Unmarshal(data []byte) error {
|
|||||||
|
|
||||||
// Login represents a login log entry.
|
// Login represents a login log entry.
|
||||||
type Login struct {
|
type Login struct {
|
||||||
|
Method string `json:"method"`
|
||||||
LoginIP string `json:"login_ip"`
|
LoginIP string `json:"login_ip"`
|
||||||
UserAgent string `json:"user_agent"`
|
UserAgent string `json:"user_agent"`
|
||||||
Success bool `json:"success"`
|
Success bool `json:"success"`
|
||||||
@ -150,7 +175,7 @@ type Subscribe struct {
|
|||||||
Token string `json:"token"`
|
Token string `json:"token"`
|
||||||
UserAgent string `json:"user_agent"`
|
UserAgent string `json:"user_agent"`
|
||||||
ClientIP string `json:"client_ip"`
|
ClientIP string `json:"client_ip"`
|
||||||
SubscribeId int64 `json:"subscribe_id"`
|
UserSubscribeId int64 `json:"user_subscribe_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marshal implements the json.Marshaler interface for Subscribe.
|
// Marshal implements the json.Marshaler interface for Subscribe.
|
||||||
@ -170,15 +195,10 @@ func (s *Subscribe) Unmarshal(data []byte) error {
|
|||||||
return json.Unmarshal(data, aux)
|
return json.Unmarshal(data, aux)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
ResetSubscribeTypeAuto uint8 = 1
|
|
||||||
ResetSubscribeTypeAdvance uint8 = 2
|
|
||||||
ResetSubscribeTypePaid uint8 = 3
|
|
||||||
)
|
|
||||||
|
|
||||||
// ResetSubscribe represents a reset subscription log entry.
|
// ResetSubscribe represents a reset subscription log entry.
|
||||||
type ResetSubscribe struct {
|
type ResetSubscribe struct {
|
||||||
Type uint8 `json:"type"`
|
Type uint16 `json:"type"`
|
||||||
|
UserId int64 `json:"user_id"`
|
||||||
OrderNo string `json:"order_no,omitempty"`
|
OrderNo string `json:"order_no,omitempty"`
|
||||||
ResetAt int64 `json:"reset_at"`
|
ResetAt int64 `json:"reset_at"`
|
||||||
}
|
}
|
||||||
@ -200,18 +220,9 @@ func (r *ResetSubscribe) Unmarshal(data []byte) error {
|
|||||||
return json.Unmarshal(data, aux)
|
return json.Unmarshal(data, aux)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
BalanceTypeRecharge uint8 = 1 // Recharge
|
|
||||||
BalanceTypeWithdraw uint8 = 2 // Withdraw
|
|
||||||
BalanceTypePayment uint8 = 3 // Payment
|
|
||||||
BalanceTypeRefund uint8 = 4 // Refund
|
|
||||||
BalanceTypeReward uint8 = 5 // Reward
|
|
||||||
)
|
|
||||||
|
|
||||||
// Balance represents a balance log entry.
|
// Balance represents a balance log entry.
|
||||||
type Balance struct {
|
type Balance struct {
|
||||||
Id int64 `json:"id"`
|
Type uint16 `json:"type"`
|
||||||
Type uint8 `json:"type"`
|
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
OrderId int64 `json:"order_id,omitempty"`
|
OrderId int64 `json:"order_id,omitempty"`
|
||||||
Balance int64 `json:"balance"`
|
Balance int64 `json:"balance"`
|
||||||
@ -235,15 +246,9 @@ func (b *Balance) Unmarshal(data []byte) error {
|
|||||||
return json.Unmarshal(data, aux)
|
return json.Unmarshal(data, aux)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
CommissionTypePurchase uint8 = 1 // Purchase
|
|
||||||
CommissionTypeRenewal uint8 = 2 // Renewal
|
|
||||||
CommissionTypeRefund uint8 = 3 // Gift
|
|
||||||
)
|
|
||||||
|
|
||||||
// Commission represents a commission log entry.
|
// Commission represents a commission log entry.
|
||||||
type Commission struct {
|
type Commission struct {
|
||||||
Type uint8 `json:"type"`
|
Type uint16 `json:"type"`
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
OrderNo string `json:"order_no"`
|
OrderNo string `json:"order_no"`
|
||||||
CreatedAt int64 `json:"created_at"`
|
CreatedAt int64 `json:"created_at"`
|
||||||
@ -266,14 +271,9 @@ func (c *Commission) Unmarshal(data []byte) error {
|
|||||||
return json.Unmarshal(data, aux)
|
return json.Unmarshal(data, aux)
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
GiftTypeIncrease uint8 = 1 // Increase
|
|
||||||
GiftTypeReduce uint8 = 2 // Reduce
|
|
||||||
)
|
|
||||||
|
|
||||||
// Gift represents a gift log entry.
|
// Gift represents a gift log entry.
|
||||||
type Gift struct {
|
type Gift struct {
|
||||||
Type uint8 `json:"type"`
|
Type uint16 `json:"type"`
|
||||||
OrderNo string `json:"order_no"`
|
OrderNo string `json:"order_no"`
|
||||||
SubscribeId int64 `json:"subscribe_id"`
|
SubscribeId int64 `json:"subscribe_id"`
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
|
|||||||
@ -16,6 +16,7 @@ type FilterParams struct {
|
|||||||
Page int
|
Page int
|
||||||
Size int
|
Size int
|
||||||
Type uint8
|
Type uint8
|
||||||
|
Data string
|
||||||
Search string
|
Search string
|
||||||
ObjectID int64
|
ObjectID int64
|
||||||
}
|
}
|
||||||
@ -43,6 +44,11 @@ func (m *customSystemLogModel) FilterSystemLog(ctx context.Context, filter *Filt
|
|||||||
if filter.Type != 0 {
|
if filter.Type != 0 {
|
||||||
tx = tx.Where("`type` = ?", filter.Type)
|
tx = tx.Where("`type` = ?", filter.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filter.Data != "" {
|
||||||
|
tx = tx.Where("`data` = ?", filter.Data)
|
||||||
|
}
|
||||||
|
|
||||||
if filter.ObjectID != 0 {
|
if filter.ObjectID != 0 {
|
||||||
tx = tx.Where("`object_id` = ?", filter.ObjectID)
|
tx = tx.Where("`object_id` = ?", filter.ObjectID)
|
||||||
}
|
}
|
||||||
|
|||||||
127
internal/model/node/default.go
Normal file
127
internal/model/node/default.go
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
package node
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ Model = (*customServerModel)(nil)
|
||||||
|
|
||||||
|
//goland:noinspection GoNameStartsWithPackageName
|
||||||
|
type (
|
||||||
|
Model interface {
|
||||||
|
serverModel
|
||||||
|
NodeModel
|
||||||
|
customServerLogicModel
|
||||||
|
}
|
||||||
|
serverModel interface {
|
||||||
|
InsertServer(ctx context.Context, data *Server, tx ...*gorm.DB) error
|
||||||
|
FindOneServer(ctx context.Context, id int64) (*Server, error)
|
||||||
|
UpdateServer(ctx context.Context, data *Server, tx ...*gorm.DB) error
|
||||||
|
DeleteServer(ctx context.Context, id int64, tx ...*gorm.DB) error
|
||||||
|
Transaction(ctx context.Context, fn func(db *gorm.DB) error) error
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeModel interface {
|
||||||
|
InsertNode(ctx context.Context, data *Node, tx ...*gorm.DB) error
|
||||||
|
FindOneNode(ctx context.Context, id int64) (*Node, error)
|
||||||
|
UpdateNode(ctx context.Context, data *Node, tx ...*gorm.DB) error
|
||||||
|
DeleteNode(ctx context.Context, id int64, tx ...*gorm.DB) error
|
||||||
|
}
|
||||||
|
|
||||||
|
customServerModel struct {
|
||||||
|
*defaultServerModel
|
||||||
|
}
|
||||||
|
defaultServerModel struct {
|
||||||
|
*gorm.DB
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newServerModel(db *gorm.DB) *defaultServerModel {
|
||||||
|
return &defaultServerModel{
|
||||||
|
DB: db,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewModel returns a model for the database table.
|
||||||
|
func NewModel(conn *gorm.DB) Model {
|
||||||
|
return &customServerModel{
|
||||||
|
defaultServerModel: newServerModel(conn),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultServerModel) InsertServer(ctx context.Context, data *Server, tx ...*gorm.DB) error {
|
||||||
|
db := m.DB
|
||||||
|
if len(tx) > 0 {
|
||||||
|
db = tx[0]
|
||||||
|
}
|
||||||
|
return db.WithContext(ctx).Create(data).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultServerModel) FindOneServer(ctx context.Context, id int64) (*Server, error) {
|
||||||
|
var server Server
|
||||||
|
err := m.WithContext(ctx).Model(&Server{}).Where("id = ?", id).First(&server).Error
|
||||||
|
return &server, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultServerModel) UpdateServer(ctx context.Context, data *Server, tx ...*gorm.DB) error {
|
||||||
|
_, err := m.FindOneServer(ctx, data.Id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
db := m.DB
|
||||||
|
if len(tx) > 0 {
|
||||||
|
db = tx[0]
|
||||||
|
}
|
||||||
|
return db.WithContext(ctx).Save(data).Error
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultServerModel) DeleteServer(ctx context.Context, id int64, tx ...*gorm.DB) error {
|
||||||
|
db := m.DB
|
||||||
|
if len(tx) > 0 {
|
||||||
|
db = tx[0]
|
||||||
|
}
|
||||||
|
return db.WithContext(ctx).Where("`id` = ?", id).Delete(&Server{}).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultServerModel) InsertNode(ctx context.Context, data *Node, tx ...*gorm.DB) error {
|
||||||
|
db := m.DB
|
||||||
|
if len(tx) > 0 {
|
||||||
|
db = tx[0]
|
||||||
|
}
|
||||||
|
return db.WithContext(ctx).Create(data).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultServerModel) FindOneNode(ctx context.Context, id int64) (*Node, error) {
|
||||||
|
var node Node
|
||||||
|
err := m.WithContext(ctx).Model(&Node{}).Where("id = ?", id).First(&node).Error
|
||||||
|
return &node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultServerModel) UpdateNode(ctx context.Context, data *Node, tx ...*gorm.DB) error {
|
||||||
|
_, err := m.FindOneNode(ctx, data.Id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
db := m.DB
|
||||||
|
if len(tx) > 0 {
|
||||||
|
db = tx[0]
|
||||||
|
}
|
||||||
|
return db.WithContext(ctx).Save(data).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultServerModel) DeleteNode(ctx context.Context, id int64, tx ...*gorm.DB) error {
|
||||||
|
db := m.DB
|
||||||
|
if len(tx) > 0 {
|
||||||
|
db = tx[0]
|
||||||
|
}
|
||||||
|
return db.WithContext(ctx).Where("`id` = ?", id).Delete(&Node{}).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultServerModel) Transaction(ctx context.Context, fn func(db *gorm.DB) error) error {
|
||||||
|
return m.WithContext(ctx).Transaction(fn)
|
||||||
|
}
|
||||||
53
internal/model/node/model.go
Normal file
53
internal/model/node/model.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package node
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type customServerLogicModel interface {
|
||||||
|
FilterServerList(ctx context.Context, params *FilterParams) (int64, []*Server, error)
|
||||||
|
FilterNodeList(ctx context.Context, params *FilterParams) (int64, []*Node, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterParams Filter Server Params
|
||||||
|
type FilterParams struct {
|
||||||
|
Page int
|
||||||
|
Size int
|
||||||
|
Search string
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterServerList Filter Server List
|
||||||
|
func (m *customServerModel) FilterServerList(ctx context.Context, params *FilterParams) (int64, []*Server, error) {
|
||||||
|
var servers []*Server
|
||||||
|
var total int64
|
||||||
|
query := m.WithContext(ctx).Model(&Server{})
|
||||||
|
if params == nil {
|
||||||
|
params = &FilterParams{
|
||||||
|
Page: 1,
|
||||||
|
Size: 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if params.Search != "" {
|
||||||
|
s := "%" + params.Search + "%"
|
||||||
|
query = query.Where("`name` LIKE ? OR `address` LIKE ?", s, s)
|
||||||
|
}
|
||||||
|
err := query.Count(&total).Limit(params.Size).Offset((params.Page - 1) * params.Size).Find(&servers).Error
|
||||||
|
return total, servers, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// FilterNodeList Filter Node List
|
||||||
|
func (m *customServerModel) FilterNodeList(ctx context.Context, params *FilterParams) (int64, []*Node, error) {
|
||||||
|
var nodes []*Node
|
||||||
|
var total int64
|
||||||
|
query := m.WithContext(ctx).Model(&Node{})
|
||||||
|
if params == nil {
|
||||||
|
params = &FilterParams{
|
||||||
|
Page: 1,
|
||||||
|
Size: 10,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if params.Search != "" {
|
||||||
|
s := "%" + params.Search + "%"
|
||||||
|
query = query.Where("`name` LIKE ? OR `address` LIKE ? OR `tags` LIKE ? OR `port` LIKE ? ", s, s, s, s)
|
||||||
|
}
|
||||||
|
err := query.Count(&total).Limit(params.Size).Offset((params.Page - 1) * params.Size).Find(&nodes).Error
|
||||||
|
return total, nodes, err
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user