mirror of
https://github.com/alireza0/x-ui.git
synced 2026-03-18 06:45:49 +00:00
[api] add server endpoint #1590
This commit is contained in:
@@ -9,27 +9,36 @@ import (
|
||||
type APIController struct {
|
||||
BaseController
|
||||
inboundController *InboundController
|
||||
serverController *ServerController
|
||||
Tgbot service.Tgbot
|
||||
}
|
||||
|
||||
func NewAPIController(g *gin.RouterGroup) *APIController {
|
||||
a := &APIController{}
|
||||
func NewAPIController(g *gin.RouterGroup, s *ServerController) *APIController {
|
||||
a := &APIController{
|
||||
serverController: s,
|
||||
}
|
||||
a.initRouter(g)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *APIController) initRouter(g *gin.RouterGroup) {
|
||||
g = g.Group("/xui/API/inbounds")
|
||||
g.Use(a.checkLogin)
|
||||
api := g.Group("/xui/API")
|
||||
api.Use(a.checkLogin)
|
||||
|
||||
a.inboundController = NewInboundController(g)
|
||||
a.inboundApi(api)
|
||||
a.serverApi(api)
|
||||
}
|
||||
|
||||
func (a *APIController) inboundApi(api *gin.RouterGroup) {
|
||||
inboundsApi := api.Group("/inbounds")
|
||||
|
||||
a.inboundController = &InboundController{}
|
||||
|
||||
inboundRoutes := []struct {
|
||||
Method string
|
||||
Path string
|
||||
Handler gin.HandlerFunc
|
||||
}{
|
||||
{"GET", "/createbackup", a.createBackup},
|
||||
{"GET", "/", a.inboundController.getInbounds},
|
||||
{"GET", "/get/:id", a.inboundController.getInbound},
|
||||
{"GET", "/getClientTraffics/:email", a.inboundController.getClientTraffics},
|
||||
@@ -48,7 +57,37 @@ func (a *APIController) initRouter(g *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
for _, route := range inboundRoutes {
|
||||
g.Handle(route.Method, route.Path, route.Handler)
|
||||
inboundsApi.Handle(route.Method, route.Path, route.Handler)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) serverApi(api *gin.RouterGroup) {
|
||||
serverApi := api.Group("/server")
|
||||
|
||||
serverRoutes := []struct {
|
||||
Method string
|
||||
Path string
|
||||
Handler gin.HandlerFunc
|
||||
}{
|
||||
{"GET", "/status", a.serverController.status},
|
||||
{"GET", "/getDb", a.serverController.getDb},
|
||||
{"GET", "/createbackup", a.createBackup},
|
||||
{"GET", "/getConfigJson", a.serverController.getConfigJson},
|
||||
{"GET", "/getXrayVersion", a.serverController.getXrayVersion},
|
||||
{"GET", "/getNewVlessEnc", a.serverController.getNewVlessEnc},
|
||||
{"GET", "/getNewX25519Cert", a.serverController.getNewX25519Cert},
|
||||
{"GET", "/getNewmldsa65", a.serverController.getNewmldsa65},
|
||||
|
||||
{"POST", "/getNewEchCert", a.serverController.getNewEchCert},
|
||||
{"POST", "/importDB", a.serverController.importDB},
|
||||
{"POST", "/stopXrayService", a.serverController.stopXrayService},
|
||||
{"POST", "/restartXrayService", a.serverController.restartXrayService},
|
||||
{"POST", "/installXray/:version", a.serverController.installXray},
|
||||
{"POST", "/logs/:count", a.serverController.getLogs},
|
||||
}
|
||||
|
||||
for _, route := range serverRoutes {
|
||||
serverApi.Handle(route.Method, route.Path, route.Handler)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user