mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 22:07:34 +00:00
fix: requestIndicator
This commit is contained in:
parent
70ef993039
commit
f67ed9e62a
|
@ -12,7 +12,7 @@ local function showableBody(endpoint)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local requestIndicator = {}
|
local requestIndicator = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
function gmInte.http.requestAPI(params)
|
function gmInte.http.requestAPI(params)
|
||||||
local body = params.body && util.TableToJSON(params.body || {}) || ""
|
local body = params.body && util.TableToJSON(params.body || {}) || ""
|
||||||
local bodyLength = string.len(body)
|
local bodyLength = string.len(body)
|
||||||
|
@ -22,10 +22,10 @@ function gmInte.http.requestAPI(params)
|
||||||
local success = params.success || function() end
|
local success = params.success || function() end
|
||||||
local failed = params.failed || function() end
|
local failed = params.failed || function() end
|
||||||
local version = gmInte.version || "Unknown"
|
local version = gmInte.version || "Unknown"
|
||||||
local showableBody = showableBody(params.endpoint)
|
local actualSec = math.Round(SysTime()) % 10
|
||||||
local localRequestID = util.CRC(tostring(SysTime()))
|
local localRequestID = util.CRC(tostring(SysTime()))
|
||||||
requestIndicator[CurTime()] = requestIndicator[CurTime()] + 1 || 1
|
requestIndicator[actualSec] = requestIndicator[actualSec] && requestIndicator[actualSec] + 1 || 1
|
||||||
timer.Simple(10, function() requestIndicator[CurTime()] = requestIndicator[CurTime()] - 1 end)
|
timer.Simple(10, function() requestIndicator[actualSec] = requestIndicator[actualSec] - 1 end)
|
||||||
if token == "" then
|
if token == "" then
|
||||||
return failed(401, {
|
return failed(401, {
|
||||||
["error"] = "No token provided"
|
["error"] = "No token provided"
|
||||||
|
@ -43,7 +43,7 @@ function gmInte.http.requestAPI(params)
|
||||||
gmInte.log("HTTP FQDN: " .. gmInte.config.apiFQDN, true)
|
gmInte.log("HTTP FQDN: " .. gmInte.config.apiFQDN, true)
|
||||||
gmInte.log("HTTP Request ID: " .. localRequestID, true)
|
gmInte.log("HTTP Request ID: " .. localRequestID, true)
|
||||||
gmInte.log("HTTP Request: " .. method .. " " .. url, true)
|
gmInte.log("HTTP Request: " .. method .. " " .. url, true)
|
||||||
gmInte.log("HTTP Body: " .. (showableBody && body || "HIDDEN"), true)
|
gmInte.log("HTTP Body: " .. (showableBody(params.endpoint) && body || "HIDDEN"), true)
|
||||||
HTTP({
|
HTTP({
|
||||||
["url"] = url,
|
["url"] = url,
|
||||||
["method"] = method,
|
["method"] = method,
|
||||||
|
@ -96,7 +96,14 @@ end
|
||||||
|
|
||||||
local nextLogPacket = {}
|
local nextLogPacket = {}
|
||||||
function gmInte.http.postLog(endpoint, data)
|
function gmInte.http.postLog(endpoint, data)
|
||||||
if requestIndicator[CurTime()] > 20 then
|
local requestAverage = 0
|
||||||
|
PrintTable(requestIndicator)
|
||||||
|
for k, v in ipairs(requestIndicator) do
|
||||||
|
requestAverage = requestAverage + v
|
||||||
|
end
|
||||||
|
|
||||||
|
requestAverage = requestAverage / 10
|
||||||
|
if requestAverage >= 2 then
|
||||||
local logPacketIndex = #nextLogPacket + 1
|
local logPacketIndex = #nextLogPacket + 1
|
||||||
table.insert(nextLogPacket, {
|
table.insert(nextLogPacket, {
|
||||||
["endpoint"] = endpoint,
|
["endpoint"] = endpoint,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user