From 2afa5f02b7f4f6b4d61babbb85e5e2e40eef0bbf Mon Sep 17 00:00:00 2001 From: Alexander Kraev Date: Tue, 22 Jul 2025 02:54:53 +0300 Subject: [PATCH] no message --- sub/subJsonService.go | 2 +- sub/subService.go | 2 +- web/controller/api.go | 8 -------- web/controller/blocked_domain.go | 17 ++++++++++------- web/controller/inbound.go | 2 +- web/controller/index.go | 1 - web/controller/setting.go | 2 +- web/controller/xray_setting.go | 3 +-- web/job/check_cpu_usage.go | 3 +-- web/service/blocked_domain.go | 1 - web/service/xray.go | 6 ++++-- web/web.go | 7 +++++-- 12 files changed, 25 insertions(+), 29 deletions(-) diff --git a/sub/subJsonService.go b/sub/subJsonService.go index 008e1658..0eb88bb4 100644 --- a/sub/subJsonService.go +++ b/sub/subJsonService.go @@ -10,8 +10,8 @@ import ( "x-ui/logger" "x-ui/util/json_util" "x-ui/util/random" - "x-ui/web/service" "x-ui/xray" + "x-ui/web/service" ) //go:embed default.json diff --git a/sub/subService.go b/sub/subService.go index 9f26c0e0..45a25d83 100644 --- a/sub/subService.go +++ b/sub/subService.go @@ -12,8 +12,8 @@ import ( "x-ui/logger" "x-ui/util/common" "x-ui/util/random" - "x-ui/web/service" "x-ui/xray" + "x-ui/web/service" "github.com/goccy/go-json" ) diff --git a/web/controller/api.go b/web/controller/api.go index 9944e2a3..ae25bdb4 100644 --- a/web/controller/api.go +++ b/web/controller/api.go @@ -1,15 +1,12 @@ package controller import ( - "x-ui/web/service" - "github.com/gin-gonic/gin" ) type APIController struct { BaseController inboundController *InboundController - Tgbot service.Tgbot } func NewAPIController(g *gin.RouterGroup) *APIController { @@ -29,7 +26,6 @@ func (a *APIController) initRouter(g *gin.RouterGroup) { Path string Handler gin.HandlerFunc }{ - {"GET", "/createbackup", a.createBackup}, {"GET", "/list", a.inboundController.getInbounds}, {"GET", "/get/:id", a.inboundController.getInbound}, {"GET", "/getClientTraffics/:email", a.inboundController.getClientTraffics}, @@ -53,7 +49,3 @@ func (a *APIController) initRouter(g *gin.RouterGroup) { g.Handle(route.Method, route.Path, route.Handler) } } - -func (a *APIController) createBackup(c *gin.Context) { - a.Tgbot.SendBackupToAdmins() -} diff --git a/web/controller/blocked_domain.go b/web/controller/blocked_domain.go index f4e3c986..9600dfd6 100644 --- a/web/controller/blocked_domain.go +++ b/web/controller/blocked_domain.go @@ -6,15 +6,14 @@ import ( "github.com/gin-gonic/gin" "x-ui/database/model" - "x-ui/web/service" + "x-ui/database" ) type BlockedDomainController struct { - service *service.BlockedDomainService } func NewBlockedDomainController(g *gin.RouterGroup) *BlockedDomainController { - ctrl := &BlockedDomainController{service: &service.BlockedDomainService{}} + ctrl := &BlockedDomainController{} r := g.Group("/blocked-domains") r.GET("/", ctrl.List) r.POST("/", ctrl.Create) @@ -24,7 +23,8 @@ func NewBlockedDomainController(g *gin.RouterGroup) *BlockedDomainController { } func (ctrl *BlockedDomainController) List(c *gin.Context) { - domains, err := ctrl.service.GetAll() + var domains []model.BlockedDomain + err := database.GetDB().Find(&domains).Error if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"success": false, "msg": err.Error()}) return @@ -38,7 +38,8 @@ func (ctrl *BlockedDomainController) Create(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"success": false, "msg": err.Error()}) return } - if err := ctrl.service.Create(&domain); err != nil { + err := database.GetDB().Create(&domain).Error + if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"success": false, "msg": err.Error()}) return } @@ -57,7 +58,8 @@ func (ctrl *BlockedDomainController) Update(c *gin.Context) { return } domain.Id = id - if err := ctrl.service.Update(&domain); err != nil { + err = database.GetDB().Save(&domain).Error + if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"success": false, "msg": err.Error()}) return } @@ -70,7 +72,8 @@ func (ctrl *BlockedDomainController) Delete(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"success": false, "msg": "invalid id"}) return } - if err := ctrl.service.Delete(id); err != nil { + err = database.GetDB().Delete(&model.BlockedDomain{}, id).Error + if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"success": false, "msg": err.Error()}) return } diff --git a/web/controller/inbound.go b/web/controller/inbound.go index 592a4bd0..0116dd80 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -6,8 +6,8 @@ import ( "strconv" "x-ui/database/model" - "x-ui/web/service" "x-ui/web/session" + "x-ui/web/service" "github.com/gin-gonic/gin" ) diff --git a/web/controller/index.go b/web/controller/index.go index c19d1b6e..85fdac39 100644 --- a/web/controller/index.go +++ b/web/controller/index.go @@ -21,7 +21,6 @@ type LoginForm struct { type IndexController struct { BaseController - settingService service.SettingService userService service.UserService tgbot service.Tgbot diff --git a/web/controller/setting.go b/web/controller/setting.go index ddd9f55a..8c087c2d 100644 --- a/web/controller/setting.go +++ b/web/controller/setting.go @@ -6,8 +6,8 @@ import ( "x-ui/util/crypto" "x-ui/web/entity" - "x-ui/web/service" "x-ui/web/session" + "x-ui/web/service" "github.com/gin-gonic/gin" ) diff --git a/web/controller/xray_setting.go b/web/controller/xray_setting.go index 5b2d1036..a49c8def 100644 --- a/web/controller/xray_setting.go +++ b/web/controller/xray_setting.go @@ -1,9 +1,8 @@ package controller import ( - "x-ui/web/service" - "github.com/gin-gonic/gin" + "x-ui/web/service" ) type XraySettingController struct { diff --git a/web/job/check_cpu_usage.go b/web/job/check_cpu_usage.go index cd9fcc9a..5557afa4 100644 --- a/web/job/check_cpu_usage.go +++ b/web/job/check_cpu_usage.go @@ -4,9 +4,8 @@ import ( "strconv" "time" - "x-ui/web/service" - "github.com/shirou/gopsutil/v4/cpu" + "x-ui/web/service" ) type CheckCpuJob struct { diff --git a/web/service/blocked_domain.go b/web/service/blocked_domain.go index 065061ae..7ed001d6 100644 --- a/web/service/blocked_domain.go +++ b/web/service/blocked_domain.go @@ -3,7 +3,6 @@ package service import ( "x-ui/database" "x-ui/database/model" - "gorm.io/gorm" ) type BlockedDomainService struct{} diff --git a/web/service/xray.go b/web/service/xray.go index 20356eb9..a4614064 100644 --- a/web/service/xray.go +++ b/web/service/xray.go @@ -7,7 +7,8 @@ import ( "x-ui/logger" "x-ui/xray" - "x-ui/web/service" + "x-ui/database" + "x-ui/database/model" "go.uber.org/atomic" ) @@ -74,7 +75,8 @@ func (s *XrayService) GetXrayConfig() (*xray.Config, error) { } // --- Блокировка запрещённых доменов --- - blockedDomains, err := service.BlockedDomainService{}.GetAll() + var blockedDomains []model.BlockedDomain + err = database.GetDB().Find(&blockedDomains).Error if err == nil && len(blockedDomains) > 0 { var domains []string for _, d := range blockedDomains { diff --git a/web/web.go b/web/web.go index 79573525..e6829607 100644 --- a/web/web.go +++ b/web/web.go @@ -100,8 +100,11 @@ type Server struct { func NewServer() *Server { ctx, cancel := context.WithCancel(context.Background()) return &Server{ - ctx: ctx, - cancel: cancel, + ctx: ctx, + cancel: cancel, + xrayService: service.XrayService{}, + settingService: service.SettingService{}, + tgbotService: service.Tgbot{}, } }