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:
Diffstat (limited to 'web/service')
-rw-r--r--web/service/server.go48
1 files changed, 38 insertions, 10 deletions
diff --git a/web/service/server.go b/web/service/server.go
index 376126df..6319cab7 100644
--- a/web/service/server.go
+++ b/web/service/server.go
@@ -254,7 +254,6 @@ func (s *ServerService) GetXrayVersions() ([]string, error) {
}
func (s *ServerService) StopXrayService() (string error) {
-
err := s.xrayService.StopXray()
if err != nil {
logger.Error("stop xray failed:", err)
@@ -265,7 +264,6 @@ func (s *ServerService) StopXrayService() (string error) {
}
func (s *ServerService) RestartXrayService() (string error) {
-
s.xrayService.StopXray()
defer func() {
err := s.xrayService.RestartXray(true)
@@ -363,17 +361,47 @@ func (s *ServerService) UpdateXray(version string) error {
return err
}
- err = copyZipFile("xray", xray.GetBinaryPath())
- if err != nil {
+ downloadFile := func(fileName string, url string) error {
+ os.Remove(fileName)
+ file, err := os.OpenFile(fileName, os.O_CREATE|os.O_RDWR|os.O_TRUNC, fs.ModePerm)
+ if err != nil {
+ return err
+ }
+ defer file.Close()
+ resp, err := http.Get(url)
+ if err != nil {
+ return err
+ }
+ defer resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
+ return fmt.Errorf("download file failed: %s", resp.Status)
+ }
+ _, err = io.Copy(file, resp.Body)
return err
}
- err = copyZipFile("geosite.dat", xray.GetGeositePath())
- if err != nil {
- return err
+
+ copyFiles := map[string]string{
+ "xray": xray.GetBinaryPath(),
+ "geosite.dat": xray.GetGeositePath(),
+ "geoip.dat": xray.GetGeoipPath(),
}
- err = copyZipFile("geoip.dat", xray.GetGeoipPath())
- if err != nil {
- return err
+
+ downloadFiles := map[string]string{
+ xray.GetIranPath(): "https://github.com/MasterKia/iran-hosted-domains/releases/latest/download/iran.dat",
+ }
+
+ for fileName, filePath := range copyFiles {
+ err := copyZipFile(fileName, filePath)
+ if err != nil {
+ return err
+ }
+ }
+
+ for fileName, filePath := range downloadFiles {
+ err := downloadFile(fileName, filePath)
+ if err != nil {
+ return err
+ }
}
return nil