fix: failded connection spam

This commit is contained in:
Linventif 2024-03-29 14:23:29 +01:00
parent 3210d70554
commit 343f00798c
No known key found for this signature in database
GPG Key ID: FAC0CA60F9AEEC24

View File

@ -1,10 +1,6 @@
local apiVersion = "v3"
gmInte.http = gmInte.http || {}
//
// HTTP
//
local function getAPIURL(endpoint)
local url = "https://" .. gmInte.config.apiFQDN .. "/" .. apiVersion
@ -22,7 +18,6 @@ local function getAPIURL(endpoint)
end
local function showableBody(endpoint)
// if start with /streams or /screenshots return false
if (string.sub(endpoint, 1, 8) == "/streams" || string.sub(endpoint, 1, 12) == "/screenshots") then
return false
end
@ -34,6 +29,12 @@ local function genRequestID()
return "gmInte-" .. util.CRC(tostring(SysTime()))
end
local lastErrorMessages = 0
local function noTokenError()
if (curTime() - lastErrorMessages < 10) then return end
gmInte.log("HTTP Failed: No token provided")
end
function gmInte.http.requestAPI(params)
local body = params.body && util.TableToJSON(params.body || {}) || ""
local bodyLength = string.len(body)
@ -46,6 +47,10 @@ function gmInte.http.requestAPI(params)
local showableBody = showableBody(params.endpoint)
local requestID = genRequestID()
if (token == "") then
return noTokenError()
end
local headers = {
["Content-Type"] = "application/json",
["Content-Length"] = bodyLength,