"use strict"; // Where a link that leaves the client goes (launcher/main.cjs wraps shell.openExternal with it). The client's own // ogrines / vote / support / "Create an account" / "Forgot your password?" buttons point at its account API host // (api.khaos.invalid) and Ankama: those go to the Khaosdofus website instead (KHAOS_WEBSITE). Other http(s) links go to the // player's browser as they are; any other scheme is dropped. Tested by client/release/external-url.test.mjs. const API_HOST = "api.khaos.invalid"; const LANGS = new Set(["fr", "en", "es"]); // account API path -> the website's ?account= page const ACCOUNT_PAGES = Object.freeze({ __proto__: null, "/register": "register", "/forgot-password": "forgot" }); /** @param {string} raw @param {string} website the Khaos website, ending with "/" */ function externalUrl(raw, website) { let url; try { url = new URL(raw); } catch { return null; } if (url.protocol !== "https:" && url.protocol !== "http:") return null; const host = url.hostname.toLowerCase(); if (host === API_HOST) { if (url.pathname.startsWith("/ogrines")) return `${website}shop`; if (url.pathname.startsWith("/voter")) return `${website}vote`; // the login screen's account pages (desktop:app:open-account-site, a fixed allowlist in Electron main): // "Create an account" -> the website's registration dialog (server/web static/khaosdofus.js opens it on // ?account=register, client-accounts 2026-10-08); "Forgot your password?" -> the website's password reset // request page (server/web password_reset.go redirects ?account=forgot to /account/forgot, password-reset) const page = ACCOUNT_PAGES[url.pathname]; if (page) { const lang = LANGS.has(url.searchParams.get("lang")) ? url.searchParams.get("lang") : "fr"; return `${website}?account=${page}&lang=${lang}`; } return website; } if (host === "support.ankama.com") return website; return url.href; } module.exports = { API_HOST, externalUrl };