From 1d7211488791e28d8ba03e3cd37149de2124b176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20K=C3=B6hring?= Date: Fri, 3 Jan 2025 13:30:18 +0100 Subject: [PATCH] fix: use html, image and video content size for ratio calculation Applied from patch submitted by ~issotm Thanks! --- index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.ts b/index.ts index 339bf2cb..6feecdf2 100644 --- a/index.ts +++ b/index.ts @@ -39,17 +39,19 @@ async function updateRecord(runId: string, url: string): Promise { const now = new Date().toISOString().split("T")[0]; const weight = metrics.metrics.contentLength; - const ratio = Math.round((metrics.metrics.htmlSize / weight) * 100); if (weight > REJECT_THRESHOLD) { console.log(url, "rejected! Weighs", Math.round(weight / 1024), "kb"); if (oldRecord) { + console.log("Removing record at", OUTPUT_PATH) removeRecord(url, OUTPUT_PATH).catch(() => { console.error("Failed to remove old record of rejected url", url); }); } return false; } + const { htmlSize, imageSize, videoSize } = metrics.metrics + const contentSize = htmlSize + imageSize + videoSize const record: PageRecord = { title: url2title(url), @@ -58,7 +60,7 @@ async function updateRecord(runId: string, url: string): Promise { weight, extra: { source: url, - ratio, + ratio: Math.round(contentSize / weight * 100), size: Math.round(weight / 1024), }, };