From 334b28cddc713fbeb01e1589926e1975de83c64f Mon Sep 17 00:00:00 2001 From: Mahdi Nemati Date: Fri, 19 May 2023 00:31:05 +0330 Subject: [PATCH] Api for backup Telegram (#468) --- web/controller/api.go | 13 +++++++++++-- web/service/tgbot.go | 7 +++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/web/controller/api.go b/web/controller/api.go index 607dd83a9..170733459 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 { @@ -32,7 +37,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) } @@ -95,3 +100,7 @@ func (a *APIController) resetAllClientTraffics(c *gin.Context) { func (a *APIController) delDepletedClients(c *gin.Context) { a.inboundController.delDepletedClients(c) } + +func (a *APIController) createBackup(c *gin.Context) { + a.Tgbot.SendBackUP(c) +} diff --git a/web/service/tgbot.go b/web/service/tgbot.go index 973ee97f9..0b301e297 100644 --- a/web/service/tgbot.go +++ b/web/service/tgbot.go @@ -13,6 +13,7 @@ import ( "x-ui/util/common" "x-ui/xray" + "github.com/gin-gonic/gin" "github.com/mymmrac/telego" th "github.com/mymmrac/telego/telegohandler" tu "github.com/mymmrac/telego/telegoutil" @@ -500,6 +501,12 @@ func (t *Tgbot) SendReport() { } } +func (t *Tgbot) SendBackUP(c *gin.Context) { + for _, adminId := range adminIds { + t.sendBackup(int64(adminId)) + } +} + func (t *Tgbot) getServerUsage() string { var info string //get hostname