mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
tweak(resource/version): currentVersion validation
Check currentVersion is valid before performing HttpRequest, and print a message when failing.
This commit is contained in:
@@ -1,6 +1,14 @@
|
|||||||
function lib.versionCheck(repository)
|
function lib.versionCheck(repository)
|
||||||
local resource = GetInvokingResource() or GetCurrentResourceName()
|
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()
|
SetTimeout(1000, function()
|
||||||
PerformHttpRequest(('https://api.github.com/repos/%s/releases/latest'):format(repository), function(status, response)
|
PerformHttpRequest(('https://api.github.com/repos/%s/releases/latest'):format(repository), function(status, response)
|
||||||
if status ~= 200 then return end
|
if status ~= 200 then return end
|
||||||
@@ -8,9 +16,6 @@ function lib.versionCheck(repository)
|
|||||||
response = json.decode(response)
|
response = json.decode(response)
|
||||||
if response.prerelease then return end
|
if response.prerelease then return end
|
||||||
|
|
||||||
local currentVersion = GetResourceMetadata(resource, 'version', 0):match('%d%.%d+%.%d+')
|
|
||||||
if not currentVersion then return end
|
|
||||||
|
|
||||||
local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
|
local latestVersion = response.tag_name:match('%d%.%d+%.%d+')
|
||||||
if not latestVersion then return end
|
if not latestVersion then return end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user