Files
trihuy-russian/web/controller/api.go
T

61 lines
2.0 KiB
Go
Raw Normal View History

2023-02-09 22:48:06 +03:30
package controller
2023-05-19 00:31:05 +03:30
import (
"x-ui/web/service"
"github.com/gin-gonic/gin"
)
2023-02-09 22:48:06 +03:30
2023-04-02 02:30:15 +04:30
type APIController struct {
2023-04-09 23:13:18 +03:30
BaseController
inboundController *InboundController
2023-05-19 00:31:05 +03:30
Tgbot service.Tgbot
2023-02-09 22:48:06 +03:30
}
func NewAPIController(g *gin.RouterGroup) *APIController {
2023-04-09 23:13:18 +03:30
a := &APIController{}
a.initRouter(g)
return a
2023-02-09 22:48:06 +03:30
}
func (a *APIController) initRouter(g *gin.RouterGroup) {
2023-05-14 01:41:18 +04:30
g = g.Group("/panel/api/inbounds")
2023-04-09 23:13:18 +03:30
g.Use(a.checkLogin)
a.inboundController = NewInboundController(g)
2023-04-02 02:30:15 +04:30
2024-03-11 01:01:24 +03:30
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},
2024-07-23 11:28:28 +02:00
{"GET", "/getClientTrafficsById/:id", a.inboundController.getClientTrafficsById},
2024-03-11 01:01:24 +03:30
{"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},
{"POST", "/updateClientTraffic/:email", a.inboundController.updateClientTraffic},
2024-03-11 01:01:24 +03:30
}
for _, route := range inboundRoutes {
g.Handle(route.Method, route.Path, route.Handler)
}
2023-04-25 18:46:09 +03:30
}
2023-05-19 00:31:05 +03:30
func (a *APIController) createBackup(c *gin.Context) {
2023-05-21 03:29:27 +04:30
a.Tgbot.SendBackupToAdmins()
2023-05-19 00:31:05 +03:30
}