api.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. {"POST", "/add", a.inboundController.addInbound},
  30. {"POST", "/del/:id", a.inboundController.delInbound},
  31. {"POST", "/update/:id", a.inboundController.updateInbound},
  32. {"POST", "/clientIps/:email", a.inboundController.getClientIps},
  33. {"POST", "/clearClientIps/:email", a.inboundController.clearClientIps},
  34. {"POST", "/addClient", a.inboundController.addInboundClient},
  35. {"POST", "/:id/delClient/:clientId", a.inboundController.delInboundClient},
  36. {"POST", "/updateClient/:clientId", a.inboundController.updateInboundClient},
  37. {"POST", "/:id/resetClientTraffic/:email", a.inboundController.resetClientTraffic},
  38. {"POST", "/resetAllTraffics", a.inboundController.resetAllTraffics},
  39. {"POST", "/resetAllClientTraffics/:id", a.inboundController.resetAllClientTraffics},
  40. {"POST", "/delDepletedClients/:id", a.inboundController.delDepletedClients},
  41. {"POST", "/onlines", a.inboundController.onlines},
  42. }
  43. for _, route := range inboundRoutes {
  44. g.Handle(route.Method, route.Path, route.Handler)
  45. }
  46. }
  47. func (a *APIController) createBackup(c *gin.Context) {
  48. a.Tgbot.SendBackupToAdmins()
  49. }