src/core/pipeline.ts (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
import type { Modo, Observations, Report } from './types.js';
import { montarRelatorio } from '../report/model.js';
import { coletarHttp } from '../collectors/http.js';
import { coletarHtml } from '../collectors/html.js';
import { coletarAnatomia } from '../collectors/assets.js';
import { coletarDns } from '../collectors/dns.js';
import { coletarTls } from '../collectors/tls.js';
import { coletarProtocolo } from '../collectors/protocol.js';
import { coletarRobots } from '../collectors/robots.js';
export interface OpcoesAnalise {
modo: Modo;
lighthouse?: boolean;
aoProgredir?: (etapa: string) => void;
}
function novaObservacao(url: string, modo: Modo): Observations {
return {
urlSolicitada: url,
urlFinal: url,
modo,
redirecionamentos: [],
headers: {},
cookies: [],
html: '',
meta: {},
scriptSrc: [],
linksAssets: [],
globaisJs: [],
avisos: [],
};
}
export function normalizarUrl(entrada: string): string {
const t = entrada.trim();
if (/^https?:\/\//i.test(t)) return t;
return `https://${t}`;
}
export async function analisarSite(entrada: string, opcoes: OpcoesAnalise): Promise<Report> {
const url = normalizarUrl(entrada);
const obs = novaObservacao(url, opcoes.modo);
const progresso = opcoes.aoProgredir ?? (() => {});
progresso('buscando a página');
const http = await coletarHttp(url, obs);
if (http) {
coletarHtml(obs);
coletarAnatomia(obs);
}
progresso('inspecionando infraestrutura');
await Promise.all([coletarDns(obs), coletarTls(obs), coletarRobots(obs)]);
coletarProtocolo(obs);
if (opcoes.modo === 'completo') {
progresso('abrindo em navegador headless');
try {
const { coletarBrowser } = await import('../collectors/browser.js');
await coletarBrowser(obs, { lighthouse: opcoes.lighthouse ?? false, progresso });
coletarAnatomia(obs);
} catch (erro) {
obs.avisos.push(`Modo completo indisponível: ${(erro as Error).message}`);
}
}
progresso('montando o relatório');
return montarRelatorio(obs);
}
|