Standard formatting and removal of redundant structures

This commit is contained in:
Pk-web6936 2025-05-06 16:27:03 +00:00
parent 1aed2d8cdc
commit da04b36f09
3 changed files with 50 additions and 50 deletions

View file

@ -13,10 +13,10 @@ import (
"x-ui/database" "x-ui/database"
"x-ui/logger" "x-ui/logger"
"x-ui/sub" "x-ui/sub"
"x-ui/util/crypto"
"x-ui/web" "x-ui/web"
"x-ui/web/global" "x-ui/web/global"
"x-ui/web/service" "x-ui/web/service"
"x-ui/util/crypto"
"github.com/op/go-logging" "github.com/op/go-logging"
) )

View file

@ -85,7 +85,7 @@ func (a *SUBController) subs(c *gin.Context) {
// Add headers // Add headers
c.Writer.Header().Set("Subscription-Userinfo", header) c.Writer.Header().Set("Subscription-Userinfo", header)
c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval) c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval)
c.Writer.Header().Set("Profile-Title", "base64:" + base64.StdEncoding.EncodeToString([]byte(a.subTitle))) c.Writer.Header().Set("Profile-Title", "base64:"+base64.StdEncoding.EncodeToString([]byte(a.subTitle)))
if a.subEncrypt { if a.subEncrypt {
c.String(200, base64.StdEncoding.EncodeToString([]byte(result))) c.String(200, base64.StdEncoding.EncodeToString([]byte(result)))
@ -119,7 +119,7 @@ func (a *SUBController) subJsons(c *gin.Context) {
// Add headers // Add headers
c.Writer.Header().Set("Subscription-Userinfo", header) c.Writer.Header().Set("Subscription-Userinfo", header)
c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval) c.Writer.Header().Set("Profile-Update-Interval", a.updateInterval)
c.Writer.Header().Set("Profile-Title", "base64:" + base64.StdEncoding.EncodeToString([]byte(a.subTitle))) c.Writer.Header().Set("Profile-Title", "base64:"+base64.StdEncoding.EncodeToString([]byte(a.subTitle)))
c.String(200, jsonSub) c.String(200, jsonSub)
} }

View file

@ -592,63 +592,63 @@ func (s *ServerService) ImportDB(file multipart.File) error {
} }
func (s *ServerService) UpdateGeofile(fileName string) error { func (s *ServerService) UpdateGeofile(fileName string) error {
files := []struct { files := []struct {
URL string URL string
FileName string FileName string
}{ }{
{"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat", "geoip.dat"}, {"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat", "geoip.dat"},
{"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat", "geosite.dat"}, {"https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat", "geosite.dat"},
{"https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat", "geoip_IR.dat"}, {"https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geoip.dat", "geoip_IR.dat"},
{"https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat", "geosite_IR.dat"}, {"https://github.com/chocolate4u/Iran-v2ray-rules/releases/latest/download/geosite.dat", "geosite_IR.dat"},
{"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat", "geoip_RU.dat"}, {"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geoip.dat", "geoip_RU.dat"},
{"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat", "geosite_RU.dat"}, {"https://github.com/runetfreedom/russia-v2ray-rules-dat/releases/latest/download/geosite.dat", "geosite_RU.dat"},
} }
downloadFile := func(url, destPath string) error { downloadFile := func(url, destPath string) error {
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
return common.NewErrorf("Failed to download Geofile from %s: %v", url, err) return common.NewErrorf("Failed to download Geofile from %s: %v", url, err)
} }
defer resp.Body.Close() defer resp.Body.Close()
file, err := os.Create(destPath) file, err := os.Create(destPath)
if err != nil { if err != nil {
return common.NewErrorf("Failed to create Geofile %s: %v", destPath, err) return common.NewErrorf("Failed to create Geofile %s: %v", destPath, err)
} }
defer file.Close() defer file.Close()
_, err = io.Copy(file, resp.Body) _, err = io.Copy(file, resp.Body)
if err != nil { if err != nil {
return common.NewErrorf("Failed to save Geofile %s: %v", destPath, err) return common.NewErrorf("Failed to save Geofile %s: %v", destPath, err)
} }
return nil return nil
} }
var fileURL string var fileURL string
for _, file := range files { for _, file := range files {
if file.FileName == fileName { if file.FileName == fileName {
fileURL = file.URL fileURL = file.URL
break break
} }
} }
if fileURL == "" { if fileURL == "" {
return common.NewErrorf("File '%s' not found in the list of Geofiles", fileName) return common.NewErrorf("File '%s' not found in the list of Geofiles", fileName)
} }
destPath := fmt.Sprintf("%s/%s", config.GetBinFolderPath(), fileName) destPath := fmt.Sprintf("%s/%s", config.GetBinFolderPath(), fileName)
if err := downloadFile(fileURL, destPath); err != nil { if err := downloadFile(fileURL, destPath); err != nil {
return common.NewErrorf("Error downloading Geofile '%s': %v", fileName, err) return common.NewErrorf("Error downloading Geofile '%s': %v", fileName, err)
} }
err := s.RestartXrayService() err := s.RestartXrayService()
if err != nil { if err != nil {
return common.NewErrorf("Updated Geofile '%s' but Failed to start Xray: %v", fileName, err) return common.NewErrorf("Updated Geofile '%s' but Failed to start Xray: %v", fileName, err)
} }
return nil return nil
} }
func (s *ServerService) GetNewX25519Cert() (any, error) { func (s *ServerService) GetNewX25519Cert() (any, error) {