text

Share:

 

export const config = { runtime: 'edge', }; export default async function handler(req) { const testFileUrl = 'https://speed.hetzner.de/1MB.bin'; // arquivo de teste (~1MB) const start = performance.now(); const response = await fetch(testFileUrl); const data = await response.arrayBuffer(); const end = performance.now(); const durationInSeconds = (end - start) / 1000; const fileSizeInBits = data.byteLength * 8; const speedMbps = (fileSizeInBits / durationInSeconds) / 1_000_000; return new Response( JSON.stringify({ speedMbps: speedMbps.toFixed(2), durationInSeconds: durationInSeconds.toFixed(2), fileSizeMB: (data.byteLength / 1024 / 1024).toFixed(2) }), { headers: { 'Content-Type': 'application/json' } } ); }

Nenhum comentário