Skip to content

Commit

Permalink
Xray core buggy version removed
Browse files Browse the repository at this point in the history
only v24.10.16 or newer and v1.8.24
  • Loading branch information
MHSanaei committed Oct 29, 2024
1 parent e359b5c commit 0e3691f
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions web/service/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,28 +248,46 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
}

func (s *ServerService) GetXrayVersions() ([]string, error) {
url := "https://api.github.com/repos/XTLS/Xray-core/releases"
resp, err := http.Get(url)
const (
XrayURL = "https://api.github.com/repos/XTLS/Xray-core/releases"
bufferSize = 8192
)

resp, err := http.Get(XrayURL)
if err != nil {
return nil, err
}

defer resp.Body.Close()
buffer := bytes.NewBuffer(make([]byte, 8192))

buffer := bytes.NewBuffer(make([]byte, bufferSize))
buffer.Reset()
_, err = buffer.ReadFrom(resp.Body)
if err != nil {
if _, err := buffer.ReadFrom(resp.Body); err != nil {
return nil, err
}

releases := make([]Release, 0)
err = json.Unmarshal(buffer.Bytes(), &releases)
if err != nil {
var releases []Release
if err := json.Unmarshal(buffer.Bytes(), &releases); err != nil {
return nil, err
}

var versions []string
for _, release := range releases {
if release.TagName >= "v1.7.5" {
tagVersion := strings.TrimPrefix(release.TagName, "v")
tagParts := strings.Split(tagVersion, ".")
if len(tagParts) != 3 {
continue
}

major, err1 := strconv.Atoi(tagParts[0])
minor, err2 := strconv.Atoi(tagParts[1])
patch, err3 := strconv.Atoi(tagParts[2])
if err1 != nil || err2 != nil || err3 != nil {
continue
}

if (major == 1 && minor == 8 && patch == 24) ||
(major == 24 && ((minor > 10) || (minor == 10 && patch >= 16))) ||
(major > 24) {
versions = append(versions, release.TagName)
}
}
Expand Down

0 comments on commit 0e3691f

Please sign in to comment.