mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 23:16:03 +01:00
Check currentVersion is valid before performing HttpRequest, and print a message when failing.
30 lines
1008 B
Lua
30 lines
1008 B
Lua
function lib.versionCheck(repository)
|
|
local resource = GetInvokingResource() or GetCurrentResourceName()
|
|
|
|
local currentVersion = GetResourceMetadata(resource, 'version', 0)
|
|
|
|
if currentVersion then
|
|
currentVersion = currentVersion:match('%d%.%d+%.%d+')
|
|
end
|
|
|
|
if not currentVersion then return print(("^1Unable to determine current resource version for '%s' ^0"):format(resource)) end
|
|
|
|
SetTimeout(1000, function()
|
|
PerformHttpRequest(('https://api.github.com/repos/%s/releases/latest'):format(repository), function(status, response)
|
|
if status ~= 200 then return end
|
|
|
|
response = json.decode(response)
|
|
if response.prerelease then return end
|
|
|
|
local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
|
|
if not latestVersion then return end
|
|
|
|
if currentVersion >= latestVersion then return end
|
|
|
|
print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
|
|
end, 'GET')
|
|
end)
|
|
end
|
|
|
|
lib.versionCheck('overextended/ox_lib')
|