Api for backup Telegram (#468)

This commit is contained in:
Mahdi Nemati 2023-05-19 00:31:05 +03:30 committed by GitHub
parent 2fbfc88bc1
commit 334b28cddc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View file

@ -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)
}

View file

@ -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