Browse Source

Api for backup Telegram (#468)

Mahdi Nemati 1 year ago
parent
commit
334b28cddc
2 changed files with 18 additions and 2 deletions
  1. 11 2
      web/controller/api.go
  2. 7 0
      web/service/tgbot.go

+ 11 - 2
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)
+}

+ 7 - 0
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