HEX
Server: Apache
System: Linux vpshost11508.publiccloud.com.br 5.15.179-grsec-vpshost-10.lc.el8.x86_64 #1 SMP Mon Apr 7 12:04:45 -03 2025 x86_64
User: wicomm2 (10002)
PHP: 8.3.0
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: /home/storage/5/78/dd/wicomm2/public_html/clientes/performance-healthcheck/app.js
async function api(path, method = "GET", body) {
  const res = await fetch(path, {
    method,
    headers: body ? { "Content-Type": "application/json" } : undefined,
    body: body ? JSON.stringify(body) : undefined
  });
  const data = await res.json().catch(() => ({}));
  if (!res.ok) throw new Error(data.error || "Erro na requisição");
  return data;
}

function qs(name) {
  const u = new URL(window.location.href);
  return u.searchParams.get(name);
}

async function boot() {
  const page = document.body.getAttribute("data-page");

  if (page === "home") {
    const mount = document.getElementById("clients");
    const filter = document.getElementById("filter");
    const data = await api("/api/clients");
    const rows = data.items || [];

    const render = (term) => {
      const t = (term || "").toLowerCase().trim();
      const list = !t ? rows : rows.filter(r =>
        String(r.client_name || "").toLowerCase().includes(t) ||
        String(r.client_url || "").toLowerCase().includes(t) ||
        String(r.client_plataforma || "").toLowerCase().includes(t)
      );

      mount.innerHTML = list.map(r => {
        const name = r.client_name || "";
        const url = r.client_url || "";
        const platform = r.client_plataforma || "";
        return `<tr>
          <td><b>${escapeHtml(name)}</b><div class="muted">${escapeHtml(url)}</div></td>
          <td>${escapeHtml(platform)}</td>
          <td><a class="btn" href="/analisar?id=${encodeURIComponent(r.id)}">Analisar</a></td>
        </tr>`;
      }).join("");
    };

    filter.addEventListener("input", e => render(e.target.value));
    render("");
  }

  if (page === "loading") {
    const id = qs("id");
    const strategy = qs("strategy") || "mobile";
    const status = document.getElementById("status");
    const bar = document.getElementById("bar");

    try {
      status.textContent = "Executando Lighthouse e consolidando dados";
      bar.style.width = "35%";

      const out = await api("/api/run", "POST", { id, strategy });

      status.textContent = "Gerando relatório com IA e salvando histórico";
      bar.style.width = "75%";

      if (out && out.id) {
        bar.style.width = "100%";
        window.location.href = `/relatorio?id=${encodeURIComponent(out.id)}&report_id=${encodeURIComponent(out.report_id)}`;
        return;
      }

      throw new Error("Resposta inválida");
    } catch (e) {
      status.textContent = String(e.message || e);
      bar.style.width = "0%";
    }
  }
}

function escapeHtml(s) {
  return String(s).replace(/[&<>"']/g, m => ({ "&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;" }[m]));
}

document.addEventListener("DOMContentLoaded", boot);