Commit 9a4749b587

9a4749b587b0c61cd4462c16bcabaf5b7d4f2505

parent: 660a1b8ac9

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-08-09 10:21 UTC

Fefactored fetching for logic

Layout: unified · split

web/.env.sample +1 −1
@@ -19,7 +19,7 @@ SITE_URL=''
1919PUBLIC_API_URL='https://api.awesome-privacy.xyz'
2020
2121# Bearer token for the API's enrichment routes (/v1/enrich/*).
22# Only needed at build-time, and only if the target API has auth enabled.
22# For build-time. Anon-callers be rate limited to 10 req/sec
2323API_TOKEN=''
2424
2525# GitHub API key (with pub repo read perms).
web/src/components/things/DataActions.svelte +3 −3
@@ -31,8 +31,8 @@
3131 source,
3232 }: Props = $props();
3333
34 const lineNumbers = source?.lineNumbers;
35 const yamlContent = source?.yaml ?? '';
34 const lineNumbers = $derived(source?.lineNumbers);
35 const yamlContent = $derived(source?.yaml ?? '');
3636
3737 const getGitHubSrcFile = () => {
3838 if (lineNumbers) {
@@ -55,7 +55,7 @@
5555{#if history.length > 0}
5656 <h4>Change History</h4>
5757 <ul class="history">
58 {#each history as h}
58 {#each history as h (h)}
5959 <li>
6060 <span class="history-badge {h.type}">
6161 {h.type === 'added'
web/src/components/things/DeleteListing.svelte +7 −5
@@ -14,11 +14,13 @@
1414 const apYaml =
1515 'https://github.com/lissy93/awesome-privacy/blob/main/awesome-privacy.yml';
1616
17 const yamlContent = source?.yaml ?? '';
18 const lineNumbers = source?.lineNumbers;
19 const editLink = lineNumbers
20 ? `${apYaml}#L${lineNumbers.start}-L${lineNumbers.end}`
21 : apYaml;
17 const yamlContent = $derived(source?.yaml ?? '');
18 const lineNumbers = $derived(source?.lineNumbers);
19 const editLink = $derived(
20 lineNumbers
21 ? `${apYaml}#L${lineNumbers.start}-L${lineNumbers.end}`
22 : apYaml,
23 );
2224</script>
2325
2426<div class="actions">
web/src/components/things/DiscordDetailedInfo.astro +3 −1
@@ -50,7 +50,9 @@ const { discordData } = Astro.props;
5050 class="banner"
5151 width="300"
5252 src={discordData.banner}
53 alt={`${discordData.name} banner`} loading="lazy" />
53 alt={`${discordData.name} banner`}
54 loading="lazy"
55 />
5456 )
5557 }
5658</div>
web/src/components/things/DockerDetailedInfo.astro +20 −22
@@ -1,5 +1,5 @@
11---
2import type { TemplateResponse } from '@utils/fetch-docker-instructions';
2import { dockerHubUrl, type TemplateResponse } from '@utils/fetch-docker-instructions';
33import { formatDate, timeAgo } from '@utils/dates-n-stuff';
44
55interface Props {
@@ -13,6 +13,10 @@ const formatBigNumber = (num: number): string => {
1313 return num.toLocaleString();
1414};
1515
16const { user, name } = docker.dockerHubData || {};
17const imageRef =
18 user && name ? `${user}/${name}` : docker.template?.image || null;
19const imageUrl = imageRef && dockerHubUrl(imageRef);
1620---
1721
1822<div class="docker-info-wrap">
@@ -54,24 +58,11 @@ const formatBigNumber = (num: number): string => {
5458 </ul>
5559 )}
5660
57 {docker.dockerHubData && (
61 {imageUrl && (
5862 <h4>View on DockerHub</h4>
63 <a href={imageUrl} target="_blank" rel="noreferrer">{imageRef}</a>
5964 )}
60
61 {docker.dockerHubData && Object.keys(docker.dockerHubData).length > 0 && (
62 <a href={`https://hub.docker.com/r/${docker.dockerHubData.user}/${docker.dockerHubData.name}`} target="_blank">
63 {docker.dockerHubData.user}/{docker.dockerHubData.name}
64 </a>
65 )}
66
67 {!docker.dockerHubData && docker.template &&
68 (
69 <a href={`https://hub.docker.com/r/${docker.template.image}`} target="_blank">
70 {docker.template.image}
71 </a>
72 )
73 }
74
65
7566 </div>
7667 <div class="right">
7768 {docker.usage && docker.usage.dockerRunCommand && (
@@ -110,11 +101,15 @@ const formatBigNumber = (num: number): string => {
110101
111102 {docker.template && docker.template.volumes && (
112103 <h4>Volume Mounting</h4>
113 <ul class="table">
104 <ul class="table wide">
105 <li class="header">
106 <span class="lbl">Container Path</span>
107 <span class="val">Host Bind</span>
108 </li>
114109 {docker.template.volumes.map((volume) => (
115110 <li>
116 <span class="lbl">{volume.bind}</span>
117 <span class="val">{volume.container || '(any)'}</span>
111 <span class="lbl">{volume.container}</span>
112 <span class="val">{volume.bind || '(anonymous)'}</span>
118113 </li>
119114 ))}
120115 </ul>
@@ -123,10 +118,10 @@ const formatBigNumber = (num: number): string => {
123118 {docker.dockerHubData && docker.dockerHubData.permissions && (
124119 <h4>Permissions</h4>
125120 <ul class="table">
126 {Object.keys(docker.dockerHubData.permissions).map((perm) => (
121 {Object.entries(docker.dockerHubData.permissions).map(([perm, granted]) => (
127122 <li>
128123 <span class="lbl">{perm}</span>
129 <span class="val">{perm ? '✅ Yes' : '❎ No'}</span>
124 <span class="val">{granted ? '✅ Yes' : '❎ No'}</span>
130125 </li>
131126 ))}
132127 </ul>
@@ -166,6 +161,9 @@ const formatBigNumber = (num: number): string => {
166161 .table {
167162 max-width: 15rem;
168163 padding-left: 0;
164 &.wide {
165 max-width: none;
166 }
169167 li {
170168 display: flex;
171169 justify-content: space-between;
web/src/components/things/GitHubDetailedInfo.astro +2 −4
@@ -282,10 +282,8 @@ const languageChart = `https://quickchart.io/chart?c=${generateChartData(gitHubD
282282 }
283283 }
284284
285 .list-table {
286 li .val a :global(svg) {
287 width: 1rem;
288 }
285 .list-table li .val a :global(svg) {
286 width: 1rem;
289287 }
290288
291289 @include detail-info-base;
web/src/components/things/ItemGitHubMetrics.astro +1 −1
@@ -137,7 +137,7 @@ const metrics = await getMetrics(github);
137137 }
138138 }
139139 :global(svg) {
140 color: var(--foregroung);
140 color: var(--foreground);
141141 width: var(--text-md);
142142 height: var(--text-md);
143143 }
web/src/components/things/RedditDetailedInfo.astro +3 −1
@@ -23,7 +23,9 @@ const { redditData } = Astro.props;
2323 class="banner"
2424 width="300"
2525 src={redditData.info.banner}
26 alt="Banner" loading="lazy" />
26 alt="Banner"
27 loading="lazy"
28 />
2729 )
2830 }
2931 <ul class="list-table">
web/src/pages/about.astro +26 −6
@@ -138,7 +138,13 @@ const licenseContent = async () => {
138138 target="_blank"
139139 rel="noreferrer"
140140 >
141 <img src={sponsor.avatarUrl} alt={sponsor.login || ""} width="80" height="80" loading="lazy" />
141 <img
142 src={sponsor.avatarUrl}
143 alt={sponsor.login || ''}
144 width="80"
145 height="80"
146 loading="lazy"
147 />
142148 <p>{sponsor.name || sponsor.login}</p>
143149 </a>
144150 ))}
@@ -147,7 +153,9 @@ const licenseContent = async () => {
147153 <img
148154 class="fallback-img"
149155 src="https://readme-contribs.as93.net/sponsors/lissy93?perRow=12&shape=squircle&textColor=ffffff&limit=96"
150 alt="Sponsors" loading="lazy" />
156 alt="Sponsors"
157 loading="lazy"
158 />
151159 )
152160 }
153161
@@ -167,7 +175,13 @@ const licenseContent = async () => {
167175 target="_blank"
168176 rel="noreferrer"
169177 >
170 <img src={contributor.avatar_url} alt={contributor.login || ""} width="80" height="80" loading="lazy" />
178 <img
179 src={contributor.avatar_url}
180 alt={contributor.login || ''}
181 width="80"
182 height="80"
183 loading="lazy"
184 />
171185 <p>{contributor.login}</p>
172186 </a>
173187 ))}
@@ -176,7 +190,9 @@ const licenseContent = async () => {
176190 <img
177191 class="fallback-img"
178192 src="https://readme-contribs.as93.net/contributors/lissy93/awesome-privacy?perRow=12&shape=squircle&textColor=ffffff&limit=96"
179 alt="Contributors" loading="lazy" />
193 alt="Contributors"
194 loading="lazy"
195 />
180196 )
181197 }
182198
@@ -234,7 +250,9 @@ const licenseContent = async () => {
234250 width="180"
235251 height="240"
236252 alt="Alicia Sykes"
237 src="https://cdn.as93.net/profile-pictures/dsc_0597" loading="lazy" />
253 src="https://cdn.as93.net/profile-pictures/dsc_0597"
254 loading="lazy"
255 />
238256 </a>
239257 <div class="socials">
240258 {
@@ -271,7 +289,9 @@ const licenseContent = async () => {
271289 width="20"
272290 height="20"
273291 alt={project.title}
274 src={project.icon} loading="lazy" />
292 src={project.icon}
293 loading="lazy"
294 />
275295 <a href={project.link} target="_blank" rel="noreferrer">
276296 {project.title}
277297 </a>{' '}
web/src/utils/fetch-android-info.ts +8 −22
@@ -1,30 +1,16 @@
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
1import { fetchEnrich } from './fetch-enrich';
42
53const extractPackage = (str: string): string =>
64 str.includes('id=') ? str.split('id=')[1] : str;
75
8export const fetchAndroidInfo = async (
6export const fetchAndroidInfo = (
97 androidPackage: string,
10): Promise<AndroidInfo | null> => {
11 const pkg = extractPackage(androidPackage);
12 const endpoint = `${apiBase}/v1/enrich/android/${pkg}`;
13 try {
14 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
15 if (!res.ok) {
16 error(
17 'Android',
18 `HTTP ${res.status} for ${androidPackage} (${endpoint})`,
19 );
20 return null;
21 }
22 return await res.json();
23 } catch (err) {
24 error('Android', `Network error for ${androidPackage}: ${err}`);
25 return null;
26 }
27};
8): Promise<AndroidInfo | null> =>
9 fetchEnrich<AndroidInfo>(
10 'Android',
11 `/v1/enrich/android/${extractPackage(androidPackage)}`,
12 androidPackage,
13 );
2814
2915interface Tracker {
3016 id: number;
web/src/utils/fetch-discord-info.ts +8 −18
@@ -1,23 +1,13 @@
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
1import { fetchEnrich } from './fetch-enrich';
42
5export const fetchDiscordInfo = async (
3export const fetchDiscordInfo = (
64 discordInvite: string,
7): Promise<DiscordInfo | null> => {
8 const endpoint = `${apiBase}/v1/enrich/discord/${discordInvite}`;
9 try {
10 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
11 if (!res.ok) {
12 error('Discord', `HTTP ${res.status} for ${discordInvite} (${endpoint})`);
13 return null;
14 }
15 return await res.json();
16 } catch (err) {
17 error('Discord', `Network error for ${discordInvite}: ${err}`);
18 return null;
19 }
20};
5): Promise<DiscordInfo | null> =>
6 fetchEnrich<DiscordInfo>(
7 'Discord',
8 `/v1/enrich/discord/${discordInvite}`,
9 discordInvite,
10 );
2111
2212export interface DiscordInfo {
2313 inviteCode: string;
web/src/utils/fetch-docker-instructions.ts +27 −29
@@ -1,29 +1,27 @@
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
1import { fetchEnrich } from './fetch-enrich';
42
5export const fetchDockerData = async (
3export const fetchDockerData = (
64 serviceName: string,
7): Promise<TemplateResponse | null> => {
8 const endpoint = `${apiBase}/v1/enrich/docker/${encodeURIComponent(serviceName)}`;
9 try {
10 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
11 if (!res.ok) {
12 error('Docker', `HTTP ${res.status} for ${serviceName} (${endpoint})`);
13 return null;
14 }
15 return await res.json();
16 } catch (err) {
17 error('Docker', `Network error for ${serviceName}: ${err}`);
18 return null;
19 }
20};
5): Promise<TemplateResponse | null> =>
6 fetchEnrich<TemplateResponse>(
7 'Docker',
8 `/v1/enrich/docker/${encodeURIComponent(serviceName)}`,
9 serviceName,
10 { missingIsExpected: true },
11 );
2112
22interface DockerTemplatePort {
23 privatePort: number;
24 publicPort: number;
25 type: string; // Typically TCP/UDP
26}
13export const dockerHubUrl = (image: string): string | null => {
14 const segments = image.split('/');
15 if (segments.length > 1 && /[.:]/.test(segments[0])) return null;
16 const path = image.replace(/:[^/]*$/, '');
17 const [namespace, repo] = path.includes('/')
18 ? path.split('/')
19 : ['library', path];
20 if (!repo) return null;
21 return namespace === 'library'
22 ? `https://hub.docker.com/_/${repo}`
23 : `https://hub.docker.com/r/${namespace}/${repo}`;
24};
2725
2826interface DockerTemplateEnvironmentVariable {
2927 name: string;
@@ -33,22 +31,22 @@ interface DockerTemplateEnvironmentVariable {
3331}
3432
3533interface DockerTemplateVolume {
36 bind: string;
3734 container: string;
35 bind?: string;
3836 readonly?: boolean;
3937}
4038
4139interface DockerTemplate {
4240 name?: string;
43 title: string;
41 title?: string;
4442 description?: string;
4543 logo?: string;
46 image: string;
44 image?: string;
4745 categories?: string[];
48 ports?: DockerTemplatePort[];
46 ports?: string[];
4947 env?: DockerTemplateEnvironmentVariable[];
5048 volumes?: DockerTemplateVolume[];
51 restart_policy?: string; // Typically "no", "always", "unless-stopped", "on-failure"
49 restart_policy?: string;
5250}
5351
5452interface DockerHubData {
@@ -82,6 +80,6 @@ export interface TemplateResponse {
8280 found: boolean;
8381 error: string | null;
8482 template?: DockerTemplate;
85 dockerHubData?: DockerHubData;
83 dockerHubData?: DockerHubData | null;
8684 usage?: DockerUsage;
8785}
web/src/utils/fetch-enrich.ts added +30
@@ -0,0 +1,30 @@
1import { error, warn } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
4
5interface EnrichOptions {
6 // Yeah, it's legit got no upstream record, so 404 is correct/expected
7 missingIsExpected?: boolean;
8}
9
10export const fetchEnrich = async <T>(
11 source: string,
12 path: string,
13 subject: string,
14 { missingIsExpected = false }: EnrichOptions = {},
15): Promise<T | null> => {
16 const endpoint = `${apiBase}${path}`;
17 try {
18 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
19 if (res.ok) return (await res.json()) as T;
20 if (res.status !== 404) {
21 error(source, `HTTP ${res.status} for ${subject} (${endpoint})`);
22 } else if (!missingIsExpected) {
23 warn(source, `No upstream record for ${subject} (${endpoint})`);
24 }
25 return null;
26 } catch (err) {
27 error(source, `Network error for ${subject}: ${err}`);
28 return null;
29 }
30};
web/src/utils/fetch-ios-info.ts +7 −19
@@ -1,6 +1,4 @@
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
1import { fetchEnrich } from './fetch-enrich';
42
53// Pull the id from an App Store URL's `/id123` segment, else pass it through.
64const extractId = (iosUrl: string): string => {
@@ -8,22 +6,12 @@ const extractId = (iosUrl: string): string => {
86 return match ? match[1] : iosUrl;
97};
108
11export const fetchIosInfo = async (
12 iosUrl: string,
13): Promise<IoSApiResponse | null> => {
14 const endpoint = `${apiBase}/v1/enrich/ios/${extractId(iosUrl)}`;
15 try {
16 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
17 if (!res.ok) {
18 error('iOS', `HTTP ${res.status} for ${iosUrl} (${endpoint})`);
19 return null;
20 }
21 return await res.json();
22 } catch (err) {
23 error('iOS', `Network error for ${iosUrl}: ${err}`);
24 return null;
25 }
26};
9export const fetchIosInfo = (iosUrl: string): Promise<IoSApiResponse | null> =>
10 fetchEnrich<IoSApiResponse>(
11 'iOS',
12 `/v1/enrich/ios/${extractId(iosUrl)}`,
13 iosUrl,
14 );
2715
2816export interface IoSApiResponse {
2917 artistViewUrl: string;
web/src/utils/fetch-privacy-policy.ts +7 −18
@@ -1,26 +1,15 @@
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
1import { fetchEnrich } from './fetch-enrich';
42
53// Wrap the flat ToS;DR v3 record in the shape the app already consumes.
64export const fetchTosdrPrivacy = async (
75 serviceId: string,
86): Promise<PrivacyPolicyResponse | null> => {
9 const endpoint = `${apiBase}/v1/enrich/privacy/${serviceId}`;
10 try {
11 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
12 if (!res.ok) {
13 error(
14 'ToS;DR',
15 `HTTP ${res.status} for service ${serviceId} (${endpoint})`,
16 );
17 return null;
18 }
19 return { error: 0, message: '', parameters: await res.json() };
20 } catch (err) {
21 error('ToS;DR', `Network error for service ${serviceId}: ${err}`);
22 return null;
23 }
7 const parameters = await fetchEnrich<Params>(
8 'ToS;DR',
9 `/v1/enrich/privacy/${serviceId}`,
10 `service ${serviceId}`,
11 );
12 return parameters && { error: 0, message: '', parameters };
2413};
2514
2615interface Document {
web/src/utils/fetch-reddit-info.ts +8 −18
@@ -1,23 +1,13 @@
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
1import { fetchEnrich } from './fetch-enrich';
42
5export const fetchRedditInfo = async (
3export const fetchRedditInfo = (
64 subreddit: string,
7): Promise<RedditData | null> => {
8 const endpoint = `${apiBase}/v1/enrich/reddit/${subreddit}`;
9 try {
10 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
11 if (!res.ok) {
12 error('Reddit', `HTTP ${res.status} for r/${subreddit} (${endpoint})`);
13 return null;
14 }
15 return await res.json();
16 } catch (err) {
17 error('Reddit', `Network error for r/${subreddit}: ${err}`);
18 return null;
19 }
20};
5): Promise<RedditData | null> =>
6 fetchEnrich<RedditData>(
7 'Reddit',
8 `/v1/enrich/reddit/${subreddit}`,
9 `r/${subreddit}`,
10 );
2111
2212interface SubredditInfo {
2313 name: string | null;
web/src/utils/fetch-repo-info.ts +7 −16
@@ -1,26 +1,17 @@
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
1import { fetchEnrich } from './fetch-enrich';
42
53const normalizeRepo = (github: string): string =>
64 github.replace(/^https?:\/\/github\.com\//, '').replace(/\/+$/, '');
75
8export const fetchGitHubStats = async (
6export const fetchGitHubStats = (
97 github: string,
108): Promise<GitHubStatsResponse | null> => {
119 const repo = normalizeRepo(github);
12 const endpoint = `${apiBase}/v1/enrich/github/${repo}`;
13 try {
14 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
15 if (!res.ok) {
16 error('GitHub Stats', `HTTP ${res.status} for ${repo} (${endpoint})`);
17 return null;
18 }
19 return await res.json();
20 } catch (err) {
21 error('GitHub Stats', `Network error for ${repo}: ${err}`);
22 return null;
23 }
10 return fetchEnrich<GitHubStatsResponse>(
11 'GitHub Stats',
12 `/v1/enrich/github/${repo}`,
13 repo,
14 );
2415};
2516
2617export interface GitHubStatsResponse {
web/src/utils/fetch-security-info.ts +7 −16
@@ -1,26 +1,17 @@
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
1import { fetchEnrich } from './fetch-enrich';
42
53const normalizeRepo = (github: string): string =>
64 github.replace(/^https?:\/\/github\.com\//, '').replace(/\/+$/, '');
75
8export const fetchSecurityReport = async (
6export const fetchSecurityReport = (
97 github: string,
108): Promise<SecurityReportResponse | null> => {
119 const repo = normalizeRepo(github);
12 const endpoint = `${apiBase}/v1/enrich/security/${repo}`;
13 try {
14 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
15 if (!res.ok) {
16 error('Security Report', `HTTP ${res.status} for ${repo} (${endpoint})`);
17 return null;
18 }
19 return await res.json();
20 } catch (err) {
21 error('Security Report', `Network error for ${repo}: ${err}`);
22 return null;
23 }
10 return fetchEnrich<SecurityReportResponse>(
11 'Security Report',
12 `/v1/enrich/security/${repo}`,
13 repo,
14 );
2415};
2516
2617export interface SecurityCheck {
web/src/utils/fetch-website-info.ts +8 −20
@@ -1,23 +1,11 @@
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
4
5export const fetchWebsiteInfo = async (
6 url: string,
7): Promise<WebsiteData | null> => {
8 const endpoint = `${apiBase}/v1/enrich/website?url=${encodeURIComponent(url)}`;
9 try {
10 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
11 if (!res.ok) {
12 error('Website', `HTTP ${res.status} for ${url} (${endpoint})`);
13 return null;
14 }
15 return await res.json();
16 } catch (err) {
17 error('Website', `Network error for ${url}: ${err}`);
18 return null;
19 }
20};
1import { fetchEnrich } from './fetch-enrich';
2
3export const fetchWebsiteInfo = (url: string): Promise<WebsiteData | null> =>
4 fetchEnrich<WebsiteData>(
5 'Website',
6 `/v1/enrich/website?url=${encodeURIComponent(url)}`,
7 url,
8 );
219
2210interface DNSRecord {
2311 target: string;
web/src/utils/logger.ts +26 −22
@@ -6,7 +6,15 @@ interface LogEntry {
66 message: string;
77}
88
9const entries: LogEntry[] = [];
9// Astro loads the config and the bundled page code as separate instances of
10// this module, so the entries have to live somewhere both of them can see
11const store = globalThis as typeof globalThis & { buildFetchLog?: LogEntry[] };
12const entries = (store.buildFetchLog ??= []);
13
14const MAX_SHOWN_PER_SOURCE = 5;
15
16const plural = (count: number, noun: string) =>
17 `${count} ${noun}${count === 1 ? '' : 's'}`;
1018
1119export const warn = (source: string, message: string) => {
1220 console.warn(`[${source}] ${message}`);
@@ -19,33 +27,29 @@ export const error = (source: string, message: string) => {
1927};
2028
2129export const printSummary = () => {
22 if (entries.length === 0) return;
30 if (!entries.length) return;
2331
24 const grouped: Record<
25 string,
26 { errors: number; warnings: number; messages: string[] }
27 > = {};
32 const grouped = new Map<string, LogEntry[]>();
2833 for (const entry of entries) {
29 if (!grouped[entry.source]) {
30 grouped[entry.source] = { errors: 0, warnings: 0, messages: [] };
31 }
32 const group = grouped[entry.source];
33 if (entry.level === 'error') group.errors++;
34 else group.warnings++;
35 group.messages.push(` ${entry.level.toUpperCase()}: ${entry.message}`);
34 const group = grouped.get(entry.source);
35 if (group) group.push(entry);
36 else grouped.set(entry.source, [entry]);
3637 }
3738
3839 console.log('\n───────────── Build fetch summary ──────────────');
39 for (const [source, { errors, warnings, messages }] of Object.entries(
40 grouped,
41 )) {
42 const parts = [];
43 if (errors) parts.push(`${errors} error${errors > 1 ? 's' : ''}`);
44 if (warnings) parts.push(`${warnings} warning${warnings > 1 ? 's' : ''}`);
45 console.log(`[${source}] ${parts.join(', ')}`);
46 for (const msg of messages) {
47 console.log(msg);
40 for (const [source, group] of grouped) {
41 const errors = group.filter((entry) => entry.level === 'error').length;
42 const warnings = group.length - errors;
43 const tally = [
44 ...(errors ? [plural(errors, 'error')] : []),
45 ...(warnings ? [plural(warnings, 'warning')] : []),
46 ];
47 console.log(`[${source}] ${tally.join(', ')}`);
48 for (const { level, message } of group.slice(0, MAX_SHOWN_PER_SOURCE)) {
49 console.log(` ${level.toUpperCase()}: ${message}`);
4850 }
51 const hidden = group.length - MAX_SHOWN_PER_SOURCE;
52 if (hidden > 0) console.log(` ...and ${hidden} more`);
4953 }
5054 console.log('────────────────────────────────────────────────\n');
5155