From 4b3abe9cdfb7af7215f3c83b3f7dc5d08f53143d Mon Sep 17 00:00:00 2001 From: Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> Date: Sun, 21 May 2023 06:51:54 +0430 Subject: [PATCH] add createBackup api --- web/controller/api.go | 24 +++++++++++++++++++++++- web/service/tgbot.go | 13 ++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/web/controller/api.go b/web/controller/api.go index 2134a792..73a291bf 100644 --- a/web/controller/api.go +++ b/web/controller/api.go @@ -1,10 +1,15 @@ package controller -import "github.com/gin-gonic/gin" +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 { @@ -30,6 +35,7 @@ func (a *APIController) initRouter(g *gin.RouterGroup) { g.POST("/resetAllTraffics", a.resetAllTraffics) g.POST("/resetAllClientTraffics/:id", a.resetAllClientTraffics) g.POST("/delDepletedClients/:id", a.delDepletedClients) + g.GET("/createbackup", a.createBackup) a.inboundController = NewInboundController(g) } @@ -37,39 +43,55 @@ func (a *APIController) initRouter(g *gin.RouterGroup) { func (a *APIController) inbounds(c *gin.Context) { a.inboundController.getInbounds(c) } + func (a *APIController) inbound(c *gin.Context) { a.inboundController.getInbound(c) } + func (a *APIController) getClientTraffics(c *gin.Context) { a.inboundController.getClientTraffics(c) } + func (a *APIController) addInbound(c *gin.Context) { a.inboundController.addInbound(c) } + func (a *APIController) delInbound(c *gin.Context) { a.inboundController.delInbound(c) } + func (a *APIController) updateInbound(c *gin.Context) { a.inboundController.updateInbound(c) } + func (a *APIController) addInboundClient(c *gin.Context) { a.inboundController.addInboundClient(c) } + func (a *APIController) delInboundClient(c *gin.Context) { a.inboundController.delInboundClient(c) } + func (a *APIController) updateInboundClient(c *gin.Context) { a.inboundController.updateInboundClient(c) } + func (a *APIController) resetClientTraffic(c *gin.Context) { a.inboundController.resetClientTraffic(c) } + func (a *APIController) resetAllTraffics(c *gin.Context) { a.inboundController.resetAllTraffics(c) } + func (a *APIController) resetAllClientTraffics(c *gin.Context) { a.inboundController.resetAllClientTraffics(c) } + func (a *APIController) delDepletedClients(c *gin.Context) { a.inboundController.delDepletedClients(c) } + +func (a *APIController) createBackup(c *gin.Context) { + a.Tgbot.SendBackupToAdmins() +} diff --git a/web/service/tgbot.go b/web/service/tgbot.go index 24585c99..b036b296 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -281,9 +281,16 @@ func (t *Tgbot) SendReport() { t.SendMsgToTgbotAdmins(exhausted) backupEnable, err := t.settingService.GetTgBotBackup() if err == nil && backupEnable { - for _, adminId := range adminIds { - t.sendBackup(int64(adminId)) - } + t.SendBackupToAdmins() + } +} + +func (t *Tgbot) SendBackupToAdmins() { + if !t.IsRunning() { + return + } + for _, adminId := range adminIds { + t.sendBackup(int64(adminId)) } }