26 lines
865 B
JavaScript
26 lines
865 B
JavaScript
async function fetch_urls (urls) {
|
|
let seq = 1
|
|
for (const url of urls) {
|
|
const startTime = process.hrtime()
|
|
try {
|
|
const res = await fetch(url)
|
|
const { status } = res
|
|
const sizeDownload = res.headers.get('content-length') || 0
|
|
const urlEffective = res.url
|
|
|
|
await res.text() // Consume the response body
|
|
|
|
const [seconds, nanoseconds] = process.hrtime(startTime)
|
|
const timeTotal = seconds + nanoseconds / 1e9
|
|
|
|
console.log(`${seq++}/${urls.length} | ${status} | ${timeTotal.toFixed(3)} s | ${sizeDownload} bytes | ${urlEffective}`)
|
|
} catch (e) {
|
|
console.error(`Error fetching ${url}: ${e.message}`)
|
|
}
|
|
}
|
|
}
|
|
|
|
// example: fetch_urls(['https://u.cn.agidin.com/uni_modules/uni-pay/static/wxpay.png', 'https://u.cn.agidin.com/static/js/pages-user-resource.4a81c0a7.js'])
|
|
|
|
module.exports = fetch_urls
|