Skip to content

Commit f6fe020

Browse files
authored
Merge pull request #305 from Lissy93/feat/small-improvments
Small improvments
2 parents dec03cb + 23c6b62 commit f6fe020

19 files changed

Lines changed: 153 additions & 165 deletions

api/carbon.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,23 @@ const log = createLogger('carbon');
77
const TIMEOUT = 8000;
88
const MAX_BYTES = 10 * 1024 * 1024;
99

10-
// Sustainable Web Design model v3 constants, matches websitecarbon.com formula
11-
const KWH_PER_GB = 0.81;
10+
// Sustainable Web Design model v4 constants, matches websitecarbon.com formula
11+
const KWH_PER_GB = 0.3;
1212
const FIRST_VISIT = 0.25;
1313
const RETURN_VISIT = 0.75;
1414
const RETURN_DATA_PCT = 0.02;
15-
const GRID_INTENSITY = 442;
15+
const GRID_INTENSITY = 494;
1616
const RENEWABLE_INTENSITY = 50;
1717
const LITRES_PER_GRAM = 0.5562;
1818

19-
// Reference median grams CO2 per visit, drawn from websitecarbon's published average.
20-
// Used to estimate a percentile rank since we lack their measured-sites dataset
21-
const REFERENCE_MEDIAN_GRAMS = 0.8;
19+
// Median CO2 for an HTML-only fetch at HTTP Archive's ~30 KB median
20+
const REFERENCE_MEDIAN_GRAMS = 0.001;
2221

23-
// Approximate percentile via log2 distance from the reference median.
24-
// 1 doubling above median drops 25 points; clamp to [1, 99]
22+
// Percentile rank via log2 distance from the median, clamped to [1, 95]
2523
const estimateCleanerThan = (grams) => {
2624
if (!grams || grams <= 0) return 0;
27-
const pct = 50 - 25 * Math.log2(grams / REFERENCE_MEDIAN_GRAMS);
28-
return Math.max(1, Math.min(99, Math.round(pct)));
25+
const pct = 50 - 15 * Math.log2(grams / REFERENCE_MEDIAN_GRAMS);
26+
return Math.max(1, Math.min(95, Math.round(pct)));
2927
};
3028

3129
// Stream the response, cap at MAX_BYTES so huge pages can't blow memory or time

api/rank.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@ import { parseTarget } from './_common/parse-target.js';
44
import { upstreamError } from './_common/upstream.js';
55

66
const rankHandler = async (url) => {
7-
const { hostname: domain } = parseTarget(url);
7+
const { hostname } = parseTarget(url);
88
const { TRANCO_USERNAME, TRANCO_API_KEY } = process.env;
99
const auth = TRANCO_API_KEY
1010
? { auth: { username: TRANCO_USERNAME, password: TRANCO_API_KEY } }
1111
: {};
12+
const fallback = hostname.startsWith('www.') ? hostname.slice(4) : `www.${hostname}`;
13+
// Tranco indexes only one variant per site, so try as-is, then toggle www
14+
const lookup = (domain) => httpGet(`https://tranco-list.eu/api/ranks/domain/${domain}`, auth);
1215
try {
13-
const response = await httpGet(`https://tranco-list.eu/api/ranks/domain/${domain}`, auth);
14-
if (!response.data?.ranks?.length) {
15-
return {
16-
skipped: `${domain} isn't ranked in the top 1 million sites yet`,
17-
};
16+
const first = await lookup(hostname);
17+
if (first.data?.ranks?.length) return first.data;
18+
try {
19+
const second = await lookup(fallback);
20+
if (second.data?.ranks?.length) return second.data;
21+
} catch {
22+
// Ignore fallback failures (e.g. rate limit) and accept the empty first result
1823
}
19-
return response.data;
24+
return { skipped: `${hostname} isn't ranked in the top 1 million sites yet` };
2025
} catch (error) {
2126
return upstreamError(error, 'Tranco rank lookup');
2227
}

api/subdomains.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,15 @@ const subdomainsHandler = async (url) => {
4545
params: { q: `%.${domain}`, output: 'json' },
4646
headers: { Accept: 'application/json' },
4747
});
48-
const rows = Array.isArray(res.data) ? res.data : [];
49-
const all = collectSubdomains(rows, domain);
48+
if (!Array.isArray(res.data)) {
49+
return { error: 'Certificate Transparency lookup returned unexpected data, please retry' };
50+
}
51+
const all = collectSubdomains(res.data, domain);
5052
if (!all.length) {
51-
return { skipped: `No subdomains found for ${domain} in Certificate Transparency logs` };
53+
return {
54+
skipped: `No subdomains found for ${domain} in Certificate Transparency logs`,
55+
retryable: true,
56+
};
5257
}
5358
return {
5459
domain,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"typecheck": "astro check",
1818
"lint": "eslint --config .config/eslint.config.js .",
1919
"format:check": "prettier --check --ignore-unknown '!yarn.lock' '!**/*.md' .",
20-
"format:fix": "prettier --write --ignore-unknown '!yarn.lock' '!**/*.md' ."
20+
"format:fix": "prettier --write --ignore-unknown '!yarn.lock' '!**/*.md' .",
21+
"hold-my-beer": "yarn format:fix && yarn lint && yarn typecheck"
2122
},
2223
"dependencies": {
2324
"@astrojs/check": "^0.9.9",

public/android-chrome-192x192.png

-17 KB
Loading

public/android-chrome-512x512.png

-15.7 KB
Loading

public/apple-touch-icon.png

-16.8 KB
Loading

public/favicon-16x16.png

-569 Bytes
Loading

public/favicon-32x32.png

-1.68 KB
Loading

public/manifest.json

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,45 @@
11
{
2+
"name": "Web Check",
23
"short_name": "Web Check",
3-
"name": "Lissy93/Web-Check",
4+
"description": "Web Check is the all-in-one OSINT and security tool, for revealing the inner workings of any website",
5+
"id": "/",
6+
"start_url": "/",
7+
"scope": "/",
8+
"display": "standalone",
9+
"theme_color": "#d6fb41",
10+
"background_color": "#111211",
411
"icons": [
512
{
6-
"src": "favicon.ico",
7-
"sizes": "64x64 32x32 24x24 16x16",
8-
"type": "image/x-icon"
13+
"src": "/favicon.svg",
14+
"type": "image/svg+xml",
15+
"sizes": "any"
16+
},
17+
{
18+
"src": "/favicon-16x16.png",
19+
"type": "image/png",
20+
"sizes": "16x16"
21+
},
22+
{
23+
"src": "/favicon-32x32.png",
24+
"type": "image/png",
25+
"sizes": "32x32"
926
},
1027
{
11-
"src": "apple-touch-icon.png",
28+
"src": "/apple-touch-icon.png",
1229
"type": "image/png",
1330
"sizes": "180x180"
31+
},
32+
{
33+
"src": "/android-chrome-192x192.png",
34+
"type": "image/png",
35+
"sizes": "192x192",
36+
"purpose": "any"
37+
},
38+
{
39+
"src": "/android-chrome-512x512.png",
40+
"type": "image/png",
41+
"sizes": "512x512",
42+
"purpose": "any"
1443
}
15-
],
16-
"start_url": ".",
17-
"display": "standalone",
18-
"theme_color": "#9fef00",
19-
"background_color": "#141d2b"
44+
]
2045
}

0 commit comments

Comments
 (0)