Skip to content

Commit

Permalink
🐛 fix installer not following redirects on MC 1.12 (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberbit committed Nov 5, 2024
1 parent 348b984 commit 5d84016
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/telem/bin/install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@ local ui = (function ()
return b
end)()

-- patch redirect support for CC:T on 1.12 (and earlier?)
local function httpGetRedirect(url, maxRedirects)
maxRedirects = maxRedirects or 5
local redirects = 0

while redirects < maxRedirects do
local response = http.get(url)
if not response then
return nil, 'Failed to get response'
end

local statusCode = response.getResponseCode()
if statusCode >= 300 and statusCode < 400 then
local location = response.getResponseHeaders()['Location']
if not location then
return nil, 'Redirect location not provided'
end
url = location
redirects = redirects + 1
else
return response
end
end

return nil, 'Too many redirects'
end

local termW, termH = term.getSize()

local boxSizing = {
Expand Down Expand Up @@ -84,7 +111,7 @@ local youWouldntDownloadATree = function (tree, updateProgress, updateBlob)
local bloburl = string.gsub(tree.url, '{sha}', tree.sha)
bloburl = string.gsub(bloburl, '{path}', v.path)

local blobreq = http.get(bloburl)
local blobreq = httpGetRedirect(bloburl)

local fout = fs.open(physicalPath, 'w')
fout.write(blobreq.readAll())
Expand Down Expand Up @@ -127,7 +154,7 @@ local showReleaseSelector = function ()

local releaseUrl = 'https://get.telem.cc/blob/releases'

local req = http.get(releaseUrl)
local req = httpGetRedirect(releaseUrl)
local jres = textutils.unserialiseJSON(req.readAll())

local nonPreReleases = {}
Expand Down Expand Up @@ -283,7 +310,7 @@ local installActions = {

local treeUrl = 'https://get.telem.cc/blob/lib/main'

local req = http.get(treeUrl)
local req = httpGetRedirect(treeUrl)
local res = textutils.unserialiseJSON(req.readAll())

youWouldntDownloadATree(res, progress, currentBlob)
Expand All @@ -292,7 +319,7 @@ local installActions = {

treeUrl = 'https://get.telem.cc/blob/vendor/main'

req = http.get(treeUrl)
req = httpGetRedirect(treeUrl)
res = textutils.unserialiseJSON(req.readAll())

youWouldntDownloadATree(res, progress, currentBlob)
Expand Down

0 comments on commit 5d84016

Please sign in to comment.