-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhosting-page.js
More file actions
9 lines (9 loc) · 4.29 KB
/
Copy pathhosting-page.js
File metadata and controls
9 lines (9 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
function flash(e,o){const n=document.getElementById("flash-container"),t=document.createElement("div");t.className="flash flash-"+o,t.textContent=e,n.appendChild(t),setTimeout(()=>{t.style.opacity="0",t.style.transition="opacity 0.3s",setTimeout(()=>t.remove(),300)},5e3)}function switchTab(e){document.querySelectorAll(".tab-content").forEach(o=>o.classList.add("hidden")),document.querySelectorAll(".tab-btn").forEach(o=>o.classList.remove("active")),document.getElementById("tab-"+e).classList.remove("hidden"),document.querySelector('.tab-btn[onclick*="'+e+'"]').classList.add("active"),e==="providers"&&loadProviders()}async function loadProviders(){const e=document.getElementById("provider-list");e.innerHTML='<p style="color:var(--text)">Loading providers...</p>';try{const n=await(await fetch("/api/hosting/providers")).json();if(!n.providers||n.providers.length===0){e.innerHTML='<p style="color:var(--text)">No providers registered yet.</p>';return}e.innerHTML=n.providers.filter(t=>t.status==="active").map(t=>`
<div class="provider-item">
<div class="info">
<div class="name">${esc(t.org)} <span class="tag tag-active">Active</span></div>
<div class="url"><a href="${safeUrl(t.mirror_url)}" target="_blank" rel="noopener">${esc(t.mirror_url)}</a></div>
<div class="provider-detail">${esc(t.location)} ${t.bandwidth?"\xB7 "+esc(t.bandwidth):""}</div>
</div>
</div>
`).join("")}catch{e.innerHTML='<p style="color:#e74c3c">Failed to load providers.</p>'}}function esc(e){const o=document.createElement("div");return o.textContent=e||"",o.innerHTML}function safeUrl(e){return!e||typeof e!="string"||e.indexOf("javascript:")===0||e.indexOf("data:")===0||e.indexOf("vbscript:")===0?"":e}async function registerProvider(e){e.preventDefault();const o=document.getElementById("register-btn");o.disabled=!0,o.textContent="Submitting...";const n=document.getElementById("email").value,t=document.getElementById("personal-email").checked,a=n.split("@")[1];if(!t&&a&&["gmail.com","yahoo.com","hotmail.com","outlook.com","aol.com","icloud.com","protonmail.com","proton.me","mail.com","zoho.com","yandex.com","gmx.com","tutanota.com","fastmail.com","hey.com","inbox.com","rediffmail.com","live.com","msn.com","ymail.com"].includes(a.toLowerCase())){flash(`Please use an organization email or check "I don't have an organization email"`,"error"),o.disabled=!1,o.textContent="Submit Registration";return}const r={org:document.getElementById("org").value,email:n,personal_email:t,website:document.getElementById("website").value,password:document.getElementById("password").value,mirror_url:document.getElementById("mirror-url").value,location:document.getElementById("location").value,bandwidth:document.getElementById("bandwidth").value,notes:document.getElementById("notes").value,discord_user_id:document.getElementById("discord-user-id").value,subscribe:document.getElementById("subscribe").checked};try{window.getRecaptchaToken&&(r.recaptchaToken=await window.getRecaptchaToken("hosting_register"));const i=await fetch("/api/hosting/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}),s=await i.json();i.ok?(flash("Registration submitted! We will review and add you shortly.","success"),document.getElementById("register-form").reset()):flash(s.error||"Registration failed","error")}catch{flash("Network error. Please try again.","error")}o.disabled=!1,o.textContent="Submit Registration"}async function manageListing(e){e.preventDefault();const o=document.getElementById("manage-action").value,n={email:document.getElementById("manage-email").value,password:document.getElementById("manage-password").value,notes:document.getElementById("manage-notes").value};try{window.getRecaptchaToken&&(n.recaptchaToken=await window.getRecaptchaToken("hosting_manage"));const t=await fetch("/api/hosting/"+(o==="remove"?"remove-request":"update-request"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}),a=await t.json();t.ok?(flash(a.message||"Request submitted for admin approval.","success"),document.getElementById("manage-form").reset()):flash(a.error||"Request failed","error")}catch{flash("Network error.","error")}}window.addEventListener("DOMContentLoaded",()=>{new URLSearchParams(window.location.search).get("action")==="providers"&&loadProviders()});