Optimizations, remove a call to string.format, remove an if in else/if for deciding pow and/or captcha check

This commit is contained in:
Thomas Lynch
2024-09-16 21:00:20 +10:00
parent f1d827f3b3
commit 45f81f96ae
2 changed files with 9 additions and 19 deletions

View File

@ -152,7 +152,6 @@ function _M.view(applet)
local combined_challenge = user_key .. "#" .. challenge_hash .. "#" .. expiry .. "#" .. signature
-- define body sections
local site_name_body = ""
local captcha_body = ""
local pow_body = ""
local noscript_extra_body = ""
@ -183,10 +182,6 @@ function _M.view(applet)
end
-- pow at least is always enabled when reaching bot-check page
site_name_body = string.format(
templates.site_name_section,
string.format(ll["Verifying your connection to %s"], host)
)
if captcha_enabled then
captcha_body = string.format(
templates.captcha_section,
@ -235,7 +230,7 @@ function _M.view(applet)
argon_time,
argon_kb,
ddos_config["pt"],
site_name_body,
string.format(ll["Verifying your connection to %s"], host),
pow_body,
captcha_body,
ll["JavaScript is required on this page."],
@ -485,13 +480,13 @@ function _M.decide_checks_necessary(txn)
if ddos_map_json.m == 0
or (ddos_map_json.t == true and txn.sf:hdr("X-Country-Code") ~= "T1") then
return
elseif ddos_map_json.m == 1 then
txn:set_var("txn.validate_pow", true)
elseif ddos_map_json.m == 2 then
else
txn:set_var("txn.validate_pow", true)
if ddos_map_json.m == 2 then
txn:set_var("txn.validate_captcha", true)
end
end
end
-- no entry in the map
end

View File

@ -16,7 +16,10 @@ _M.body = [[
<script src="/.basedflare/js/challenge.min.js"></script>
</head>
<body data-pow="%s" data-diff="%s" data-time="%s" data-kb="%s" data-mode="%s">
<h3 class="pt">
<img src="/.basedflare/pow-icon" width="64" height="64" alt=" ">
%s
</h3>
%s
%s
<noscript>
@ -69,14 +72,6 @@ _M.noscript_extra_sha256 = [[
</details>
]]
-- title with favicon and hostname
_M.site_name_section = [[
<h3 class="pt">
<img src="/.basedflare/pow-icon" width="64" height="64" alt=" ">
%s
</h3>
]]
-- animation while waiting
_M.pow_section = [[
<span>