Commit 66d150419a

66d150419af6adaa3d2aec459fdef39b206e9727

parent: 7cefc93986

Unsigned

Alicia Sykes <alicia@omg.lol> · 2026-04-16 16:33 UTC

Wraps fetch functions in 6-second timeout

Layout: unified · split

web/src/utils/fetch-android-info.ts +2 −1
@@ -1,4 +1,5 @@
11import { error } from './logger';
2import { safeFetch } from './safe-fetch';
23
34const doubleCheckPackageName = (packageStr: string) => {
45 return packageStr.includes('id=') ? packageStr.split('id=')[1] : packageStr;
@@ -9,7 +10,7 @@ export const fetchAndroidInfo = async (
910): Promise<AndroidInfo | null> => {
1011 const endpoint = `https://android-app-privacy.as93.net/${doubleCheckPackageName(androidPackage)}`;
1112 try {
12 const res = await fetch(endpoint);
13 const res = await safeFetch(endpoint);
1314 if (!res.ok) {
1415 error(
1516 'Android',
web/src/utils/fetch-changelog.ts +4 −3
@@ -1,8 +1,9 @@
11import { error } from './logger';
2import { safeFetch } from './safe-fetch';
23
34const changelogUrl =
4 // 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/.github/changelog.json';
5 'https://gist.githubusercontent.com/Lissy93/ddae176f3f21a0d3c0251f5f6cbd3b09/raw/9e62d21ea8866709520331dd2ec6a67494460707/changelog.json';
5 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/.github/changelog.json';
6// 'https://gist.githubusercontent.com/Lissy93/ddae176f3f21a0d3c0251f5f6cbd3b09/raw/9e62d21ea8866709520331dd2ec6a67494460707/changelog.json';
67
78export interface ChangelogPr {
89 number: number;
@@ -74,7 +75,7 @@ export interface Changelog {
7475
7576export const fetchChangelog = async (): Promise<Changelog> => {
7677 try {
77 const res = await fetch(changelogUrl);
78 const res = await safeFetch(changelogUrl);
7879 if (!res.ok) {
7980 error('Changelog', `HTTP ${res.status} fetching changelog.json`);
8081 return { generatedAt: '', entries: [] };
web/src/utils/fetch-data.ts +2 −1
@@ -1,5 +1,6 @@
11import yaml from 'js-yaml';
22import { error } from './logger';
3import { safeFetch } from './safe-fetch';
34
45import type { AwesomePrivacy } from '../types/Service';
56
@@ -8,7 +9,7 @@ const awesomePrivacyData =
89
910export const fetchData = async (): Promise<AwesomePrivacy> => {
1011 try {
11 const res = await fetch(awesomePrivacyData);
12 const res = await safeFetch(awesomePrivacyData, {}, 15000);
1213 if (!res.ok) {
1314 error(
1415 'Data',
web/src/utils/fetch-discord-info.ts +2 −1
@@ -1,11 +1,12 @@
11import { error } from './logger';
2import { safeFetch } from './safe-fetch';
23
34export const fetchDiscordInfo = async (
45 discordInvite: string,
56): Promise<DiscordInfo | null> => {
67 const endpoint = `https://discord-invite-info.as93.net/${discordInvite}`;
78 try {
8 const res = await fetch(endpoint);
9 const res = await safeFetch(endpoint);
910 if (!res.ok) {
1011 error('Discord', `HTTP ${res.status} for ${discordInvite} (${endpoint})`);
1112 return null;
web/src/utils/fetch-docker-instructions.ts +2 −1
@@ -1,11 +1,12 @@
11import { error } from './logger';
2import { safeFetch } from './safe-fetch';
23
34export const fetchDockerData = async (
45 serviceName: string,
56): Promise<TemplateResponse | null> => {
67 const endpoint = `https://docker-info.as93.workers.dev/${serviceName}`;
78 try {
8 const res = await fetch(endpoint);
9 const res = await safeFetch(endpoint);
910 if (!res.ok) {
1011 error('Docker', `HTTP ${res.status} for ${serviceName} (${endpoint})`);
1112 return null;
web/src/utils/fetch-ios-info.ts +2 −1
@@ -1,11 +1,12 @@
11import { error } from './logger';
2import { safeFetch } from './safe-fetch';
23
34export const fetchIosInfo = async (
45 iosUrl: string,
56): Promise<IoSApiResponse | null> => {
67 const endpoint = `https://ios-app-info.as93.net?appStoreUrl=${iosUrl}`;
78 try {
8 const res = await fetch(endpoint);
9 const res = await safeFetch(endpoint);
910 if (!res.ok) {
1011 error('iOS', `HTTP ${res.status} for ${iosUrl} (${endpoint})`);
1112 return null;
web/src/utils/fetch-privacy-policy.ts +2 −1
@@ -1,11 +1,12 @@
11import { error } from './logger';
2import { safeFetch } from './safe-fetch';
23
34export const fetchTosdrPrivacy = async (
45 serviceId: string,
56): Promise<PrivacyPolicyResponse | null> => {
67 const endpoint = `https://privacy-policies.as93.workers.dev/${serviceId}`;
78 try {
8 const res = await fetch(endpoint);
9 const res = await safeFetch(endpoint);
910 if (!res.ok) {
1011 error(
1112 'ToS;DR',
web/src/utils/fetch-reddit-info.ts +2 −1
@@ -1,11 +1,12 @@
11import { error } from './logger';
2import { safeFetch } from './safe-fetch';
23
34export const fetchRedditInfo = async (
45 subreddit: string,
56): Promise<RedditData | null> => {
67 const endpoint = `https://subreddit-info.as93.net/${subreddit}`;
78 try {
8 const res = await fetch(endpoint);
9 const res = await safeFetch(endpoint);
910 if (!res.ok) {
1011 error('Reddit', `HTTP ${res.status} for r/${subreddit} (${endpoint})`);
1112 return null;
web/src/utils/fetch-repo-info.ts +7 −6
@@ -1,4 +1,5 @@
11import { error } from './logger';
2import { safeFetch } from './safe-fetch';
23
34const githubHeaders = (): Record<string, string> => {
45 const headers: Record<string, string> = {
@@ -18,11 +19,11 @@ const fetchFromGitHub = async (
1819
1920 const [infoRes, langsRes, tagsRes, contribRes, commitsRes] =
2021 await Promise.all([
21 fetch(base, { headers }),
22 fetch(`${base}/languages`, { headers }),
23 fetch(`${base}/tags`, { headers }),
24 fetch(`${base}/contributors`, { headers }),
25 fetch(`${base}/commits`, { headers }),
22 safeFetch(base, { headers }),
23 safeFetch(`${base}/languages`, { headers }),
24 safeFetch(`${base}/tags`, { headers }),
25 safeFetch(`${base}/contributors`, { headers }),
26 safeFetch(`${base}/commits`, { headers }),
2627 ]);
2728
2829 if (!infoRes.ok) {
@@ -103,7 +104,7 @@ const fetchFromGitHub = async (
103104const fetchFromWorker = async (
104105 github: string,
105106): Promise<GitHubStatsResponse | null> => {
106 const res = await fetch(`https://repo-info.as93.workers.dev/${github}`);
107 const res = await safeFetch(`https://repo-info.as93.workers.dev/${github}`);
107108 if (!res.ok) return null;
108109 return res.json();
109110};
web/src/utils/fetch-website-info.ts +2 −1
@@ -1,11 +1,12 @@
11import { error } from './logger';
2import { safeFetch } from './safe-fetch';
23
34export const fetchWebsiteInfo = async (
45 url: string,
56): Promise<WebsiteData | null> => {
67 const endpoint = `https://site-info-fetch.as93.workers.dev/?url=${url}`;
78 try {
8 const res = await fetch(endpoint);
9 const res = await safeFetch(endpoint);
910 if (!res.ok) {
1011 error('Website', `HTTP ${res.status} for ${url} (${endpoint})`);
1112 return null;
web/src/utils/safe-fetch.ts added +13
@@ -0,0 +1,13 @@
1// Defensive `fetch` wrapper for build-time + runtime calls.
2// Currently enforces a timeout; future: retries, error normalisation, etc.
3const DEFAULT_TIMEOUT_MS = 6000;
4
5export const safeFetch = (
6 url: string | URL,
7 init: RequestInit = {},
8 timeoutMs: number = DEFAULT_TIMEOUT_MS,
9): Promise<Response> =>
10 fetch(url, {
11 ...init,
12 signal: init.signal ?? AbortSignal.timeout(timeoutMs),
13 });