Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlireza Ahmadi <alireza7@gmail.com>2023-12-10 14:57:39 +0300
committerAlireza Ahmadi <alireza7@gmail.com>2023-12-10 14:57:39 +0300
commit4cb67fd1c3129b83f3750f863caba081453f42b1 (patch)
tree85c7e5c47f4415f775729aff26b60796590ef34a /web/controller/xray_setting.go
parent655e17e162129087263e85dfe9d5ba49c0a7044f (diff)
[xray] show xray errors #1300
Diffstat (limited to 'web/controller/xray_setting.go')
-rw-r--r--web/controller/xray_setting.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/web/controller/xray_setting.go b/web/controller/xray_setting.go
new file mode 100644
index 00000000..d4deacd9
--- /dev/null
+++ b/web/controller/xray_setting.go
@@ -0,0 +1,63 @@
+package controller
+
+import (
+ "x-ui/web/service"
+
+ "github.com/gin-gonic/gin"
+)
+
+type XraySettingController struct {
+ XraySettingService service.XraySettingService
+ SettingService service.SettingService
+ InboundService service.InboundService
+ XrayService service.XrayService
+}
+
+func NewXraySettingController(g *gin.RouterGroup) *XraySettingController {
+ a := &XraySettingController{}
+ a.initRouter(g)
+ return a
+}
+
+func (a *XraySettingController) initRouter(g *gin.RouterGroup) {
+ g = g.Group("/xray")
+
+ g.POST("/", a.getXraySetting)
+ g.POST("/update", a.updateSetting)
+ g.GET("/getXrayResult", a.getXrayResult)
+ g.GET("/getDefaultJsonConfig", a.getDefaultXrayConfig)
+}
+
+func (a *XraySettingController) getXraySetting(c *gin.Context) {
+ xraySetting, err := a.SettingService.GetXrayConfigTemplate()
+ if err != nil {
+ jsonMsg(c, I18nWeb(c, "pages.settings.toasts.getSettings"), err)
+ return
+ }
+ inboundTags, err := a.InboundService.GetInboundTags()
+ if err != nil {
+ jsonMsg(c, I18nWeb(c, "pages.settings.toasts.getSettings"), err)
+ return
+ }
+ xrayResponse := "{ \"xraySetting\": " + xraySetting + ", \"inboundTags\": " + inboundTags + " }"
+ jsonObj(c, xrayResponse, nil)
+}
+
+func (a *XraySettingController) updateSetting(c *gin.Context) {
+ xraySetting := c.PostForm("xraySetting")
+ err := a.XraySettingService.SaveXraySetting(xraySetting)
+ jsonMsg(c, I18nWeb(c, "pages.settings.toasts.modifySettings"), err)
+}
+
+func (a *XraySettingController) getDefaultXrayConfig(c *gin.Context) {
+ defaultJsonConfig, err := a.SettingService.GetDefaultXrayConfig()
+ if err != nil {
+ jsonMsg(c, I18nWeb(c, "pages.settings.toasts.getSettings"), err)
+ return
+ }
+ jsonObj(c, defaultJsonConfig, nil)
+}
+
+func (a *XraySettingController) getXrayResult(c *gin.Context) {
+ jsonObj(c, a.XrayService.GetXrayResult(), nil)
+}