diff options
| author | Mohammad Movaghari <52345697+mohammadmovaghari@users.noreply.github.com> | 2023-04-12 16:29:17 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-12 16:29:17 +0300 |
| commit | c575425292e2c4c690728174e42a6f34963394c2 (patch) | |
| tree | c9b033457baa55a98cea23a8769645f8f3dbd476 /web/controller/sub.go | |
| parent | 63f71e527ceddc724e0bd2893c4946b01f3a5f6c (diff) | |
| parent | 82b2809fccb6a131b4f84e2ca236f8bea567beae (diff) | |
Merge branch 'MHSanaei:main' into main
Diffstat (limited to 'web/controller/sub.go')
| -rw-r--r-- | web/controller/sub.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/web/controller/sub.go b/web/controller/sub.go new file mode 100644 index 00000000..5695f032 --- /dev/null +++ b/web/controller/sub.go @@ -0,0 +1,42 @@ +package controller + +import ( + "encoding/base64" + "strings" + "x-ui/web/service" + + "github.com/gin-gonic/gin" +) + +type SUBController struct { + BaseController + + subService service.SubService +} + +func NewSUBController(g *gin.RouterGroup) *SUBController { + a := &SUBController{} + a.initRouter(g) + return a +} + +func (a *SUBController) initRouter(g *gin.RouterGroup) { + g = g.Group("/sub") + + g.GET("/:subid", a.subs) +} + +func (a *SUBController) subs(c *gin.Context) { + subId := c.Param("subid") + host := strings.Split(c.Request.Host, ":")[0] + subs, err := a.subService.GetSubs(subId, host) + if err != nil { + c.String(400, "Error!") + } else { + result := "" + for _, sub := range subs { + result += sub + "\n" + } + c.String(200, base64.StdEncoding.EncodeToString([]byte(result))) + } +} |
