fix: updates.rb 处理 Gitee raw URL 302 重定向

This commit is contained in:
2026-06-08 20:31:50 +08:00
parent d494093850
commit 5d2e13db0c
+14 -7
View File
@@ -32,14 +32,21 @@ class UpdateManager
def self.fetch def self.fetch
MethodExecutor.record('debug', 'updates', "Fetching version list from #{VERSION_LIST_URL}") MethodExecutor.record('debug', 'updates', "Fetching version list from #{VERSION_LIST_URL}")
uri = URI(VERSION_LIST_URL) uri = URI(VERSION_LIST_URL)
response = Net::HTTP.get_response(uri) 5.times do # 跟随重定向(Gitee raw URL → raw.giteeusercontent.com
case response.code.to_i response = Net::HTTP.get_response(uri)
when 200 case response.code.to_i
MethodExecutor.record('debug', 'updates', 'Version list fetched successfully.') when 200
response.body MethodExecutor.record('debug', 'updates', 'Version list fetched successfully.')
else return response.body
raise "Unexpected HTTP response code: #{response.code}" when 301, 302, 307, 308
uri = URI(response['location'])
MethodExecutor.record('debug', 'updates', "Following redirect to #{uri}")
next
else
raise "Unexpected HTTP response code: #{response.code}"
end
end end
raise 'Too many redirects'
rescue StandardError => e rescue StandardError => e
MethodExecutor.record('error', 'updates', "Failed to fetch version list: #{e}") MethodExecutor.record('error', 'updates', "Failed to fetch version list: #{e}")
nil nil