3x-ui/web/controller/api.go

59 lines
1.9 KiB
Go
Raw Normal View History

2023-02-09 22:18:06 +03:00
package controller
2023-05-19 00:01:05 +03:00
import (
"x-ui/web/service"
"github.com/gin-gonic/gin"
)
2023-02-09 22:18:06 +03:00
2023-04-02 01:00:15 +03:00
type APIController struct {
BaseController
inboundController *InboundController
2023-05-19 00:01:05 +03:00
Tgbot service.Tgbot
2023-02-09 22:18:06 +03:00
}
func NewAPIController(g *gin.RouterGroup) *APIController {
a := &APIController{}
a.initRouter(g)
return a
2023-02-09 22:18:06 +03:00
}
func (a *APIController) initRouter(g *gin.RouterGroup) {
g = g.Group("/panel/api/inbounds")
g.Use(a.checkLogin)
a.inboundController = NewInboundController(g)
2023-04-02 01:00:15 +03:00
inboundRoutes := []struct {
Method string
Path string
Handler gin.HandlerFunc
}{
{"GET", "/createbackup", a.createBackup},
{"GET", "/list", a.inboundController.getInbounds},
{"GET", "/get/:id", a.inboundController.getInbound},
{"GET", "/getClientTraffics/:email", a.inboundController.getClientTraffics},
{"POST", "/add", a.inboundController.addInbound},
{"POST", "/del/:id", a.inboundController.delInbound},
{"POST", "/update/:id", a.inboundController.updateInbound},
{"POST", "/clientIps/:email", a.inboundController.getClientIps},
{"POST", "/clearClientIps/:email", a.inboundController.clearClientIps},
{"POST", "/addClient", a.inboundController.addInboundClient},
{"POST", "/:id/delClient/:clientId", a.inboundController.delInboundClient},
{"POST", "/updateClient/:clientId", a.inboundController.updateInboundClient},
{"POST", "/:id/resetClientTraffic/:email", a.inboundController.resetClientTraffic},
{"POST", "/resetAllTraffics", a.inboundController.resetAllTraffics},
{"POST", "/resetAllClientTraffics/:id", a.inboundController.resetAllClientTraffics},
{"POST", "/delDepletedClients/:id", a.inboundController.delDepletedClients},
{"POST", "/onlines", a.inboundController.onlines},
}
for _, route := range inboundRoutes {
g.Handle(route.Method, route.Path, route.Handler)
}
}
2023-05-19 00:01:05 +03:00
func (a *APIController) createBackup(c *gin.Context) {
2023-05-21 01:59:27 +03:00
a.Tgbot.SendBackupToAdmins()
2023-05-19 00:01:05 +03:00
}