Skip to content

Commit

Permalink
Api for backup Telegram (#468)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdintm authored May 18, 2023
1 parent 2fbfc88 commit 334b28c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions web/controller/api.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 changes: 7 additions & 0 deletions web/service/tgbot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 334b28c

Please sign in to comment.