feat: standalone: minor improvements

This commit is contained in:
tiago
2026-03-02 15:55:21 +00:00
parent fa47df01bf
commit 5550c2eeeb
4 changed files with 15 additions and 8 deletions
+1 -1
View File
@@ -331,7 +331,7 @@ class Cap extends EventEmitter {
}),
);
const isValid = hashes.every((pair) => pair?.[0].startsWith(pair[1]));
const isValid = hashes.every((pair) => pair?.[0]?.startsWith?.(pair[1]));
if (!isValid) return { success: false, message: "Invalid solution" };
+7 -2
View File
@@ -8,7 +8,12 @@ const welcomeScreen = document.getElementById("welcomeScreen");
const keyDetail = document.getElementById("keyDetail");
const escapeHtml = (s) => {
return s.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
return String(s)
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
};
const api = async (method, path, body) => {
@@ -508,7 +513,7 @@ async function saveConfig() {
if (!name || difficulty < 2 || challengeCount < 1 || saltSize < 7) {
showModal(
"Validation Error",
"Validation error",
`<div class="modal-body"><p>Please check your input values. Difficulty must be ≥2, challenge count ≥1, and salt size ≥7.</p></div>`,
);
btn.disabled = false;
+2 -1
View File
@@ -4,7 +4,8 @@ export const ratelimitGenerator = (req, server) => {
const ip = req.headers.get(header) || req.headers.get(header.toLowerCase());
if (ip) {
return ip.split(",")[0].trim();
const parts = ip.split(",").filter((e) => !!e.trim());
return (parts[parts.length - 1] || parts[0]).trim();
}
console.error(
+5 -4
View File
@@ -295,6 +295,7 @@ export const server = new Elysia({
instrumentation,
blockAutomatedBrowsers,
} = body;
const config = {
...keyDefaults,
...existingConfig,
@@ -313,10 +314,10 @@ export const server = new Elysia({
},
{
body: t.Object({
name: t.Optional(t.String()),
difficulty: t.Optional(t.Number()),
challengeCount: t.Optional(t.Number()),
saltSize: t.Optional(t.Number()),
name: t.Optional(t.String({ maxLength: 600 })),
difficulty: t.Optional(t.Number({ minimum: 1, maximum: 8 })),
challengeCount: t.Optional(t.Number({ minimum: 1, maximum: 500 })),
saltSize: t.Optional(t.Number({ minimum: 7, maximum: 1_001 })),
instrumentation: t.Optional(t.Boolean()),
blockAutomatedBrowsers: t.Optional(t.Boolean()),
}),