Skip to content

Commit

Permalink
chore: ox_lib 🎨 Run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator committed Jun 29, 2024
1 parent 51ce7cd commit 7549023
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
50 changes: 30 additions & 20 deletions server-data/resources/[ox]/ox_lib/resource/version/server.lua
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
function lib.versionCheck(repository)
local resource = GetInvokingResource() or GetCurrentResourceName()
local resource = GetInvokingResource() or GetCurrentResourceName()

local currentVersion = GetResourceMetadata(resource, 'version', 0)
local currentVersion = GetResourceMetadata(resource, "version", 0)

if currentVersion then
currentVersion = currentVersion:match('%d+%.%d+%.%d+')
end
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
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
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
response = json.decode(response)
if response.prerelease then
return
end

local latestVersion = response.tag_name:match('%d+%.%d+%.%d+')
if not latestVersion or latestVersion == currentVersion then return end
local latestVersion = response.tag_name:match("%d+%.%d+%.%d+")
if not latestVersion or latestVersion == currentVersion then
return
end

local cv = { string.strsplit('.', currentVersion) }
local lv = { string.strsplit('.', latestVersion) }
local cv = { string.strsplit(".", currentVersion) }
local lv = { string.strsplit(".", latestVersion) }

for i = 1, #cv do
local current, minimum = tonumber(cv[i]), tonumber(lv[i])

if current ~= minimum then
if current < minimum then
return print(('^3An update is available for %s (current version: %s)\r\n%s^0'):format(resource, currentVersion, response.html_url))
else break end
return print(("^3An update is available for %s (current version: %s)\r\n%s^0"):format(resource, currentVersion, response.html_url))
else
break
end
end
end
end, 'GET')
end)
end, "GET")
end)
end

lib.versionCheck('overextended/ox_lib')
lib.versionCheck("overextended/ox_lib")
24 changes: 13 additions & 11 deletions server-data/resources/[ox]/ox_lib/resource/version/shared.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
function lib.checkDependency(resource, minimumVersion, printMessage)
local currentVersion = GetResourceMetadata(resource, 'version', 0)
currentVersion = currentVersion and currentVersion:match('%d+%.%d+%.%d+') or 'unknown'
local currentVersion = GetResourceMetadata(resource, "version", 0)
currentVersion = currentVersion and currentVersion:match("%d+%.%d+%.%d+") or "unknown"

if currentVersion ~= minimumVersion then
local cv = { string.strsplit('.', currentVersion) }
local mv = { string.strsplit('.', minimumVersion) }
local msg = ("^1%s requires version '%s' of '%s' (current version: %s)^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion)
if currentVersion ~= minimumVersion then
local cv = { string.strsplit(".", currentVersion) }
local mv = { string.strsplit(".", minimumVersion) }
local msg = ("^1%s requires version '%s' of '%s' (current version: %s)^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion)

for i = 1, #cv do
for i = 1, #cv do
local current, minimum = tonumber(cv[i]), tonumber(mv[i])

if current ~= minimum then
Expand All @@ -17,10 +17,12 @@ function lib.checkDependency(resource, minimumVersion, printMessage)
end

return false, msg
else break end
else
break
end
end
end
end
end
end

return true
return true
end

0 comments on commit 7549023

Please sign in to comment.