-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
211 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package controller | ||
|
||
import ( | ||
"x-ui/web/service" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type XraySettingController struct { | ||
XraySettingService service.XraySettingService | ||
SettingService service.SettingService | ||
} | ||
|
||
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("/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 | ||
} | ||
jsonObj(c, xraySetting, 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package service | ||
|
||
import ( | ||
_ "embed" | ||
"encoding/json" | ||
"x-ui/util/common" | ||
"x-ui/xray" | ||
) | ||
|
||
type XraySettingService struct { | ||
SettingService | ||
} | ||
|
||
func (s *XraySettingService) SaveXraySetting(newXraySettings string) error { | ||
if err := s.CheckXrayConfig(newXraySettings); err != nil { | ||
return err | ||
} | ||
return s.SettingService.saveSetting("xrayTemplateConfig", newXraySettings) | ||
} | ||
|
||
func (s *XraySettingService) CheckXrayConfig(XrayTemplateConfig string) error { | ||
xrayConfig := &xray.Config{} | ||
err := json.Unmarshal([]byte(XrayTemplateConfig), xrayConfig) | ||
if err != nil { | ||
return common.NewError("xray template config invalid:", err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.