Files
community_bridge/modules/version/server/VersionChecker.lua
T

36 lines
1.7 KiB
Lua
Raw Normal View History

2025-02-17 12:14:12 -05:00
Version = Version or {}
2025-03-04 17:50:47 -05:00
---Pass a github username and repo name to check for the latest version of the resource.
2025-05-09 01:59:36 -04:00
---
2025-03-04 17:50:47 -05:00
---Tebex is a optional boolean to determine if the message should be for a escrowed resource or not.
2025-05-09 01:59:36 -04:00
---
---Example Version.VersionChecker("The-Order-Of-The-Sacred-Framework/community_bridge", false)
2025-03-04 17:50:47 -05:00
---@param repoPath string
---@param tebex boolean | nil
---@return nil
function Version.VersionChecker(repoPath, tebex)
2025-05-09 01:59:36 -04:00
local username, reponame = repoPath:match("([^/]+)/([^/]+)")
local resource = reponame and repoPath:match("([^/]+)$")
if not username or not reponame or not resource then
return Prints.Error('^1Invalid repository format. Expected format: "username/reponame"^0')
end
2025-05-09 01:59:36 -04:00
local version = GetResourceMetadata(resource, "version", 0):match('%d+%.%d+%.%d+')
if not version then return end
PerformHttpRequest(('https://api.github.com/repos/%s/%s/releases/latest'):format(username, reponame), function(status, response)
2025-04-12 02:32:55 -04:00
if status ~= 200 then return end
2025-05-09 01:59:36 -04:00
local latest = json.decode(response).tag_name:match('%d+%.%d+%.%d+')
if not latest or latest == version or version:gsub('%D', '') >= latest:gsub('%D', '') then return end
2025-05-09 01:59:36 -04:00
local url = tebex and "https://portal.cfx.re/assets/granted-assets" or json.decode(response).html_url
print(('^1An update is available for %s (current version: %s)\r\n - ^5Please download the latest version from %s^7'):format(resource, version, url))
end, 'GET')
end
AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
2025-02-17 12:14:12 -05:00
Version.VersionChecker("The-Order-Of-The-Sacred-Framework/community_bridge")
end)
return Version