api.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package controller
  2. import (
  3. "x-ui/web/service"
  4. "github.com/gin-gonic/gin"
  5. )
  6. type APIController struct {
  7. BaseController
  8. inboundController *InboundController
  9. Tgbot service.Tgbot
  10. }
  11. func NewAPIController(g *gin.RouterGroup) *APIController {
  12. a := &APIController{}
  13. a.initRouter(g)
  14. return a
  15. }
  16. func (a *APIController) initRouter(g *gin.RouterGroup) {
  17. g = g.Group("/panel/api/inbounds")
  18. g.Use(a.checkLogin)
  19. a.inboundController = NewInboundController(g)
  20. inboundRoutes := []struct {
  21. Method string
  22. Path string
  23. Handler gin.HandlerFunc
  24. }{
  25. {"GET", "/createbackup", a.createBackup},
  26. {"GET", "/list", a.inboundController.getInbounds},
  27. {"GET", "/get/:id", a.inboundController.getInbound},
  28. {"GET", "/getClientTraffics/:email", a.inboundController.getClientTraffics},
  29. {"GET", "/getClientTrafficsById/:id", a.inboundController.getClientTrafficsById},
  30. {"POST", "/add", a.inboundController.addInbound},
  31. {"POST", "/del/:id", a.inboundController.delInbound},
  32. {"POST", "/update/:id", a.inboundController.updateInbound},
  33. {"POST", "/clientIps/:email", a.inboundController.getClientIps},
  34. {"POST", "/clearClientIps/:email", a.inboundController.clearClientIps},
  35. {"POST", "/addClient", a.inboundController.addInboundClient},
  36. {"POST", "/:id/delClient/:clientId", a.inboundController.delInboundClient},
  37. {"POST", "/updateClient/:clientId", a.inboundController.updateInboundClient},
  38. {"POST", "/:id/resetClientTraffic/:email", a.inboundController.resetClientTraffic},
  39. {"POST", "/resetAllTraffics", a.inboundController.resetAllTraffics},
  40. {"POST", "/resetAllClientTraffics/:id", a.inboundController.resetAllClientTraffics},
  41. {"POST", "/delDepletedClients/:id", a.inboundController.delDepletedClients},
  42. {"POST", "/onlines", a.inboundController.onlines},
  43. }
  44. for _, route := range inboundRoutes {
  45. g.Handle(route.Method, route.Path, route.Handler)
  46. }
  47. }
  48. func (a *APIController) createBackup(c *gin.Context) {
  49. a.Tgbot.SendBackupToAdmins()
  50. }