Develop (#76)
* refactor: rename queryannouncementhandler.go to queryAnnouncementLogic.go for clarity
* feat(panDomain): update subscription logic to use V2 handler for improved functionality
* refactor(subscribe): replace V2 handler with a unified Handler method for subscription logic
* feat(subscribe): implement user agent limit feature with configurable list
* fix(subscribe): improve error handling and logging for subscription requests
* feat(subscribe): add user agent limit configuration to system settings
* refactor(api): remove deprecated application-related endpoints and types
* refactor(swagger): remove deprecated app.json generation from swagger configuration
* refactor(swagger): remove deprecated app.json check from swagger configuration
* fix(subscribe): update delete method to use Where clause for improved query accuracy
* fix(subscribe): update Id field tag to use primaryKey and improve save method query
* fix(subscribe): update Id field tag to use primaryKey and improve model queries
* fix(subscribe): rename variable for clarity and add special handling for Stash user agent
* fix(email): convert RegisterStartTime and RegisterEndTime to time.Time for accurate query filtering
* refactor(log): consolidate logging models and update related logic for improved clarity and functionality
* fix(types): change Content field type in MessageLog to interface{} for improved flexibility
* fix(log): change MessageLog list to use value type for improved performance and memory efficiency
* fix(email): set EmailTypeVerify in task payload and update content type conversion for verification email
* fix(log): remove unused Id field from SystemLog during login log insertion
* fix(login): remove debug logs and error logging during user login process
* fix(log): add traffic reset logging for subscription resets
* fix(log): insert reset traffic log during subscription activation
* feat(log): add endpoints for retrieving and resetting subscribe traffic logs
* refactor(log): remove Reset Subscribe Traffic Log endpoint and related types
* feat(traffic): add traffic statistics logging and scheduling
* fix(subscribe): ensure active status and reset timestamps during traffic resets
* feat(api): enhance server and node management with new request/response structures
* refactor(api): rename OnlineUser to ServerOnlineUser for clarity
* feat(api): define OnlineUser type with SID and IP fields
* feat(server): implement server management handlers and database schema
* feat(api): add traffic log details filtering and enhance traffic log structures
* feat(api): migrate server and node data handling, update related structures and logic
* feat(server): implement server deletion logic with error handling
* feat(api): update log filtering to use ResetSubscribe type for subscription logs
* feat(api): standardize timestamp field across log structures
* feat(api): refactor cache key handling for server and user lists
* feat(api): enhance server status handling with protocol support and refactor related logic
* fix(traffic): adjust start date for traffic statistics and improve log deletion comment
* feat(api): implement daily traffic ranking for users and servers with error handling
* feat(api): update server total data response to use 'OnlineUsers' and implement daily traffic statistics logging
* feat(api): add log settings management with auto-clear and clear days configuration
* fix(log): correct category in log settings update query
* feat(routes): add handler for scheduled traffic statistics
* feat(model): add user counts struct and update queries for new and renewal users
* feat(api): add referral percentage and only first purchase fields to user model and requests
* feat(database): update user table to add referral percentage and only first purchase fields
* feat(api): add reset sort endpoints for server and node
* feat(api): add sort field to server model
* feat(api): implement sorting functionality for nodes and servers
* fix(database): add sort column to nodes table
* fix(model): enhance user statistics queries with new order and renewal order counts
* fix(log): update timestamp handling in login and registration logs
* fix(log): update sorting logic for server and user subscribe traffic logs
* fix(server): add server status handling based on last reported time
* fix(model): correct filter condition to use 'date' instead of 'data'
* fix(migration): add index for traffic log on timestamp, user_id, and subscribe_id
* fix(log): optimize user traffic rank data handling by using append instead of index assignment
* fix(filter): refactor node list creation to use append and remove duplicates from tags
* fix(node): add ServerId and Enabled fields to node update logic
* feat(tags): add endpoint to query all node tags
* fix(preview): add Preload parameter to FilterNodeList for improved data retrieval
* fix(log): date is empty
* feat(subscribe): add Language field to subscription models and update query logic
* feat(subscription): add Language parameter to GetSubscription request and update query logic
* fix(server): encode ServerKey in base64 and update last reported time for nodes
* feat: delete common GetSubscription
* feat(subscription): implement FilterList method for subscription queries and update related logic
* fix(subscribe): remove duplicate user agents in SubscribeHandler
* fix(push): initialize onlineUsers as a map in pushOnlineUsersLogic
* fix(reset): initialize subs as a map in clearCache method
* refactor(query): simplify node and tag filtering using InSet function
* feat(userlist): enhance GetServerUserListLogic with improved node and tag handling
* fix(userlist): correct node ID assignment and update query logic for tag filtering
* fix(userlist): correct node ID assignment in getServerUserListLogic
* refactor(query): streamline query construction for tag filtering
* fix(statistics): optimize server ranking data handling in QueryServerTotalDataLogic
* refactor(statistics): simplify server ranking data construction in QueryServerTotalDataLogic
* fix(statistics): correct server traffic data assignment in QueryServerTotalDataLogic
* fix(statistics): optimize yesterday's top 10 server traffic data assignment in QueryServerTotalDataLogic
* fix(middleware): remove duplicate elements from user agent list in PanDomainMiddleware
* feat(middleware): enhance user agent handling by querying client list in PanDomainMiddleware
* feat(client): subscribe_template
* feat(oauth): add user agent and IP logging to registration and login processes
* fix(balance): add timestamp to balance logs for payment, refund, and recharge transactions
* fix(log): correct comment for CommissionTypeRefund to improve clarity
* fix(log): replace magic number with constant for gift type in purchase checkout logic
* fix(log): rename OrderId to OrderNo for consistency in balance logging
* feat(log): add logging for balance, gift amount, and commission adjustments
* fix(user): correct placement of DeepCopy for user info update logic
* feat(log): add UserSubscribeId to FilterSubscribeLogRequest for enhanced filtering
* fix(purchase): streamline error handling and improve JSON marshaling for temporary orders
* fix(order): simplify commission handling and improve payload parsing logic
* fix(order): update commission calculation to actual payment amount minus gateway handling fee
* feat(payment): add support for CryptoSaaS payment platform and enhance configuration handling
* fix(balance): update QueryUserBalanceLog response structure to include balance log list
* fix(email): update task progress handling to use specific task ID for updates
* feat(quota): add quota task creation and querying endpoints with updated data structures
* fix(email): update task handling to use generic task model and improve error logging
* fix(order): improve error logging for database transaction and user cache updates
* feat(quota): enhance quota task management with new request structures and processing logic
* fix(quota): remove redundant quota task status endpoint from admin marketing routes
* fix(worker): update task completion status handling in worker logic
* fix(quota): update taskInfo to include current subscription count in quota logic
* doc(log): rename function for clarity and add cache cleanup comment
* fix(quota): update time handling in quota logic and correct subscriber ID query
* fix(quota): update time handling to use UnixMilli for start time in quota logic
* feat(protocol): add server protocol configuration query and enhance protocol options
* fix(quota): correct time range queries for start and expire times in quota logic
* fix(types): update plugin options to include 'none' in the plugin field
---------
Co-authored-by: Chang lue Tsen <tension@ppanel.dev>
This commit is contained in:
@@ -12,9 +12,6 @@ const SiteConfigKey = "system:site_config"
|
||||
// SubscribeConfigKey Subscribe Config Key
|
||||
const SubscribeConfigKey = "system:subscribe_config"
|
||||
|
||||
// ApplicationKey Application Key
|
||||
const ApplicationKey = "system:application"
|
||||
|
||||
// RegisterConfigKey Register Config Key
|
||||
const RegisterConfigKey = "system:register_config"
|
||||
|
||||
@@ -51,26 +48,12 @@ const AuthCodeCacheKey = "auth:verify:email"
|
||||
// AuthCodeTelephoneCacheKey Register Code Cache Key
|
||||
const AuthCodeTelephoneCacheKey = "auth:verify:telephone"
|
||||
|
||||
// ServerUserListCacheKey Server User List Cache Key
|
||||
const ServerUserListCacheKey = "server:user_list:id:"
|
||||
|
||||
// ServerConfigCacheKey Server Config Cache Key
|
||||
const ServerConfigCacheKey = "server:config:id:"
|
||||
|
||||
// CommonStat Cache Key
|
||||
// CommonStatCacheKey CommonStat Cache Key
|
||||
const CommonStatCacheKey = "common:stat"
|
||||
|
||||
// ServerStatusCacheKey Server Status Cache Key
|
||||
const ServerStatusCacheKey = "server:status:id:"
|
||||
|
||||
// ServerCountCacheKey Server Count Cache Key
|
||||
const ServerCountCacheKey = "server:count"
|
||||
|
||||
// UserBindTelegramCacheKey User Bind Telegram Cache Key
|
||||
const UserBindTelegramCacheKey = "user:bind:telegram:code:"
|
||||
|
||||
const CacheSmsCount = "cache:sms:count"
|
||||
|
||||
// SendIntervalKeyPrefix Auth Code Send Interval Key Prefix
|
||||
const SendIntervalKeyPrefix = "send:interval:"
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ type Config struct {
|
||||
Subscribe SubscribeConfig `yaml:"Subscribe"`
|
||||
Invite InviteConfig `yaml:"Invite"`
|
||||
Telegram Telegram `yaml:"Telegram"`
|
||||
Log Log `yaml:"Log"`
|
||||
Administrator struct {
|
||||
Email string `yaml:"Email" default:"admin@ppanel.dev"`
|
||||
Password string `yaml:"Password" default:"password"`
|
||||
@@ -55,6 +56,8 @@ type SubscribeConfig struct {
|
||||
SubscribePath string `yaml:"SubscribePath" default:"/api/subscribe"`
|
||||
SubscribeDomain string `yaml:"SubscribeDomain" default:""`
|
||||
PanDomain bool `yaml:"PanDomain" default:"false"`
|
||||
UserAgentLimit bool `yaml:"UserAgentLimit" default:"false"`
|
||||
UserAgentList string `yaml:"UserAgentList" default:""`
|
||||
}
|
||||
|
||||
type RegisterConfig struct {
|
||||
@@ -144,3 +147,8 @@ type VerifyCode struct {
|
||||
Limit int64 `yaml:"Limit" default:"15"`
|
||||
Interval int64 `yaml:"Interval" default:"60"`
|
||||
}
|
||||
|
||||
type Log struct {
|
||||
AutoClear bool `yaml:"AutoClear" default:"true"`
|
||||
ClearDays int64 `yaml:"ClearDays" default:"7"`
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package order
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/order"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Get order
|
||||
func QueryOrderDetailHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Filter balance log
|
||||
func FilterBalanceLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.QueryOrderDetailRequest
|
||||
var req types.FilterBalanceLogRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func QueryOrderDetailHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewQueryOrderDetailLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryOrderDetail(&req)
|
||||
l := log.NewFilterBalanceLogLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterBalanceLog(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package document
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/document"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Get document detail
|
||||
func QueryDocumentDetailHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Filter commission log
|
||||
func FilterCommissionLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.QueryDocumentDetailRequest
|
||||
var req types.FilterCommissionLogRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func QueryDocumentDetailHandler(svcCtx *svc.ServiceContext) func(c *gin.Context)
|
||||
return
|
||||
}
|
||||
|
||||
l := document.NewQueryDocumentDetailLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryDocumentDetail(&req)
|
||||
l := log.NewFilterCommissionLogLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterCommissionLog(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package order
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/order"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Get order list
|
||||
func QueryOrderListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Filter email log
|
||||
func FilterEmailLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.QueryOrderListRequest
|
||||
var req types.FilterLogParams
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func QueryOrderListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewQueryOrderListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryOrderList(&req)
|
||||
l := log.NewFilterEmailLogLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterEmailLog(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package order
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/order"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Checkout order
|
||||
func CheckoutOrderHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Filter gift log
|
||||
func FilterGiftLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.CheckoutOrderRequest
|
||||
var req types.FilterGiftLogRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func CheckoutOrderHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewCheckoutOrderLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.CheckoutOrder(&req, c.Request.Host)
|
||||
l := log.NewFilterGiftLogLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterGiftLog(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package order
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/order"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Pre create order
|
||||
func PreCreateOrderHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Filter login log
|
||||
func FilterLoginLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.PurchaseOrderRequest
|
||||
var req types.FilterLoginLogRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func PreCreateOrderHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewPreCreateOrderLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.PreCreateOrder(&req)
|
||||
l := log.NewFilterLoginLogLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterLoginLog(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package node
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/node"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Get Node list
|
||||
func GetNodeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Filter mobile log
|
||||
func FilterMobileLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.AppUserSubscbribeNodeRequest
|
||||
var req types.FilterLogParams
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func GetNodeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := node.NewGetNodeListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetNodeList(&req)
|
||||
l := log.NewFilterMobileLogLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterMobileLog(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package announcement
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/announcement"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Query announcement
|
||||
func QueryAnnouncementHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Filter register log
|
||||
func FilterRegisterLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.QueryAnnouncementRequest
|
||||
var req types.FilterRegisterLogRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func QueryAnnouncementHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := announcement.NewQueryAnnouncementLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryAnnouncement(&req)
|
||||
l := log.NewFilterRegisterLogLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterRegisterLog(&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 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)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package user
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/user"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Query User Affiliate List
|
||||
func QueryUserAffiliateListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Filter server traffic log
|
||||
func FilterServerTrafficLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.QueryUserAffiliateListRequest
|
||||
var req types.FilterServerTrafficLogRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func QueryUserAffiliateListHandler(svcCtx *svc.ServiceContext) func(c *gin.Conte
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewQueryUserAffiliateListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryUserAffiliateList(&req)
|
||||
l := log.NewFilterServerTrafficLogLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterServerTrafficLog(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package auth
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/auth"
|
||||
"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"
|
||||
)
|
||||
|
||||
// GetAppConfig
|
||||
func GetAppConfigHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Filter subscribe log
|
||||
func FilterSubscribeLogHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.AppConfigRequest
|
||||
var req types.FilterSubscribeLogRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func GetAppConfigHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := auth.NewGetAppConfigLogic(c, svcCtx)
|
||||
resp, err := l.GetAppConfig(&req)
|
||||
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 traffic log details
|
||||
func FilterTrafficLogDetailsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.FilterTrafficLogDetailsRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := log.NewFilterTrafficLogDetailsLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterTrafficLogDetails(&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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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/pkg/result"
|
||||
)
|
||||
|
||||
// Get log setting
|
||||
func GetLogSettingHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := log.NewGetLogSettingLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetLogSetting()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package order
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/order"
|
||||
"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"
|
||||
)
|
||||
|
||||
// Close order
|
||||
func CloseOrderHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Update log setting
|
||||
func UpdateLogSettingHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.CloseOrderRequest
|
||||
var req types.LogSetting
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func CloseOrderHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewCloseOrderLogic(c.Request.Context(), svcCtx)
|
||||
err := l.CloseOrder(&req)
|
||||
l := log.NewUpdateLogSettingLogic(c.Request.Context(), svcCtx)
|
||||
err := l.UpdateLogSetting(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package marketing
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/marketing"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Create a quota task
|
||||
func CreateQuotaTaskHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.CreateQuotaTaskRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := marketing.NewCreateQuotaTaskLogic(c.Request.Context(), svcCtx)
|
||||
err := l.CreateQuotaTask(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -1,17 +1,17 @@
|
||||
package auth
|
||||
package marketing
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/auth"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/marketing"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Check Account
|
||||
func CheckHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Query quota task list
|
||||
func QueryQuotaTaskListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.AppAuthCheckRequest
|
||||
var req types.QueryQuotaTaskListRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func CheckHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := auth.NewCheckLogic(c, svcCtx)
|
||||
resp, err := l.Check(&req)
|
||||
l := marketing.NewQueryQuotaTaskListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryQuotaTaskList(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package marketing
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/marketing"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Query quota task pre-count
|
||||
func QueryQuotaTaskPreCountHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.QueryQuotaTaskPreCountRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := marketing.NewQueryQuotaTaskPreCountLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryQuotaTaskPreCount(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package marketing
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/marketing"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Query quota task status
|
||||
func QueryQuotaTaskStatusHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.QueryQuotaTaskStatusRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := marketing.NewQueryQuotaTaskStatusLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryQuotaTaskStatus(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// Batch delete node group
|
||||
func BatchDeleteNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.BatchDeleteNodeGroupRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewBatchDeleteNodeGroupLogic(c.Request.Context(), svcCtx)
|
||||
err := l.BatchDeleteNodeGroup(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Create node
|
||||
// Create Node
|
||||
func CreateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.CreateNodeRequest
|
||||
|
||||
+5
-5
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Delete node group
|
||||
func DeleteNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// CreateServerHandler Create Server
|
||||
func CreateServerHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.DeleteNodeGroupRequest
|
||||
var req types.CreateServerRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func DeleteNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewDeleteNodeGroupLogic(c.Request.Context(), svcCtx)
|
||||
err := l.DeleteNodeGroup(&req)
|
||||
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"
|
||||
)
|
||||
|
||||
// Delete node
|
||||
// Delete Node
|
||||
func DeleteNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.DeleteNodeRequest
|
||||
|
||||
+5
-5
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Node sort
|
||||
func NodeSortHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Delete Server
|
||||
func DeleteServerHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.NodeSortRequest
|
||||
var req types.DeleteServerRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func NodeSortHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewNodeSortLogic(c.Request.Context(), svcCtx)
|
||||
err := l.NodeSort(&req)
|
||||
l := server.NewDeleteServerLogic(c.Request.Context(), svcCtx)
|
||||
err := l.DeleteServer(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get node detail
|
||||
func GetNodeDetailHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Filter Node List
|
||||
func FilterNodeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.GetDetailRequest
|
||||
var req types.FilterNodeListRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func GetNodeDetailHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewGetNodeDetailLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetNodeDetail(&req)
|
||||
l := server.NewFilterNodeListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterNodeList(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// CreateRuleGroupHandler Create rule group
|
||||
func CreateRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// FilterServerListHandler Filter Server List
|
||||
func FilterServerListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.CreateRuleGroupRequest
|
||||
var req types.FilterServerListRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func CreateRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewCreateRuleGroupLogic(c.Request.Context(), svcCtx)
|
||||
err := l.CreateRuleGroup(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
l := server.NewFilterServerListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.FilterServerList(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get node list
|
||||
func GetNodeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Get Server Protocols
|
||||
func GetServerProtocolsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.GetNodeServerListRequest
|
||||
var req types.GetServerProtocolsRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func GetNodeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewGetNodeListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetNodeList(&req)
|
||||
l := server.NewGetServerProtocolsLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetServerProtocols(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -7,12 +7,12 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get node group list
|
||||
func GetNodeGroupListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Check if there is any server or node to migrate
|
||||
func HasMigrateSeverNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := server.NewGetNodeGroupListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetNodeGroupList()
|
||||
l := server.NewHasMigrateSeverNodeLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.HasMigrateSeverNode()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -7,12 +7,12 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get rule group list
|
||||
func GetRuleGroupListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Migrate server and node data to new database
|
||||
func MigrateServerNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := server.NewGetRuleGroupListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetRuleGroupList()
|
||||
l := server.NewMigrateServerNodeLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.MigrateServerNode()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -7,12 +7,12 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get node tag list
|
||||
func GetNodeTagListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Query all node tags
|
||||
func QueryNodeTagHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := server.NewGetNodeTagListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetNodeTagList()
|
||||
l := server.NewQueryNodeTagLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryNodeTag()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Batch delete node
|
||||
func BatchDeleteNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Reset node sort
|
||||
func ResetSortWithNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.BatchDeleteNodeRequest
|
||||
var req types.ResetSortRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func BatchDeleteNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewBatchDeleteNodeLogic(c.Request.Context(), svcCtx)
|
||||
err := l.BatchDeleteNode(&req)
|
||||
l := server.NewResetSortWithNodeLogic(c.Request.Context(), svcCtx)
|
||||
err := l.ResetSortWithNode(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
// Reset server sort
|
||||
func ResetSortWithServerHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.ResetSortRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewResetSortWithServerLogic(c.Request.Context(), svcCtx)
|
||||
err := l.ResetSortWithServer(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Delete rule group
|
||||
func DeleteRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Toggle Node Status
|
||||
func ToggleNodeStatusHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.DeleteRuleGroupRequest
|
||||
var req types.ToggleNodeStatusRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func DeleteRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewDeleteRuleGroupLogic(c.Request.Context(), svcCtx)
|
||||
err := l.DeleteRuleGroup(&req)
|
||||
l := server.NewToggleNodeStatusLogic(c.Request.Context(), svcCtx)
|
||||
err := l.ToggleNodeStatus(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
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 node group
|
||||
func UpdateNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.UpdateNodeGroupRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewUpdateNodeGroupLogic(c.Request.Context(), svcCtx)
|
||||
err := l.UpdateNodeGroup(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Update node
|
||||
// Update Node
|
||||
func UpdateNodeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.UpdateNodeRequest
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
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 rule group
|
||||
func UpdateRuleGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.UpdateRuleGroupRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewUpdateRuleGroupLogic(c.Request.Context(), svcCtx)
|
||||
err := l.UpdateRuleGroup(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -8,10 +8,10 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Create node group
|
||||
func CreateNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
// Update Server
|
||||
func UpdateServerHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.CreateNodeGroupRequest
|
||||
var req types.UpdateServerRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
@@ -19,8 +19,8 @@ func CreateNodeGroupHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewCreateNodeGroupLogic(c.Request.Context(), svcCtx)
|
||||
err := l.CreateNodeGroup(&req)
|
||||
l := server.NewUpdateServerLogic(c.Request.Context(), svcCtx)
|
||||
err := l.UpdateServer(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Create application
|
||||
func CreateApplicationHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.CreateApplicationRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := system.NewCreateApplicationLogic(c.Request.Context(), svcCtx)
|
||||
err := l.CreateApplication(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Create application version
|
||||
func CreateApplicationVersionHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.CreateApplicationVersionRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := system.NewCreateApplicationVersionLogic(c.Request.Context(), svcCtx)
|
||||
err := l.CreateApplicationVersion(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Delete application
|
||||
func DeleteApplicationHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.DeleteApplicationRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := system.NewDeleteApplicationLogic(c.Request.Context(), svcCtx)
|
||||
err := l.DeleteApplication(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Delete application
|
||||
func DeleteApplicationVersionHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.DeleteApplicationVersionRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := system.NewDeleteApplicationVersionLogic(c.Request.Context(), svcCtx)
|
||||
err := l.DeleteApplicationVersion(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// get application config
|
||||
func GetApplicationConfigHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := system.NewGetApplicationConfigLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetApplicationConfig()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get application
|
||||
func GetApplicationHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := system.NewGetApplicationLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetApplication()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get subscribe type
|
||||
func GetSubscribeTypeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := system.NewGetSubscribeTypeLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetSubscribeType()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// update application config
|
||||
func UpdateApplicationConfigHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.ApplicationConfig
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := system.NewUpdateApplicationConfigLogic(c.Request.Context(), svcCtx)
|
||||
err := l.UpdateApplicationConfig(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Update application
|
||||
func UpdateApplicationHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.UpdateApplicationRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := system.NewUpdateApplicationLogic(c.Request.Context(), svcCtx)
|
||||
err := l.UpdateApplication(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Update application version
|
||||
func UpdateApplicationVersionHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.UpdateApplicationVersionRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := system.NewUpdateApplicationVersionLogic(c.Request.Context(), svcCtx)
|
||||
err := l.UpdateApplicationVersion(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/admin/user"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get user subcribe reset traffic logs
|
||||
func GetUserSubscribeResetTrafficLogsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.GetUserSubscribeResetTrafficLogsRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewGetUserSubscribeResetTrafficLogsLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetUserSubscribeResetTrafficLogs(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/auth"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
"github.com/perfect-panel/server/pkg/turnstile"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Login
|
||||
func LoginHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.AppAuthRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
if svcCtx.Config.Verify.LoginVerify {
|
||||
verifyTurns := turnstile.New(turnstile.Config{
|
||||
Secret: svcCtx.Config.Verify.TurnstileSecret,
|
||||
Timeout: 3 * time.Second,
|
||||
})
|
||||
if verify, err := verifyTurns.Verify(c, req.CfToken, c.ClientIP()); err != nil || !verify {
|
||||
err = errors.Wrapf(xerr.NewErrCode(xerr.TooManyRequests), "error: %v, verify: %v", err, verify)
|
||||
result.HttpResult(c, nil, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
l := auth.NewLoginLogic(c, svcCtx)
|
||||
resp, err := l.Login(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/auth"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
"github.com/perfect-panel/server/pkg/turnstile"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Register
|
||||
func RegisterHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.AppAuthRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
// get client ip
|
||||
if svcCtx.Config.Verify.RegisterVerify {
|
||||
verifyTurns := turnstile.New(turnstile.Config{
|
||||
Secret: svcCtx.Config.Verify.TurnstileSecret,
|
||||
Timeout: 3 * time.Second,
|
||||
})
|
||||
if verify, err := verifyTurns.Verify(c, req.CfToken, c.ClientIP()); err != nil || !verify {
|
||||
err = errors.Wrapf(xerr.NewErrCode(xerr.TooManyRequests), "error: %v, verify: %v", err, verify)
|
||||
result.HttpResult(c, nil, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
l := auth.NewRegisterLogic(c, svcCtx)
|
||||
resp, err := l.Register(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/auth"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
"github.com/perfect-panel/server/pkg/turnstile"
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Reset Password
|
||||
func ResetPasswordHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.AppAuthRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
if svcCtx.Config.Verify.ResetPasswordVerify {
|
||||
verifyTurns := turnstile.New(turnstile.Config{
|
||||
Secret: svcCtx.Config.Verify.TurnstileSecret,
|
||||
Timeout: 3 * time.Second,
|
||||
})
|
||||
if verify, err := verifyTurns.Verify(c, req.CfToken, c.ClientIP()); err != nil || !verify {
|
||||
err = errors.Wrapf(xerr.NewErrCode(xerr.TooManyRequests), "error: %v, verify: %v", err, verify)
|
||||
result.HttpResult(c, nil, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
l := auth.NewResetPasswordLogic(c, svcCtx)
|
||||
resp, err := l.ResetPassword(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package document
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/document"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get document list
|
||||
func QueryDocumentListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := document.NewQueryDocumentListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryDocumentList()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/node"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get rule group list
|
||||
func GetRuleGroupListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := node.NewGetRuleGroupListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetRuleGroupList()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/order"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// purchase Subscription
|
||||
func PurchaseHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.PurchaseOrderRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewPurchaseLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.Purchase(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/order"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Recharge
|
||||
func RechargeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.RechargeOrderRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewRechargeLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.Recharge(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/order"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Renewal Subscription
|
||||
func RenewalHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.RenewalOrderRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewRenewalLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.Renewal(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/order"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Reset traffic
|
||||
func ResetTrafficHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.ResetTrafficOrderRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := order.NewResetTrafficLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.ResetTraffic(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package payment
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/payment"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get available payment methods
|
||||
func GetAvailablePaymentMethodsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := payment.NewGetAvailablePaymentMethodsLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetAvailablePaymentMethods()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package subscribe
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/subscribe"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get application config
|
||||
func QueryApplicationConfigHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := subscribe.NewQueryApplicationConfigLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryApplicationConfig()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package subscribe
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/subscribe"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get subscribe group list
|
||||
func QuerySubscribeGroupListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := subscribe.NewQuerySubscribeGroupListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QuerySubscribeGroupList()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package subscribe
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/subscribe"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get subscribe list
|
||||
func QuerySubscribeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := subscribe.NewQuerySubscribeListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QuerySubscribeList()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package subscribe
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/subscribe"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get Already subscribed to package
|
||||
func QueryUserAlreadySubscribeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := subscribe.NewQueryUserAlreadySubscribeLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryUserAlreadySubscribe()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package subscribe
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/subscribe"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get Available subscriptions for users
|
||||
func QueryUserAvailableUserSubscribeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.AppUserSubscribeRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := subscribe.NewQueryUserAvailableUserSubscribeLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryUserAvailableUserSubscribe(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package subscribe
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/subscribe"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Reset user subscription period
|
||||
func ResetUserSubscribePeriodHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.UserSubscribeResetPeriodRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := subscribe.NewResetUserSubscribePeriodLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.ResetUserSubscribePeriod(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/user"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Delete Account
|
||||
func DeleteAccountHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.DeleteAccountRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewDeleteAccountLogic(c.Request.Context(), svcCtx)
|
||||
err := l.DeleteAccount(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/user"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get user online time total
|
||||
func GetUserOnlineTimeStatisticsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := user.NewGetUserOnlineTimeStatisticsLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetUserOnlineTimeStatistics()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/user"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get user subcribe traffic logs
|
||||
func GetUserSubscribeTrafficLogsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.GetUserSubscribeTrafficLogsRequest
|
||||
_ = c.BindQuery(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewGetUserSubscribeTrafficLogsLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetUserSubscribeTrafficLogs(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/user"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// query user info
|
||||
func QueryUserInfoHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := user.NewQueryUserInfoLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryUserInfo()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/user"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Query User Affiliate Count
|
||||
func QueryUserAffiliateHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := user.NewQueryUserAffiliateLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryUserAffiliate()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/user"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Update Password
|
||||
func UpdatePasswordHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.UpdatePasswordRequeset
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewUpdatePasswordLogic(c.Request.Context(), svcCtx)
|
||||
err := l.UpdatePassword(&req)
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/app/ws"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// App heartbeat
|
||||
func AppWsHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
ctx := c.Request.Context()
|
||||
|
||||
// Logic: App heartbeat
|
||||
l := ws.NewAppWsLogic(ctx, svcCtx)
|
||||
err := l.AppWs(c.Writer, c.Request, c.Param("userid"), c.Param("identifier"))
|
||||
result.HttpResult(c, nil, err)
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ func TelephoneUserRegisterHandler(svcCtx *svc.ServiceContext) func(c *gin.Contex
|
||||
}
|
||||
// get client ip
|
||||
req.IP = c.ClientIP()
|
||||
req.UserAgent = c.Request.UserAgent()
|
||||
if svcCtx.Config.Verify.RegisterVerify {
|
||||
verifyTurns := turnstile.New(turnstile.Config{
|
||||
Secret: svcCtx.Config.Verify.TurnstileSecret,
|
||||
|
||||
@@ -20,6 +20,7 @@ func UserRegisterHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
_ = c.ShouldBind(&req)
|
||||
// get client ip
|
||||
req.IP = c.ClientIP()
|
||||
req.UserAgent = c.Request.UserAgent()
|
||||
if svcCtx.Config.Verify.RegisterVerify {
|
||||
verifyTurns := turnstile.New(turnstile.Config{
|
||||
Secret: svcCtx.Config.Verify.TurnstileSecret,
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/common"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get Tos Content
|
||||
func GetApplicationHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := common.NewGetApplicationLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetApplication()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/common"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get Subscription
|
||||
func GetSubscriptionHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := common.NewGetSubscriptionLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetSubscription()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func PaymentNotifyHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
}
|
||||
|
||||
switch payment.ParsePlatform(platform) {
|
||||
case payment.EPay:
|
||||
case payment.EPay, payment.CryptoSaaS:
|
||||
req := &types.EPayNotifyRequest{}
|
||||
if err := c.ShouldBind(req); err != nil {
|
||||
result.HttpResult(c, nil, err)
|
||||
|
||||
@@ -4,14 +4,23 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/public/portal"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get Subscription
|
||||
func GetSubscriptionHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.GetSubscriptionRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := portal.NewGetSubscriptionLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.GetSubscription()
|
||||
resp, err := l.GetSubscription(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Purchase Checkout
|
||||
// PurchaseCheckoutHandler Purchase Checkout
|
||||
func PurchaseCheckoutHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.CheckoutOrderRequest
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package subscribe
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/public/subscribe"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get application config
|
||||
func QueryApplicationConfigHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
|
||||
l := subscribe.NewQueryApplicationConfigLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryApplicationConfig()
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,23 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/public/subscribe"
|
||||
"github.com/perfect-panel/server/internal/svc"
|
||||
"github.com/perfect-panel/server/internal/types"
|
||||
"github.com/perfect-panel/server/pkg/result"
|
||||
)
|
||||
|
||||
// Get subscribe list
|
||||
// QuerySubscribeListHandler Get subscribe list
|
||||
func QuerySubscribeListHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.QuerySubscribeListRequest
|
||||
_ = c.ShouldBind(&req)
|
||||
validateErr := svcCtx.Validate(&req)
|
||||
if validateErr != nil {
|
||||
result.ParamErrorResult(c, validateErr)
|
||||
return
|
||||
}
|
||||
|
||||
l := subscribe.NewQuerySubscribeListLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QuerySubscribeList()
|
||||
resp, err := l.QuerySubscribeList(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
+91
-231
@@ -22,15 +22,6 @@ import (
|
||||
adminTicket "github.com/perfect-panel/server/internal/handler/admin/ticket"
|
||||
adminTool "github.com/perfect-panel/server/internal/handler/admin/tool"
|
||||
adminUser "github.com/perfect-panel/server/internal/handler/admin/user"
|
||||
appAnnouncement "github.com/perfect-panel/server/internal/handler/app/announcement"
|
||||
appAuth "github.com/perfect-panel/server/internal/handler/app/auth"
|
||||
appDocument "github.com/perfect-panel/server/internal/handler/app/document"
|
||||
appNode "github.com/perfect-panel/server/internal/handler/app/node"
|
||||
appOrder "github.com/perfect-panel/server/internal/handler/app/order"
|
||||
appPayment "github.com/perfect-panel/server/internal/handler/app/payment"
|
||||
appSubscribe "github.com/perfect-panel/server/internal/handler/app/subscribe"
|
||||
appUser "github.com/perfect-panel/server/internal/handler/app/user"
|
||||
appWs "github.com/perfect-panel/server/internal/handler/app/ws"
|
||||
auth "github.com/perfect-panel/server/internal/handler/auth"
|
||||
authOauth "github.com/perfect-panel/server/internal/handler/auth/oauth"
|
||||
common "github.com/perfect-panel/server/internal/handler/common"
|
||||
@@ -198,8 +189,50 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
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
|
||||
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))
|
||||
|
||||
// Get log setting
|
||||
adminLogGroupRouter.GET("/setting", adminLog.GetLogSettingHandler(serverCtx))
|
||||
|
||||
// Update log setting
|
||||
adminLogGroupRouter.POST("/setting", adminLog.UpdateLogSettingHandler(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))
|
||||
|
||||
// Filter traffic log details
|
||||
adminLogGroupRouter.GET("/traffic/details", adminLog.FilterTrafficLogDetailsHandler(serverCtx))
|
||||
}
|
||||
|
||||
adminMarketingGroupRouter := router.Group("/v1/admin/marketing")
|
||||
@@ -220,6 +253,15 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
|
||||
// Stop a batch send email task
|
||||
adminMarketingGroupRouter.POST("/email/batch/stop", adminMarketing.StopBatchSendEmailTaskHandler(serverCtx))
|
||||
|
||||
// Create a quota task
|
||||
adminMarketingGroupRouter.POST("/quota/create", adminMarketing.CreateQuotaTaskHandler(serverCtx))
|
||||
|
||||
// Query quota task list
|
||||
adminMarketingGroupRouter.GET("/quota/list", adminMarketing.QueryQuotaTaskListHandler(serverCtx))
|
||||
|
||||
// Query quota task pre-count
|
||||
adminMarketingGroupRouter.POST("/quota/pre-count", adminMarketing.QueryQuotaTaskPreCountHandler(serverCtx))
|
||||
}
|
||||
|
||||
adminOrderGroupRouter := router.Group("/v1/admin/order")
|
||||
@@ -260,56 +302,50 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
adminServerGroupRouter.Use(middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Update node
|
||||
adminServerGroupRouter.PUT("/", adminServer.UpdateNodeHandler(serverCtx))
|
||||
// Create Server
|
||||
adminServerGroupRouter.POST("/create", adminServer.CreateServerHandler(serverCtx))
|
||||
|
||||
// Create node
|
||||
adminServerGroupRouter.POST("/", adminServer.CreateNodeHandler(serverCtx))
|
||||
// Delete Server
|
||||
adminServerGroupRouter.POST("/delete", adminServer.DeleteServerHandler(serverCtx))
|
||||
|
||||
// Delete node
|
||||
adminServerGroupRouter.DELETE("/", adminServer.DeleteNodeHandler(serverCtx))
|
||||
// Filter Server List
|
||||
adminServerGroupRouter.GET("/list", adminServer.FilterServerListHandler(serverCtx))
|
||||
|
||||
// Batch delete node
|
||||
adminServerGroupRouter.DELETE("/batch", adminServer.BatchDeleteNodeHandler(serverCtx))
|
||||
// Check if there is any server or node to migrate
|
||||
adminServerGroupRouter.GET("/migrate/has", adminServer.HasMigrateSeverNodeHandler(serverCtx))
|
||||
|
||||
// Get node detail
|
||||
adminServerGroupRouter.GET("/detail", adminServer.GetNodeDetailHandler(serverCtx))
|
||||
// Migrate server and node data to new database
|
||||
adminServerGroupRouter.POST("/migrate/run", adminServer.MigrateServerNodeHandler(serverCtx))
|
||||
|
||||
// Create node group
|
||||
adminServerGroupRouter.POST("/group", adminServer.CreateNodeGroupHandler(serverCtx))
|
||||
// Create Node
|
||||
adminServerGroupRouter.POST("/node/create", adminServer.CreateNodeHandler(serverCtx))
|
||||
|
||||
// Update node group
|
||||
adminServerGroupRouter.PUT("/group", adminServer.UpdateNodeGroupHandler(serverCtx))
|
||||
// Delete Node
|
||||
adminServerGroupRouter.POST("/node/delete", adminServer.DeleteNodeHandler(serverCtx))
|
||||
|
||||
// Delete node group
|
||||
adminServerGroupRouter.DELETE("/group", adminServer.DeleteNodeGroupHandler(serverCtx))
|
||||
// Filter Node List
|
||||
adminServerGroupRouter.GET("/node/list", adminServer.FilterNodeListHandler(serverCtx))
|
||||
|
||||
// Batch delete node group
|
||||
adminServerGroupRouter.DELETE("/group/batch", adminServer.BatchDeleteNodeGroupHandler(serverCtx))
|
||||
// Reset node sort
|
||||
adminServerGroupRouter.POST("/node/sort", adminServer.ResetSortWithNodeHandler(serverCtx))
|
||||
|
||||
// Get node group list
|
||||
adminServerGroupRouter.GET("/group/list", adminServer.GetNodeGroupListHandler(serverCtx))
|
||||
// Toggle Node Status
|
||||
adminServerGroupRouter.POST("/node/status/toggle", adminServer.ToggleNodeStatusHandler(serverCtx))
|
||||
|
||||
// Get node list
|
||||
adminServerGroupRouter.GET("/list", adminServer.GetNodeListHandler(serverCtx))
|
||||
// Query all node tags
|
||||
adminServerGroupRouter.GET("/node/tags", adminServer.QueryNodeTagHandler(serverCtx))
|
||||
|
||||
// Create rule group
|
||||
adminServerGroupRouter.POST("/rule_group", adminServer.CreateRuleGroupHandler(serverCtx))
|
||||
// Update Node
|
||||
adminServerGroupRouter.POST("/node/update", adminServer.UpdateNodeHandler(serverCtx))
|
||||
|
||||
// Update rule group
|
||||
adminServerGroupRouter.PUT("/rule_group", adminServer.UpdateRuleGroupHandler(serverCtx))
|
||||
// Get Server Protocols
|
||||
adminServerGroupRouter.GET("/protocols", adminServer.GetServerProtocolsHandler(serverCtx))
|
||||
|
||||
// Delete rule group
|
||||
adminServerGroupRouter.DELETE("/rule_group", adminServer.DeleteRuleGroupHandler(serverCtx))
|
||||
// Reset server sort
|
||||
adminServerGroupRouter.POST("/server/sort", adminServer.ResetSortWithServerHandler(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))
|
||||
// Update Server
|
||||
adminServerGroupRouter.POST("/update", adminServer.UpdateServerHandler(serverCtx))
|
||||
}
|
||||
|
||||
adminSubscribeGroupRouter := router.Group("/v1/admin/subscribe")
|
||||
@@ -357,33 +393,6 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
adminSystemGroupRouter.Use(middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Get application
|
||||
adminSystemGroupRouter.GET("/application", adminSystem.GetApplicationHandler(serverCtx))
|
||||
|
||||
// Update application
|
||||
adminSystemGroupRouter.PUT("/application", adminSystem.UpdateApplicationHandler(serverCtx))
|
||||
|
||||
// Create application
|
||||
adminSystemGroupRouter.POST("/application", adminSystem.CreateApplicationHandler(serverCtx))
|
||||
|
||||
// Delete application
|
||||
adminSystemGroupRouter.DELETE("/application", adminSystem.DeleteApplicationHandler(serverCtx))
|
||||
|
||||
// update application config
|
||||
adminSystemGroupRouter.PUT("/application_config", adminSystem.UpdateApplicationConfigHandler(serverCtx))
|
||||
|
||||
// get application config
|
||||
adminSystemGroupRouter.GET("/application_config", adminSystem.GetApplicationConfigHandler(serverCtx))
|
||||
|
||||
// Update application version
|
||||
adminSystemGroupRouter.PUT("/application_version", adminSystem.UpdateApplicationVersionHandler(serverCtx))
|
||||
|
||||
// Create application version
|
||||
adminSystemGroupRouter.POST("/application_version", adminSystem.CreateApplicationVersionHandler(serverCtx))
|
||||
|
||||
// Delete application
|
||||
adminSystemGroupRouter.DELETE("/application_version", adminSystem.DeleteApplicationVersionHandler(serverCtx))
|
||||
|
||||
// Get Currency Config
|
||||
adminSystemGroupRouter.GET("/currency_config", adminSystem.GetCurrencyConfigHandler(serverCtx))
|
||||
|
||||
@@ -435,9 +444,6 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
// Update subscribe config
|
||||
adminSystemGroupRouter.PUT("/subscribe_config", adminSystem.UpdateSubscribeConfigHandler(serverCtx))
|
||||
|
||||
// Get subscribe type
|
||||
adminSystemGroupRouter.GET("/subscribe_type", adminSystem.GetSubscribeTypeHandler(serverCtx))
|
||||
|
||||
// Get Team of Service Config
|
||||
adminSystemGroupRouter.GET("/tos_config", adminSystem.GetTosConfigHandler(serverCtx))
|
||||
|
||||
@@ -561,157 +567,13 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
// Get user subcribe logs
|
||||
adminUserGroupRouter.GET("/subscribe/logs", adminUser.GetUserSubscribeLogsHandler(serverCtx))
|
||||
|
||||
// Get user subcribe reset traffic logs
|
||||
adminUserGroupRouter.GET("/subscribe/reset/logs", adminUser.GetUserSubscribeResetTrafficLogsHandler(serverCtx))
|
||||
|
||||
// Get user subcribe traffic logs
|
||||
adminUserGroupRouter.GET("/subscribe/traffic_logs", adminUser.GetUserSubscribeTrafficLogsHandler(serverCtx))
|
||||
}
|
||||
|
||||
appAnnouncementGroupRouter := router.Group("/v1/app/announcement")
|
||||
appAnnouncementGroupRouter.Use(middleware.AppMiddleware(serverCtx), middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Query announcement
|
||||
appAnnouncementGroupRouter.GET("/list", appAnnouncement.QueryAnnouncementHandler(serverCtx))
|
||||
}
|
||||
|
||||
appAuthGroupRouter := router.Group("/v1/app/auth")
|
||||
appAuthGroupRouter.Use(middleware.AppMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Check Account
|
||||
appAuthGroupRouter.POST("/check", appAuth.CheckHandler(serverCtx))
|
||||
|
||||
// GetAppConfig
|
||||
appAuthGroupRouter.POST("/config", appAuth.GetAppConfigHandler(serverCtx))
|
||||
|
||||
// Login
|
||||
appAuthGroupRouter.POST("/login", appAuth.LoginHandler(serverCtx))
|
||||
|
||||
// Register
|
||||
appAuthGroupRouter.POST("/register", appAuth.RegisterHandler(serverCtx))
|
||||
|
||||
// Reset Password
|
||||
appAuthGroupRouter.POST("/reset_password", appAuth.ResetPasswordHandler(serverCtx))
|
||||
}
|
||||
|
||||
appDocumentGroupRouter := router.Group("/v1/app/document")
|
||||
appDocumentGroupRouter.Use(middleware.AppMiddleware(serverCtx), middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Get document detail
|
||||
appDocumentGroupRouter.GET("/detail", appDocument.QueryDocumentDetailHandler(serverCtx))
|
||||
|
||||
// Get document list
|
||||
appDocumentGroupRouter.GET("/list", appDocument.QueryDocumentListHandler(serverCtx))
|
||||
}
|
||||
|
||||
appNodeGroupRouter := router.Group("/v1/app/node")
|
||||
appNodeGroupRouter.Use(middleware.AppMiddleware(serverCtx), middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Get Node list
|
||||
appNodeGroupRouter.GET("/list", appNode.GetNodeListHandler(serverCtx))
|
||||
|
||||
// Get rule group list
|
||||
appNodeGroupRouter.GET("/rule_group_list", appNode.GetRuleGroupListHandler(serverCtx))
|
||||
}
|
||||
|
||||
appOrderGroupRouter := router.Group("/v1/app/order")
|
||||
appOrderGroupRouter.Use(middleware.AppMiddleware(serverCtx), middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Checkout order
|
||||
appOrderGroupRouter.POST("/checkout", appOrder.CheckoutOrderHandler(serverCtx))
|
||||
|
||||
// Close order
|
||||
appOrderGroupRouter.POST("/close", appOrder.CloseOrderHandler(serverCtx))
|
||||
|
||||
// Get order
|
||||
appOrderGroupRouter.GET("/detail", appOrder.QueryOrderDetailHandler(serverCtx))
|
||||
|
||||
// Get order list
|
||||
appOrderGroupRouter.GET("/list", appOrder.QueryOrderListHandler(serverCtx))
|
||||
|
||||
// Pre create order
|
||||
appOrderGroupRouter.POST("/pre", appOrder.PreCreateOrderHandler(serverCtx))
|
||||
|
||||
// purchase Subscription
|
||||
appOrderGroupRouter.POST("/purchase", appOrder.PurchaseHandler(serverCtx))
|
||||
|
||||
// Recharge
|
||||
appOrderGroupRouter.POST("/recharge", appOrder.RechargeHandler(serverCtx))
|
||||
|
||||
// Renewal Subscription
|
||||
appOrderGroupRouter.POST("/renewal", appOrder.RenewalHandler(serverCtx))
|
||||
|
||||
// Reset traffic
|
||||
appOrderGroupRouter.POST("/reset", appOrder.ResetTrafficHandler(serverCtx))
|
||||
}
|
||||
|
||||
appPaymentGroupRouter := router.Group("/v1/app/payment")
|
||||
appPaymentGroupRouter.Use(middleware.AppMiddleware(serverCtx), middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Get available payment methods
|
||||
appPaymentGroupRouter.GET("/methods", appPayment.GetAvailablePaymentMethodsHandler(serverCtx))
|
||||
}
|
||||
|
||||
appSubscribeGroupRouter := router.Group("/v1/app/subscribe")
|
||||
appSubscribeGroupRouter.Use(middleware.AppMiddleware(serverCtx), middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Get application config
|
||||
appSubscribeGroupRouter.GET("/application/config", appSubscribe.QueryApplicationConfigHandler(serverCtx))
|
||||
|
||||
// Get subscribe group list
|
||||
appSubscribeGroupRouter.GET("/group/list", appSubscribe.QuerySubscribeGroupListHandler(serverCtx))
|
||||
|
||||
// Get subscribe list
|
||||
appSubscribeGroupRouter.GET("/list", appSubscribe.QuerySubscribeListHandler(serverCtx))
|
||||
|
||||
// Reset user subscription period
|
||||
appSubscribeGroupRouter.POST("/reset/period", appSubscribe.ResetUserSubscribePeriodHandler(serverCtx))
|
||||
|
||||
// Get Already subscribed to package
|
||||
appSubscribeGroupRouter.GET("/user/already_subscribe", appSubscribe.QueryUserAlreadySubscribeHandler(serverCtx))
|
||||
|
||||
// Get Available subscriptions for users
|
||||
appSubscribeGroupRouter.GET("/user/available_subscribe", appSubscribe.QueryUserAvailableUserSubscribeHandler(serverCtx))
|
||||
}
|
||||
|
||||
appUserGroupRouter := router.Group("/v1/app/user")
|
||||
appUserGroupRouter.Use(middleware.AppMiddleware(serverCtx), middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Delete Account
|
||||
appUserGroupRouter.DELETE("/account", appUser.DeleteAccountHandler(serverCtx))
|
||||
|
||||
// Query User Affiliate Count
|
||||
appUserGroupRouter.GET("/affiliate/count", appUser.QueryUserAffiliateHandler(serverCtx))
|
||||
|
||||
// Query User Affiliate List
|
||||
appUserGroupRouter.GET("/affiliate/list", appUser.QueryUserAffiliateListHandler(serverCtx))
|
||||
|
||||
// query user info
|
||||
appUserGroupRouter.GET("/info", appUser.QueryUserInfoHandler(serverCtx))
|
||||
|
||||
// Get user online time total
|
||||
appUserGroupRouter.GET("/online_time/statistics", appUser.GetUserOnlineTimeStatisticsHandler(serverCtx))
|
||||
|
||||
// Update Password
|
||||
appUserGroupRouter.PUT("/password", appUser.UpdatePasswordHandler(serverCtx))
|
||||
|
||||
// Get user subcribe traffic logs
|
||||
appUserGroupRouter.GET("/subscribe/traffic_logs", appUser.GetUserSubscribeTrafficLogsHandler(serverCtx))
|
||||
}
|
||||
|
||||
appWsGroupRouter := router.Group("/v1/app/ws")
|
||||
appWsGroupRouter.Use(middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// App heartbeat
|
||||
appWsGroupRouter.GET("/:userid/:identifier", appWs.AppWsHandler(serverCtx))
|
||||
}
|
||||
|
||||
authGroupRouter := router.Group("/v1/auth")
|
||||
|
||||
{
|
||||
@@ -759,9 +621,6 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
// Get Ads
|
||||
commonGroupRouter.GET("/ads", common.GetAdsHandler(serverCtx))
|
||||
|
||||
// Get Tos Content
|
||||
commonGroupRouter.GET("/application", common.GetApplicationHandler(serverCtx))
|
||||
|
||||
// Check verification code
|
||||
commonGroupRouter.POST("/check_verification_code", common.CheckVerificationCodeHandler(serverCtx))
|
||||
|
||||
@@ -869,12 +728,6 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
publicSubscribeGroupRouter.Use(middleware.AuthMiddleware(serverCtx))
|
||||
|
||||
{
|
||||
// Get application config
|
||||
publicSubscribeGroupRouter.GET("/application/config", publicSubscribe.QueryApplicationConfigHandler(serverCtx))
|
||||
|
||||
// Get subscribe group list
|
||||
publicSubscribeGroupRouter.GET("/group/list", publicSubscribe.QuerySubscribeGroupListHandler(serverCtx))
|
||||
|
||||
// Get subscribe list
|
||||
publicSubscribeGroupRouter.GET("/list", publicSubscribe.QuerySubscribeListHandler(serverCtx))
|
||||
}
|
||||
@@ -989,4 +842,11 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
||||
// Get user list
|
||||
serverGroupRouter.GET("/user", server.GetServerUserListHandler(serverCtx))
|
||||
}
|
||||
|
||||
serverV2GroupRouter := router.Group("/v2/server")
|
||||
|
||||
{
|
||||
// Get Server Protocol Config
|
||||
serverV2GroupRouter.GET("/:server_id", server.QueryServerProtocolConfigHandler(serverCtx))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/perfect-panel/server/internal/logic/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/result"
|
||||
)
|
||||
|
||||
// QueryServerProtocolConfigHandler Get Server Protocol Config
|
||||
func QueryServerProtocolConfigHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.QueryServerConfigRequest
|
||||
|
||||
serverID, err := strconv.ParseInt(c.Param("server_id"), 10, 64)
|
||||
if err != nil {
|
||||
logger.Debugf("[QueryServerProtocolConfigHandler] - strconv.ParseInt(server_id) error: %v, Param: %s", err, c.Param("server_id"))
|
||||
c.String(http.StatusBadRequest, "Invalid Params")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
req.ServerID = serverID
|
||||
|
||||
key := c.GetHeader("secret_key")
|
||||
if key == "" || key != svcCtx.Config.Node.NodeSecret {
|
||||
logger.Debugf("[QueryServerProtocolConfigHandler] - secret_key error: %s", key)
|
||||
c.String(http.StatusUnauthorized, "Unauthorized")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
l := server.NewQueryServerProtocolConfigLogic(c.Request.Context(), svcCtx)
|
||||
resp, err := l.QueryServerProtocolConfig(&req)
|
||||
result.HttpResult(c, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"github.com/perfect-panel/server/internal/logic/subscribe"
|
||||
"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"
|
||||
)
|
||||
|
||||
func SubscribeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
@@ -18,63 +20,50 @@ func SubscribeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
} else {
|
||||
req.Token = c.Query("token")
|
||||
}
|
||||
ua := c.GetHeader("User-Agent")
|
||||
req.UA = c.Request.Header.Get("User-Agent")
|
||||
req.Flag = c.Query("flag")
|
||||
|
||||
// intercept browser
|
||||
ua := c.GetHeader("User-Agent")
|
||||
if ua == "" {
|
||||
c.String(http.StatusForbidden, "Access denied")
|
||||
return
|
||||
}
|
||||
browserKeywords := []string{"chrome", "firefox", "safari", "edge", "opera", "micromessenger"}
|
||||
for _, keyword := range browserKeywords {
|
||||
lcUA := strings.ToLower(ua)
|
||||
if strings.Contains(lcUA, keyword) {
|
||||
if svcCtx.Config.Subscribe.UserAgentLimit {
|
||||
if ua == "" {
|
||||
c.String(http.StatusForbidden, "Access denied")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
clientUserAgents := tool.RemoveDuplicateElements(strings.Split(svcCtx.Config.Subscribe.UserAgentList, "\n")...)
|
||||
|
||||
// query client list
|
||||
clients, err := svcCtx.ClientModel.List(c.Request.Context())
|
||||
if err != nil {
|
||||
logger.Errorw("[PanDomainMiddleware] Query client list failed", logger.Field("error", err.Error()))
|
||||
}
|
||||
for _, item := range clients {
|
||||
u := strings.ToLower(item.UserAgent)
|
||||
u = strings.Trim(u, " ")
|
||||
clientUserAgents = append(clientUserAgents, u)
|
||||
}
|
||||
|
||||
var allow = false
|
||||
for _, keyword := range clientUserAgents {
|
||||
keyword = strings.Trim(keyword, " ")
|
||||
if keyword == "" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(strings.ToLower(ua), strings.ToLower(keyword)) {
|
||||
allow = true
|
||||
}
|
||||
}
|
||||
if !allow {
|
||||
c.String(http.StatusForbidden, "Access denied")
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
l := subscribe.NewSubscribeLogic(c, svcCtx)
|
||||
resp, err := l.Generate(&req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
c.Header("subscription-userinfo", resp.Header)
|
||||
c.String(200, "%s", string(resp.Config))
|
||||
}
|
||||
}
|
||||
|
||||
func V2SubscribeHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||
return func(c *gin.Context) {
|
||||
var req types.SubscribeRequest
|
||||
if c.Request.Header.Get("token") != "" {
|
||||
req.Token = c.Request.Header.Get("token")
|
||||
} else {
|
||||
req.Token = c.Query("token")
|
||||
}
|
||||
req.UA = c.Request.Header.Get("User-Agent")
|
||||
req.Flag = c.Query("flag")
|
||||
|
||||
// intercept browser
|
||||
ua := c.GetHeader("User-Agent")
|
||||
if ua == "" {
|
||||
c.String(http.StatusForbidden, "Access denied")
|
||||
return
|
||||
}
|
||||
browserKeywords := []string{"chrome", "firefox", "safari", "edge", "opera", "micromessenger"}
|
||||
for _, keyword := range browserKeywords {
|
||||
lcUA := strings.ToLower(ua)
|
||||
if strings.Contains(lcUA, keyword) {
|
||||
c.String(http.StatusForbidden, "Access denied")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
l := subscribe.NewSubscribeLogic(c, svcCtx)
|
||||
resp, err := l.V2(&req)
|
||||
resp, err := l.Handler(&req)
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "Internal Server")
|
||||
return
|
||||
}
|
||||
c.Header("subscription-userinfo", resp.Header)
|
||||
@@ -87,7 +76,5 @@ func RegisterSubscribeHandlers(router *gin.Engine, serverCtx *svc.ServiceContext
|
||||
if path == "" {
|
||||
path = "/api/subscribe"
|
||||
}
|
||||
router.GET(path, V2SubscribeHandler(serverCtx))
|
||||
|
||||
router.GET(path+"/v2", V2SubscribeHandler(serverCtx))
|
||||
router.GET(path, SubscribeHandler(serverCtx))
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/server/adapter"
|
||||
"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"
|
||||
@@ -28,7 +29,11 @@ func NewPreviewSubscribeTemplateLogic(ctx context.Context, svcCtx *svc.ServiceCo
|
||||
}
|
||||
|
||||
func (l *PreviewSubscribeTemplateLogic) PreviewSubscribeTemplate(req *types.PreviewSubscribeTemplateRequest) (resp *types.PreviewSubscribeTemplateResponse, err error) {
|
||||
servers, err := l.svcCtx.ServerModel.FindAllServer(l.ctx)
|
||||
_, servers, err := l.svcCtx.NodeModel.FilterNodeList(l.ctx, &node.FilterNodeParams{
|
||||
Page: 1,
|
||||
Size: 1000,
|
||||
Preload: true,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorf("[PreviewSubscribeTemplateLogic] FindAllServer error: %v", err.Error())
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "FindAllServer error: %v", err.Error())
|
||||
|
||||
@@ -6,12 +6,15 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/server/pkg/xerr"
|
||||
|
||||
"github.com/perfect-panel/server/internal/model/log"
|
||||
"github.com/perfect-panel/server/internal/model/node"
|
||||
"github.com/perfect-panel/server/internal/model/traffic"
|
||||
"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 QueryServerTotalDataLogic struct {
|
||||
@@ -35,127 +38,194 @@ func (l *QueryServerTotalDataLogic) QueryServerTotalData() (resp *types.ServerTo
|
||||
return l.mockRevenueStatistics(), nil
|
||||
}
|
||||
|
||||
resp = &types.ServerTotalDataResponse{
|
||||
ServerTrafficRankingToday: make([]types.ServerTrafficData, 0),
|
||||
ServerTrafficRankingYesterday: make([]types.ServerTrafficData, 0),
|
||||
UserTrafficRankingToday: make([]types.UserTrafficData, 0),
|
||||
UserTrafficRankingYesterday: make([]types.UserTrafficData, 0),
|
||||
now := time.Now()
|
||||
|
||||
todayStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
todayEnd := todayStart.Add(24 * time.Hour).Add(-time.Second)
|
||||
query := l.svcCtx.DB.WithContext(l.ctx)
|
||||
var todayTop10User []log.UserTraffic
|
||||
|
||||
err = query.Model(&traffic.TrafficLog{}).
|
||||
Select("user_id, subscribe_id, SUM(download + upload) AS total, SUM(download) AS download, SUM(upload) AS upload").
|
||||
Where("timestamp BETWEEN ? AND ?", todayStart, todayEnd).
|
||||
Group("user_id, subscribe_id").
|
||||
Order("total DESC").
|
||||
Limit(10).
|
||||
Scan(&todayTop10User).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Errorf("[Traffic Stat Queue] Query user traffic failed: %v", err.Error())
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), " Query user traffic failed: %v", err.Error())
|
||||
}
|
||||
var userTodayTrafficRanking []types.UserTrafficData
|
||||
for _, item := range todayTop10User {
|
||||
userTodayTrafficRanking = append(userTodayTrafficRanking, types.UserTrafficData{
|
||||
SID: item.SubscribeId,
|
||||
Upload: item.Upload,
|
||||
Download: item.Download,
|
||||
})
|
||||
}
|
||||
|
||||
// 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))
|
||||
// query yesterday user traffic rank log
|
||||
yesterday := todayStart.Add(-24 * time.Hour).Format(time.DateOnly)
|
||||
|
||||
// 获取所有节点在线用户
|
||||
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()))
|
||||
var yesterdayLog log.SystemLog
|
||||
err = query.Model(&log.SystemLog{}).Where("`date` = ? AND `type` = ?", yesterday, log.TypeUserTrafficRank).First(&yesterdayLog).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
l.Errorw("[QueryServerTotalDataLogic] Query yesterday user traffic rank log error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Query yesterday user traffic rank log error: %v", err)
|
||||
}
|
||||
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()))
|
||||
var yesterdayUserRankData []types.UserTrafficData
|
||||
if yesterdayLog.Id > 0 {
|
||||
var rank log.UserTrafficRank
|
||||
err = rank.Unmarshal([]byte(yesterdayLog.Content))
|
||||
if err != nil {
|
||||
l.Errorw("[QueryServerTotalDataLogic] Unmarshal yesterday user traffic rank log error", logger.Field("error", err.Error()))
|
||||
}
|
||||
for _, v := range rank.Rank {
|
||||
yesterdayUserRankData = append(yesterdayUserRankData, types.UserTrafficData{
|
||||
SID: v.SubscribeId,
|
||||
Upload: v.Upload,
|
||||
Download: v.Download,
|
||||
})
|
||||
}
|
||||
}
|
||||
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()))
|
||||
|
||||
// query server traffic rank today
|
||||
var todayTop10Server []log.ServerTraffic
|
||||
err = query.Model(&traffic.TrafficLog{}).Select("server_id, SUM(download + upload) AS total, SUM(download) AS download, SUM(upload) AS upload").
|
||||
Where("timestamp BETWEEN ? AND ?", todayStart, todayEnd).
|
||||
Group("server_id").
|
||||
Order("total DESC").
|
||||
Limit(10).
|
||||
Scan(&todayTop10Server).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
logger.Errorf("[Traffic Stat Queue] Query server traffic failed: %v", err.Error())
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), " Query server traffic failed: %v", 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()))
|
||||
|
||||
var todayServerRanking []types.ServerTrafficData
|
||||
for _, item := range todayTop10Server {
|
||||
info, err := l.svcCtx.NodeModel.FindOneServer(l.ctx, item.ServerId)
|
||||
if err != nil {
|
||||
l.Errorw("[QueryServerTotalDataLogic] FindOneServer error", logger.Field("error", err.Error()), logger.Field("server_id", item.ServerId))
|
||||
continue
|
||||
}
|
||||
todayServerRanking = append(todayServerRanking, types.ServerTrafficData{
|
||||
ServerId: item.ServerId,
|
||||
Name: info.Name,
|
||||
Upload: item.Upload,
|
||||
Download: item.Download,
|
||||
})
|
||||
}
|
||||
if len(nodeTrafficRankingToday) > 0 {
|
||||
var serverTrafficData []types.ServerTrafficData
|
||||
for _, rank := range nodeTrafficRankingToday {
|
||||
serverInfo, err := l.svcCtx.ServerModel.FindOne(l.ctx, rank.ID)
|
||||
|
||||
// query server traffic rank yesterday
|
||||
var yesterdayTop10Server []types.ServerTrafficData
|
||||
var yesterdayServerTrafficLog log.SystemLog
|
||||
err = query.Model(&log.SystemLog{}).Where("`date` = ? AND `type` = ?", yesterday, log.TypeServerTrafficRank).First(&yesterdayServerTrafficLog).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
l.Errorw("[QueryServerTotalDataLogic] Query yesterday server traffic rank log error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Query yesterday server traffic rank log error: %v", err)
|
||||
}
|
||||
if yesterdayServerTrafficLog.Id > 0 {
|
||||
var rank log.ServerTrafficRank
|
||||
err = rank.Unmarshal([]byte(yesterdayServerTrafficLog.Content))
|
||||
if err != nil {
|
||||
l.Errorw("[QueryServerTotalDataLogic] Unmarshal yesterday server traffic rank log error", logger.Field("error", err.Error()))
|
||||
}
|
||||
|
||||
for _, v := range rank.Rank {
|
||||
info, err := l.svcCtx.NodeModel.FindOneServer(l.ctx, v.ServerId)
|
||||
if err != nil {
|
||||
l.Errorw("[QueryServerTotalDataLogic] FindOne error", logger.Field("error", err))
|
||||
l.Errorw("[QueryServerTotalDataLogic] FindOneServer error", logger.Field("error", err.Error()), logger.Field("server_id", v.ServerId))
|
||||
continue
|
||||
}
|
||||
serverTrafficData = append(serverTrafficData, types.ServerTrafficData{
|
||||
ServerId: rank.ID,
|
||||
Name: serverInfo.Name,
|
||||
Upload: rank.Upload,
|
||||
Download: rank.Download,
|
||||
yesterdayTop10Server = append(yesterdayTop10Server, types.ServerTrafficData{
|
||||
ServerId: v.ServerId,
|
||||
Name: info.Name,
|
||||
Upload: v.Upload,
|
||||
Download: v.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)
|
||||
// query online user count
|
||||
onlineUsers, err := l.svcCtx.NodeModel.OnlineUserSubscribeGlobal(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
|
||||
l.Errorw("[QueryServerTotalDataLogic] OnlineUserSubscribeGlobal error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "OnlineUserSubscribeGlobal error: %v", err)
|
||||
}
|
||||
|
||||
// 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())
|
||||
// query online/offline server count
|
||||
var onlineServers, offlineServers int64
|
||||
err = query.Model(&node.Server{}).Where("`last_reported_at` > ?", now.Add(-5*time.Minute)).Count(&onlineServers).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
l.Errorw("[QueryServerTotalDataLogic] Count online servers error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Count online servers error: %v", err)
|
||||
}
|
||||
|
||||
err = query.Model(&node.Server{}).Where("`last_reported_at` <= ? OR `last_reported_at` IS NULL", now.Add(-5*time.Minute)).Count(&offlineServers).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
l.Errorw("[QueryServerTotalDataLogic] Count offline servers error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Count offline servers error: %v", err)
|
||||
}
|
||||
// TodayUpload, TodayDownload, MonthlyUpload, MonthlyDownload
|
||||
var todayUpload, todayDownload, monthlyUpload, monthlyDownload int64
|
||||
|
||||
type trafficSum struct {
|
||||
Upload int64
|
||||
Download int64
|
||||
}
|
||||
var todayTraffic trafficSum
|
||||
// Today
|
||||
err = query.Model(&traffic.TrafficLog{}).Select("SUM(upload) AS upload, SUM(download) AS download").
|
||||
Where("timestamp BETWEEN ? AND ?", todayStart, todayEnd).
|
||||
Scan(&todayTraffic).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
l.Errorw("[QueryServerTotalDataLogic] Sum today traffic error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Sum today traffic error: %v", err)
|
||||
}
|
||||
todayUpload = todayTraffic.Upload
|
||||
todayDownload = todayTraffic.Download
|
||||
|
||||
// Monthly
|
||||
monthlyUpload += todayUpload
|
||||
monthlyDownload += todayDownload
|
||||
|
||||
for i := now.Day() - 1; i >= 1; i-- {
|
||||
var logInfo log.SystemLog
|
||||
date := time.Date(now.Year(), now.Month(), i, 0, 0, 0, 0, now.Location()).Format(time.DateOnly)
|
||||
err = query.Model(&log.SystemLog{}).Where("`date` = ? AND `type` = ?", date, log.TypeTrafficStat).First(&logInfo).Error
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
l.Errorw("[QueryServerTotalDataLogic] Query daily traffic stat log error", logger.Field("error", err.Error()), logger.Field("date", date))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "Query daily traffic stat log error: %v", err)
|
||||
}
|
||||
if logInfo.Id > 0 {
|
||||
var stat log.TrafficStat
|
||||
err = stat.Unmarshal([]byte(logInfo.Content))
|
||||
if err != nil {
|
||||
l.Errorw("[QueryServerTotalDataLogic] Unmarshal daily traffic stat log error", logger.Field("error", err.Error()), logger.Field("date", date))
|
||||
continue
|
||||
}
|
||||
monthlyUpload += stat.Upload
|
||||
monthlyDownload += stat.Download
|
||||
}
|
||||
}
|
||||
|
||||
resp = &types.ServerTotalDataResponse{
|
||||
OnlineUsers: onlineUsers,
|
||||
OnlineServers: onlineServers,
|
||||
OfflineServers: offlineServers,
|
||||
TodayUpload: todayUpload,
|
||||
TodayDownload: todayDownload,
|
||||
MonthlyUpload: monthlyUpload,
|
||||
MonthlyDownload: monthlyDownload,
|
||||
UpdatedAt: now.Unix(),
|
||||
ServerTrafficRankingToday: todayServerRanking,
|
||||
ServerTrafficRankingYesterday: yesterdayTop10Server,
|
||||
UserTrafficRankingToday: userTodayTrafficRanking,
|
||||
UserTrafficRankingYesterday: yesterdayUserRankData,
|
||||
}
|
||||
resp.MonthlyUpload = nodeTraffic.Upload
|
||||
resp.MonthlyDownload = nodeTraffic.Download
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
@@ -215,7 +285,7 @@ func (l *QueryServerTotalDataLogic) mockRevenueStatistics() *types.ServerTotalDa
|
||||
//}
|
||||
//
|
||||
return &types.ServerTotalDataResponse{
|
||||
OnlineUserIPs: 1688,
|
||||
OnlineUsers: 1688,
|
||||
OnlineServers: 8,
|
||||
OfflineServers: 2,
|
||||
TodayUpload: 8888888888, // ~8.3GB
|
||||
|
||||
@@ -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,
|
||||
OrderNo: content.OrderNo,
|
||||
Balance: content.Balance,
|
||||
Timestamp: content.Timestamp,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.FilterBalanceLogResponse{
|
||||
Total: total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@@ -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,
|
||||
Timestamp: content.Timestamp,
|
||||
})
|
||||
}
|
||||
return &types.FilterCommissionLogResponse{
|
||||
Total: total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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,
|
||||
Timestamp: content.Timestamp,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.FilterGiftLogResponse{
|
||||
Total: total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@@ -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,
|
||||
Timestamp: datum.CreatedAt.UnixMilli(),
|
||||
})
|
||||
}
|
||||
|
||||
return &types.FilterLoginLogResponse{
|
||||
Total: total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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,
|
||||
Timestamp: item.Timestamp,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.FilterRegisterLogResponse{
|
||||
List: list,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
@@ -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.TypeResetSubscribe.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,
|
||||
Timestamp: content.Timestamp,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.FilterResetSubscribeLogResponse{
|
||||
List: list,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/server/internal/model/log"
|
||||
"github.com/perfect-panel/server/internal/model/traffic"
|
||||
"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 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")
|
||||
var list []types.ServerTrafficLog
|
||||
var total int64
|
||||
|
||||
if req.Date == today || req.Date == "" {
|
||||
now := time.Now()
|
||||
start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
|
||||
end := start.Add(24 * time.Hour).Add(-time.Nanosecond)
|
||||
|
||||
var serverTraffic []log.ServerTraffic
|
||||
err = l.svcCtx.DB.WithContext(l.ctx).
|
||||
Model(&traffic.TrafficLog{}).
|
||||
Select("server_id, SUM(download + upload) AS total, SUM(download) AS download, SUM(upload) AS upload").
|
||||
Where("timestamp BETWEEN ? AND ?", start, end).
|
||||
Group("server_id").
|
||||
Order("SUM(download + upload) DESC").
|
||||
Scan(&serverTraffic).Error
|
||||
if err != nil {
|
||||
l.Errorw("[FilterServerTrafficLog] Query Database Error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "today traffic query error: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, v := range serverTraffic {
|
||||
list = append(list, types.ServerTrafficLog{
|
||||
ServerId: v.ServerId,
|
||||
Upload: v.Upload,
|
||||
Download: v.Download,
|
||||
Total: v.Total,
|
||||
Date: today,
|
||||
Details: true,
|
||||
})
|
||||
}
|
||||
|
||||
todayTotal := len(list)
|
||||
|
||||
startIdx := (req.Page - 1) * req.Size
|
||||
endIdx := startIdx + req.Size
|
||||
|
||||
if startIdx < todayTotal {
|
||||
if endIdx > todayTotal {
|
||||
endIdx = todayTotal
|
||||
}
|
||||
pageData := list[startIdx:endIdx]
|
||||
return &types.FilterServerTrafficLogResponse{
|
||||
List: pageData,
|
||||
Total: int64(todayTotal),
|
||||
}, nil
|
||||
}
|
||||
|
||||
need := endIdx - todayTotal
|
||||
historyPage := (need + req.Size - 1) / req.Size // 算出需要的历史页数
|
||||
historyData, historyTotal, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||
Page: historyPage,
|
||||
Size: need,
|
||||
Type: log.TypeServerTraffic.Uint8(),
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[FilterServerTrafficLog] Query History Error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "history query error: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, item := range historyData {
|
||||
var content log.ServerTraffic
|
||||
if err = content.Unmarshal([]byte(item.Content)); err != nil {
|
||||
l.Errorw("[FilterServerTrafficLog] Unmarshal Error", logger.Field("error", err.Error()), logger.Field("content", item.Content))
|
||||
continue
|
||||
}
|
||||
|
||||
hasDetails := true
|
||||
if l.svcCtx.Config.Log.AutoClear {
|
||||
last := now.AddDate(0, 0, int(-l.svcCtx.Config.Log.ClearDays))
|
||||
dataTime, err := time.Parse(time.DateOnly, item.Date)
|
||||
if err != nil {
|
||||
l.Errorw("[FilterServerTrafficLog] Parse Date Error", logger.Field("error", err.Error()), logger.Field("date", item.Date))
|
||||
} else {
|
||||
if dataTime.Before(last) {
|
||||
hasDetails = false
|
||||
} else {
|
||||
hasDetails = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
list = append(list, types.ServerTrafficLog{
|
||||
ServerId: item.ObjectID,
|
||||
Upload: content.Upload,
|
||||
Download: content.Download,
|
||||
Total: content.Total,
|
||||
Date: item.Date,
|
||||
Details: hasDetails,
|
||||
})
|
||||
}
|
||||
|
||||
// 返回最终分页数据
|
||||
if endIdx > len(list) {
|
||||
endIdx = len(list)
|
||||
}
|
||||
pageData := list[startIdx:endIdx]
|
||||
|
||||
return &types.FilterServerTrafficLogResponse{
|
||||
List: pageData,
|
||||
Total: int64(todayTotal) + historyTotal,
|
||||
}, nil
|
||||
}
|
||||
|
||||
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
Type: log.TypeServerTraffic.Uint8(),
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[FilterServerTrafficLog] Query Database Error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "history query error: %s", err.Error())
|
||||
}
|
||||
|
||||
for _, item := range data {
|
||||
var content log.ServerTraffic
|
||||
if err = content.Unmarshal([]byte(item.Content)); err != nil {
|
||||
l.Errorw("[FilterServerTrafficLog] Unmarshal Error", logger.Field("error", err.Error()), logger.Field("content", item.Content))
|
||||
continue
|
||||
}
|
||||
list = append(list, types.ServerTrafficLog{
|
||||
ServerId: item.ObjectID,
|
||||
Upload: content.Upload,
|
||||
Download: content.Download,
|
||||
Total: content.Total,
|
||||
Date: item.Date,
|
||||
Details: false,
|
||||
})
|
||||
}
|
||||
|
||||
return &types.FilterServerTrafficLogResponse{
|
||||
List: list,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"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
|
||||
}
|
||||
|
||||
// NewFilterSubscribeLogLogic 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) {
|
||||
params := &log.FilterParams{
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
Type: log.TypeSubscribe.Uint8(),
|
||||
Data: req.Date,
|
||||
ObjectID: req.UserId,
|
||||
}
|
||||
|
||||
if req.UserSubscribeId != 0 {
|
||||
params.Search = `"user_subscribe_id":` + strconv.FormatInt(req.UserSubscribeId, 10)
|
||||
}
|
||||
|
||||
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, params)
|
||||
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,
|
||||
Timestamp: datum.CreatedAt.UnixMilli(),
|
||||
})
|
||||
}
|
||||
|
||||
return &types.FilterSubscribeLogResponse{
|
||||
Total: total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/server/internal/model/traffic"
|
||||
"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 FilterTrafficLogDetailsLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// NewFilterTrafficLogDetailsLogic Filter traffic log details
|
||||
func NewFilterTrafficLogDetailsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FilterTrafficLogDetailsLogic {
|
||||
return &FilterTrafficLogDetailsLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *FilterTrafficLogDetailsLogic) FilterTrafficLogDetails(req *types.FilterTrafficLogDetailsRequest) (resp *types.FilterTrafficLogDetailsResponse, err error) {
|
||||
var start, end time.Time
|
||||
if req.Date != "" {
|
||||
day, err := time.ParseInLocation("2006-01-02", req.Date, time.Local)
|
||||
if err != nil {
|
||||
l.Errorw("[FilterTrafficLogDetails] Date Parse Error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidParams), " date parse error: %s", err.Error())
|
||||
}
|
||||
start = day
|
||||
end = day.Add(24*time.Hour - time.Nanosecond)
|
||||
} else {
|
||||
// query today
|
||||
now := time.Now()
|
||||
start = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
end = start.Add(24*time.Hour - time.Nanosecond)
|
||||
}
|
||||
var data []*traffic.TrafficLog
|
||||
tx := l.svcCtx.DB.WithContext(l.ctx).Model(&traffic.TrafficLog{})
|
||||
if req.ServerId != 0 {
|
||||
tx = tx.Where("server_id = ?", req.ServerId)
|
||||
}
|
||||
if !start.IsZero() && !end.IsZero() {
|
||||
tx = tx.Where("timestamp BETWEEN ? AND ?", start, end)
|
||||
}
|
||||
if req.UserId != 0 {
|
||||
tx = tx.Where("user_id = ?", req.UserId)
|
||||
}
|
||||
if req.SubscribeId != 0 {
|
||||
tx = tx.Where("subscribe_id = ?", req.SubscribeId)
|
||||
}
|
||||
var total int64
|
||||
err = tx.Count(&total).Limit(req.Size).Offset((req.Page - 1) * req.Size).Find(&data).Error
|
||||
if err != nil {
|
||||
l.Errorw("[FilterTrafficLogDetails] Query Database Error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), " database query error: %s", err.Error())
|
||||
}
|
||||
|
||||
var logs []types.TrafficLogDetails
|
||||
for _, v := range data {
|
||||
logs = append(logs, types.TrafficLogDetails{
|
||||
Id: v.Id,
|
||||
UserId: v.UserId,
|
||||
ServerId: v.ServerId,
|
||||
SubscribeId: v.SubscribeId,
|
||||
Download: v.Download,
|
||||
Upload: v.Upload,
|
||||
Timestamp: v.Timestamp.UnixMilli(),
|
||||
})
|
||||
}
|
||||
|
||||
return &types.FilterTrafficLogDetailsResponse{
|
||||
List: logs,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/server/internal/model/log"
|
||||
"github.com/perfect-panel/server/internal/model/traffic"
|
||||
"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 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) {
|
||||
if req.Size <= 0 {
|
||||
req.Size = 10
|
||||
}
|
||||
if req.Page <= 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
today := time.Now().Format("2006-01-02")
|
||||
var list []types.UserSubscribeTrafficLog
|
||||
var total int64
|
||||
|
||||
if req.Date == today || req.Date == "" {
|
||||
now := time.Now()
|
||||
start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
|
||||
end := start.Add(24 * time.Hour).Add(-time.Nanosecond)
|
||||
|
||||
var userTraffic []types.UserSubscribeTrafficLog
|
||||
err = l.svcCtx.DB.WithContext(l.ctx).
|
||||
Model(&traffic.TrafficLog{}).
|
||||
Select("user_id, subscribe_id, SUM(download + upload) AS total, SUM(download) AS download, SUM(upload) AS upload").
|
||||
Where("timestamp BETWEEN ? AND ?", start, end).
|
||||
Group("user_id, subscribe_id").
|
||||
Order("SUM(download + upload) DESC").
|
||||
Scan(&userTraffic).Error
|
||||
if err != nil {
|
||||
l.Errorw("[FilterUserSubscribeTrafficLog] Query Database Error", logger.Field("error", err.Error()))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, v := range userTraffic {
|
||||
list = append(list, types.UserSubscribeTrafficLog{
|
||||
UserId: v.UserId,
|
||||
SubscribeId: v.SubscribeId,
|
||||
Upload: v.Upload,
|
||||
Download: v.Download,
|
||||
Total: v.Total,
|
||||
Date: today,
|
||||
Details: true,
|
||||
})
|
||||
}
|
||||
todayTotal := len(list)
|
||||
|
||||
startIdx := (req.Page - 1) * req.Size
|
||||
endIdx := startIdx + req.Size
|
||||
if startIdx < todayTotal {
|
||||
if endIdx > todayTotal {
|
||||
endIdx = todayTotal
|
||||
}
|
||||
pageData := list[startIdx:endIdx]
|
||||
return &types.FilterSubscribeTrafficResponse{
|
||||
List: pageData,
|
||||
Total: int64(todayTotal),
|
||||
}, nil
|
||||
}
|
||||
|
||||
need := endIdx - todayTotal
|
||||
historyPage := (need + req.Size - 1) / req.Size // 算出需要的历史页数
|
||||
historyData, historyTotal, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||
Page: historyPage,
|
||||
Size: need,
|
||||
Type: log.TypeSubscribeTraffic.Uint8(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
l.Errorw("[FilterUserSubscribeTrafficLog] Query Database Error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[FilterUserSubscribeTrafficLog] Query Database Error")
|
||||
}
|
||||
|
||||
for _, datum := range historyData {
|
||||
var item log.UserTraffic
|
||||
err = item.Unmarshal([]byte(datum.Content))
|
||||
if err != nil {
|
||||
l.Errorw("[FilterUserSubscribeTrafficLog] Unmarshal Content Error", logger.Field("error", err.Error()))
|
||||
continue
|
||||
}
|
||||
list = append(list, types.UserSubscribeTrafficLog{
|
||||
UserId: item.UserId,
|
||||
SubscribeId: item.SubscribeId,
|
||||
Upload: item.Upload,
|
||||
Download: item.Download,
|
||||
Total: item.Total,
|
||||
Date: datum.Date,
|
||||
Details: false,
|
||||
})
|
||||
}
|
||||
// 返回最终分页数据
|
||||
if endIdx > len(list) {
|
||||
endIdx = len(list)
|
||||
}
|
||||
pageData := list[startIdx:endIdx]
|
||||
|
||||
return &types.FilterSubscribeTrafficResponse{
|
||||
List: pageData,
|
||||
Total: int64(todayTotal) + historyTotal,
|
||||
}, nil
|
||||
}
|
||||
var data []*log.SystemLog
|
||||
data, total, err = l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
Type: log.TypeSubscribeTraffic.Uint8(),
|
||||
Data: req.Date,
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("[FilterUserSubscribeTrafficLog] Query Database Error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[FilterUserSubscribeTrafficLog] Query Database Error")
|
||||
}
|
||||
for _, datum := range data {
|
||||
var item log.UserTraffic
|
||||
err = item.Unmarshal([]byte(datum.Content))
|
||||
if err != nil {
|
||||
l.Errorw("[FilterUserSubscribeTrafficLog] Unmarshal Content Error", logger.Field("error", err.Error()))
|
||||
continue
|
||||
}
|
||||
list = append(list, types.UserSubscribeTrafficLog{
|
||||
UserId: item.UserId,
|
||||
SubscribeId: item.SubscribeId,
|
||||
Upload: item.Upload,
|
||||
Download: item.Download,
|
||||
Total: item.Total,
|
||||
Date: datum.Date,
|
||||
Details: false,
|
||||
})
|
||||
}
|
||||
return &types.FilterSubscribeTrafficResponse{
|
||||
List: list,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
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"
|
||||
"github.com/perfect-panel/server/pkg/tool"
|
||||
)
|
||||
|
||||
type GetLogSettingLogic struct {
|
||||
logger.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// Get log setting
|
||||
func NewGetLogSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLogSettingLogic {
|
||||
return &GetLogSettingLogic{
|
||||
Logger: logger.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetLogSettingLogic) GetLogSetting() (resp *types.LogSetting, err error) {
|
||||
configs, err := l.svcCtx.SystemModel.GetLogConfig(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("[GetLogSetting] Database query error", logger.Field("error", err.Error()))
|
||||
return nil, err
|
||||
}
|
||||
resp = &types.LogSetting{}
|
||||
// reflect to response
|
||||
tool.SystemConfigSliceReflectToStruct(configs, resp)
|
||||
return
|
||||
}
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"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"
|
||||
)
|
||||
@@ -28,20 +27,39 @@ func NewGetMessageLogListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||
}
|
||||
|
||||
func (l *GetMessageLogListLogic) GetMessageLogList(req *types.GetMessageLogListRequest) (resp *types.GetMessageLogListResponse, err error) {
|
||||
total, data, err := l.svcCtx.LogModel.FindMessageLogList(l.ctx, req.Page, req.Size, log.MessageLogFilterParams{
|
||||
Type: req.Type,
|
||||
Platform: req.Platform,
|
||||
To: req.To,
|
||||
Subject: req.Subject,
|
||||
Content: req.Content,
|
||||
Status: req.Status,
|
||||
|
||||
data, total, err := l.svcCtx.LogModel.FilterSystemLog(l.ctx, &log.FilterParams{
|
||||
Page: req.Page,
|
||||
Size: req.Size,
|
||||
Type: req.Type,
|
||||
Search: req.Search,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
l.Errorw("[GetMessageLogList] Database Error", logger.Field("error", err.Error()))
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "[GetMessageLogList] Database Error: %s", err.Error())
|
||||
l.Errorf("[GetMessageLogList] 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
|
||||
tool.DeepCopy(&list, data)
|
||||
|
||||
for _, datum := range data {
|
||||
var content log.Message
|
||||
err = content.Unmarshal([]byte(datum.Content))
|
||||
if err != nil {
|
||||
l.Errorf("[GetMessageLogList] 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.GetMessageLogListResponse{
|
||||
Total: total,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user