11local http = require (" http" )
22local json = require (" json" )
3- local os = require (" os" )
43local util = {}
54
65local GITHUB_API_URL = " https://api.github.com/repos/chaosblade-io/chaosblade/releases"
76
87function util :Available ()
9- local code , body = http .get (GITHUB_API_URL )
10- if code ~= 200 then
8+ local resp , err = http .get ({
9+ url = GITHUB_API_URL
10+ })
11+ if err ~= nil or resp .status_code ~= 200 then
1112 return nil , " Failed to fetch releases from GitHub API."
1213 end
13- local releases = json .decode (body )
14+ local releases = json .decode (resp . body )
1415 local versions = {}
1516 for _ , release in ipairs (releases ) do
17+ -- Remove 'v' prefix from tag_name to avoid double 'v' prefix
18+ local clean_version = release .tag_name :gsub (" ^v" , " " )
1619 table.insert (versions , {
17- version = release . tag_name ,
20+ version = clean_version ,
1821 note = release .prerelease and " prerelease" or " "
1922 })
2023 end
2124 return versions
2225end
2326
2427function util :GetDownloadInfo (version )
25- local arch = os .arch ()
28+ local os_type = RUNTIME .osType
29+ os_type = " linux"
30+ -- if os_type ~= "Linux" then
31+ -- return nil, "Unsupported OS type: " .. os_type
32+ -- end
33+
34+ local arch = RUNTIME .archType
2635 if arch == " x86_64" then
2736 arch = " amd64"
2837 end
29- local os_type = os .type ()
30- if os_type == " Darwin" then
31- os_type = " darwin"
32- elseif os_type == " Linux" then
33- os_type = " linux"
34- else
35- return nil , " Unsupported OS type: " .. os_type
36- end
37-
38- -- Remove 'v' prefix from version for filename
39- local clean_version = version :gsub (" ^v" , " " )
40- local file_name = string.format (" chaosblade-%s-%s-%s.tar.gz" , clean_version , os_type , arch )
41- local url = string.format (" https://github.com/chaosblade-io/chaosblade/releases/download/%s/%s" , version , file_name )
38+ arch = " amd64"
39+ local file_name = string.format (" chaosblade-%s-%s-%s.tar.gz" , version , os_type , arch )
40+ local url = string.format (" https://github.com/chaosblade-io/chaosblade/releases/download/v%s/%s" , version , file_name )
4241
43- local checksum_url = string.format (" https://github.com/chaosblade-io/chaosblade/releases/download/%s/checksum.txt" , version )
44- local code , body = http .get (checksum_url )
45- local checksum = " "
46-
47- -- Try to get checksum if available, but don't fail if not found
48- if code == 200 then
49- for line in string.gmatch (body , " [^\r\n ]+" ) do
50- local sha , name = line :match (" ([a-f0-9]+)%s+(.+)" )
51- if name == file_name then
52- checksum = sha
53- break
54- end
55- end
56- end
57-
58- -- Return the download info, with or without checksum
59- local result = {
60- url = url
61- }
62-
63- if checksum ~= " " then
64- result .sha256 = checksum
65- end
66-
67- return result
42+ return url
6843end
6944
70- return util
45+ return util
0 commit comments