From 5e47b4e94925c2272a7f0a4cc355cede72c671a4 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Fri, 8 Dec 2023 17:18:51 +0100 Subject: [PATCH] pagination and sub URI support #1300 --- web/controller/setting.go | 41 ++-------------- web/entity/entity.go | 8 +++ web/html/common/qrcode_modal.html | 3 +- web/html/xui/component/setting.html | 6 +-- web/html/xui/inbound_info_modal.html | 3 +- web/html/xui/inbounds.html | 40 ++++++++++----- web/html/xui/settings.html | 2 + web/service/setting.go | 68 ++++++++++++++++++++++++++ web/translation/translate.en_US.toml | 4 ++ web/translation/translate.es_ES.toml | 4 ++ web/translation/translate.fa_IR.toml | 4 ++ web/translation/translate.ru_RU.toml | 10 ++-- web/translation/translate.vi_VN.toml | 4 ++ web/translation/translate.zh_Hans.toml | 4 ++ 14 files changed, 142 insertions(+), 59 deletions(-) diff --git a/web/controller/setting.go b/web/controller/setting.go index 96223c28..64cae71b 100644 --- a/web/controller/setting.go +++ b/web/controller/setting.go @@ -56,44 +56,11 @@ func (a *SettingController) getAllSetting(c *gin.Context) { } func (a *SettingController) getDefaultSettings(c *gin.Context) { - type settingFunc func() (interface{}, error) - - settings := map[string]settingFunc{ - "expireDiff": func() (interface{}, error) { return a.settingService.GetExpireDiff() }, - "trafficDiff": func() (interface{}, error) { return a.settingService.GetTrafficDiff() }, - "defaultCert": func() (interface{}, error) { return a.settingService.GetCertFile() }, - "defaultKey": func() (interface{}, error) { return a.settingService.GetKeyFile() }, - "tgBotEnable": func() (interface{}, error) { return a.settingService.GetTgbotenabled() }, - "subEnable": func() (interface{}, error) { return a.settingService.GetSubEnable() }, - "subPort": func() (interface{}, error) { return a.settingService.GetSubPort() }, - "subPath": func() (interface{}, error) { return a.settingService.GetSubPath() }, - "subDomain": func() (interface{}, error) { return a.settingService.GetSubDomain() }, - "subKeyFile": func() (interface{}, error) { return a.settingService.GetSubKeyFile() }, - "subCertFile": func() (interface{}, error) { return a.settingService.GetSubCertFile() }, - "subEncrypt": func() (interface{}, error) { return a.settingService.GetSubEncrypt() }, - "subShowInfo": func() (interface{}, error) { return a.settingService.GetSubShowInfo() }, + result, err := a.settingService.GetDefaultSettings(c.Request.Host) + if err != nil { + jsonMsg(c, I18nWeb(c, "pages.settings.toasts.getSettings"), err) + return } - - result := make(map[string]interface{}) - - for key, fn := range settings { - value, err := fn() - if err != nil { - jsonMsg(c, I18nWeb(c, "pages.settings.toasts.getSettings"), err) - return - } - result[key] = value - } - - subTLS := false - if result["subKeyFile"] != "" || result["subCertFile"] != "" { - subTLS = true - } - result["subTLS"] = subTLS - - delete(result, "subKeyFile") - delete(result, "subCertFile") - jsonObj(c, result, nil) } diff --git a/web/entity/entity.go b/web/entity/entity.go index 2c7b39ca..94f0171f 100644 --- a/web/entity/entity.go +++ b/web/entity/entity.go @@ -22,6 +22,7 @@ type AllSetting struct { WebKeyFile string `json:"webKeyFile" form:"webKeyFile"` WebBasePath string `json:"webBasePath" form:"webBasePath"` SessionMaxAge int `json:"sessionMaxAge" form:"sessionMaxAge"` + PageSize int `json:"pageSize" form:"pageSize"` ExpireDiff int `json:"expireDiff" form:"expireDiff"` TrafficDiff int `json:"trafficDiff" form:"trafficDiff"` TgBotEnable bool `json:"tgBotEnable" form:"tgBotEnable"` @@ -44,6 +45,7 @@ type AllSetting struct { SubUpdates int `json:"subUpdates" form:"subUpdates"` SubEncrypt bool `json:"subEncrypt" form:"subEncrypt"` SubShowInfo bool `json:"subShowInfo" form:"subShowInfo"` + SubURI string `json:"subURI" form:"subURI"` } func (s *AllSetting) CheckValid() error { @@ -93,6 +95,12 @@ func (s *AllSetting) CheckValid() error { if !strings.HasSuffix(s.WebBasePath, "/") { s.WebBasePath += "/" } + if !strings.HasPrefix(s.SubPath, "/") { + s.SubPath = "/" + s.SubPath + } + if !strings.HasSuffix(s.SubPath, "/") { + s.SubPath += "/" + } _, err := time.LoadLocation(s.TimeLocation) if err != nil { diff --git a/web/html/common/qrcode_modal.html b/web/html/common/qrcode_modal.html index 2db1948b..85ada3d4 100644 --- a/web/html/common/qrcode_modal.html +++ b/web/html/common/qrcode_modal.html @@ -86,8 +86,7 @@ }); }, genSubLink(subID) { - const { domain: host, port, tls: isTLS, path: base } = app.subSettings; - return buildURL({ host, port, isTLS, base, path: subID+'?name='+remark }); + return app.subSettings.subURI+subID+'?name='+subID; } }, updated() { diff --git a/web/html/xui/component/setting.html b/web/html/xui/component/setting.html index 568f03de..82c0ae75 100644 --- a/web/html/xui/component/setting.html +++ b/web/html/xui/component/setting.html @@ -13,10 +13,10 @@