Finalize API envelopes and close validation drift tasks
This commit is contained in:
@@ -89,7 +89,6 @@ function setupHandlers() {
|
||||
e.preventDefault();
|
||||
const username = $("login-username").value.trim();
|
||||
const password = $("login-password").value;
|
||||
if (username.length > 24) return toast("Username must be 24 characters or fewer.", true);
|
||||
if (!username || !password) return toast(t("auth.needCredentials"), true);
|
||||
if (!hasConsent() && !$("login-consent")?.checked) return toast(t("auth.cookieRequired"), true);
|
||||
try {
|
||||
@@ -117,8 +116,6 @@ function setupHandlers() {
|
||||
const displayName = $("register-displayName").value.trim();
|
||||
const adminKey = $("register-adminkey").value.trim();
|
||||
if (!displayName) return toast(t("toast.displayNameRequired") || "Display name is required.", true);
|
||||
if (username.length > 24) return toast("Username must be 24 characters or fewer.", true);
|
||||
if (displayName.length > 16) return toast("Display name must be 16 characters or fewer.", true);
|
||||
if (!username || !password) return toast(t("auth.needCredentials"), true);
|
||||
if (!hasConsent() && !$("register-consent")?.checked) return toast(t("auth.cookieRequired"), true);
|
||||
try {
|
||||
|
||||
@@ -630,8 +630,6 @@ function openSuggestionModal({ title, submitLabel, initial = {}, onSubmit, lockT
|
||||
const errorBox = form.querySelector('[data-error="players"]');
|
||||
const minInput = form.querySelector('input[name="minPlayers"]');
|
||||
const maxInput = form.querySelector('input[name="maxPlayers"]');
|
||||
const screenshotError = form.querySelector('[data-error="screenshot"]');
|
||||
const screenshotInput = form.querySelector('input[name="screenshotUrl"]');
|
||||
const markError = (msg) => {
|
||||
if (errorBox) {
|
||||
errorBox.textContent = msg;
|
||||
@@ -640,7 +638,6 @@ function openSuggestionModal({ title, submitLabel, initial = {}, onSubmit, lockT
|
||||
};
|
||||
const clearError = () => {
|
||||
if (errorBox) errorBox.classList.add("hidden");
|
||||
if (screenshotError) screenshotError.classList.add("hidden");
|
||||
};
|
||||
clearError();
|
||||
const min = data.minPlayers;
|
||||
@@ -657,15 +654,6 @@ function openSuggestionModal({ title, submitLabel, initial = {}, onSubmit, lockT
|
||||
markError(t("form.playersInvalid"));
|
||||
return;
|
||||
}
|
||||
if (data.screenshotUrl && !isValidImageUrl(data.screenshotUrl)) {
|
||||
if (screenshotError) {
|
||||
screenshotError.textContent = t("form.screenshotInvalid");
|
||||
screenshotError.classList.remove("hidden");
|
||||
}
|
||||
screenshotInput?.classList.add("input-error");
|
||||
return;
|
||||
}
|
||||
screenshotInput?.classList.remove("input-error");
|
||||
if (!data.name?.trim()) return toast(t("toast.nameRequired"), true);
|
||||
try {
|
||||
await onSubmit(data, close, submitBtn);
|
||||
@@ -1016,36 +1004,6 @@ function openDeleteConfirmModal(s) {
|
||||
document.body.appendChild(overlay);
|
||||
}
|
||||
|
||||
function isValidImageUrl(url) {
|
||||
if (!url) return true;
|
||||
try {
|
||||
const u = new URL(url);
|
||||
const allowed = ["http:", "https:"];
|
||||
if (!allowed.includes(u.protocol)) return false;
|
||||
const host = u.hostname.toLowerCase();
|
||||
const bannedHosts = [
|
||||
"bit.ly",
|
||||
"tinyurl.com",
|
||||
"t.co",
|
||||
"goo.gl",
|
||||
"ow.ly",
|
||||
"is.gd",
|
||||
"buff.ly",
|
||||
"rebrand.ly",
|
||||
"steamcommunity.com",
|
||||
"store.steampowered.com",
|
||||
];
|
||||
if (bannedHosts.some((h) => host === h)) return false;
|
||||
if (host === "imgur.com" && !u.pathname.startsWith("/a/") && !u.pathname.startsWith("/gallery/")) return false;
|
||||
const path = u.pathname.toLowerCase();
|
||||
return [".png", ".jpg", ".jpeg", ".gif", ".webp", ".avif"].some((ext) =>
|
||||
path.endsWith(ext),
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function linkRootId(s) {
|
||||
return s?.parentSuggestionId ?? s?.id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user