mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 22:07:34 +00:00
fix: failded connection spam
This commit is contained in:
parent
3210d70554
commit
343f00798c
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user