Skip to content

Commit be770f5

Browse files
authored
Merge pull request #13 from risu729/main
feat: support lts releases in linux
2 parents d955e1e + 0ae6d04 commit be770f5

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

hooks/available.lua

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ end
1616

1717
function GetReleaseListForWindows()
1818
local result = {}
19-
local urls = { WIN_URL, WIN_URL_LTS }
19+
local urls = { WIN_RELEASES_URL, WIN_RELEASES_URL_LTS }
2020

2121
for _, url in ipairs(urls) do
2222
local resp, err = http.get({ url = url })
@@ -41,7 +41,7 @@ function GetReleaseListForWindows()
4141
name = versionStr
4242
}
4343

44-
entry.is_from_lts = (url == WIN_URL_LTS)
44+
entry.is_from_lts = (url == WIN_RELEASES_URL_LTS)
4545
table.insert(result, entry)
4646
end
4747
end
@@ -53,20 +53,27 @@ function GetReleaseListForWindows()
5353
end
5454

5555
function GetReleaseListForLinux()
56-
local resp, err = http.get({
57-
url = URL .. '/releases'
58-
})
59-
local doc = html.parse(resp.body)
60-
6156
local result = {}
62-
doc:find("#layout-content h2"):each(function(i, selection)
63-
local versionStr = selection:text()
64-
if util.compare_versions(versionStr, "5.3.2") >= 0 then
65-
table.insert(result, {
66-
version = versionStr,
67-
})
57+
local urls = { RELEASES_URL, RELEASES_URL_LTS }
58+
59+
for _, url in ipairs(urls) do
60+
local resp, err = http.get({ url = url })
61+
local is_from_lts = (url == RELEASES_URL_LTS)
62+
63+
if resp then
64+
local doc = html.parse(resp.body)
65+
local query = "#layout-content " .. (is_from_lts and "h3" or "h2")
66+
doc:find(query):each(function(i, selection)
67+
local versionStr = is_from_lts and selection:attr("id") or selection:text()
68+
versionStr = versionStr:gsub("^v", "")
69+
if util.compare_versions(versionStr, "5.3.2") >= 0 then
70+
table.insert(result, {
71+
version = versionStr,
72+
})
73+
end
74+
end)
6875
end
69-
end)
76+
end
7077

7178
table.sort(result, function(a, b)
7279
return util.compare_versions(a.version, b.version) > 0

hooks/pre_install.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ function PLUGIN:PreInstall(ctx)
3939
end
4040

4141
function GetReleaseForWindows(versions)
42-
url = WIN_URL .. versions.name
42+
url = WIN_RELEASES_URL .. versions.name
4343

4444
if (versions.is_from_lts) then
45-
url = WIN_URL_LTS .. versions.name
45+
url = WIN_RELEASES_URL_LTS .. versions.name
4646
end
4747
return {
4848
version = versions.version,

lib/constants.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
URL = 'https://www.php.net/'
2-
WIN_URL = 'https://windows.php.net/downloads/releases/archives/'
3-
WIN_URL_LTS = 'https://windows.php.net/downloads/releases/'
1+
URL = 'https://www.php.net'
2+
RELEASES_URL = URL .. '/releases/'
3+
RELEASES_URL_LTS = URL .. '/downloads.php'
4+
WIN_RELEASES_URL = 'https://windows.php.net/downloads/releases/archives/'
5+
WIN_RELEASES_URL_LTS = 'https://windows.php.net/downloads/releases/'

0 commit comments

Comments
 (0)