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 @@
1import { error } from './logger'; 1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
2 3
3const doubleCheckPackageName = (packageStr: string) => { 4const doubleCheckPackageName = (packageStr: string) => {
4 return packageStr.includes('id=') ? packageStr.split('id=')[1] : packageStr; 5 return packageStr.includes('id=') ? packageStr.split('id=')[1] : packageStr;
@@ -9,7 +10,7 @@ export const fetchAndroidInfo = async (
9): Promise<AndroidInfo | null> => { 10): Promise<AndroidInfo | null> => {
10 const endpoint = `https://android-app-privacy.as93.net/${doubleCheckPackageName(androidPackage)}`; 11 const endpoint = `https://android-app-privacy.as93.net/${doubleCheckPackageName(androidPackage)}`;
11 try { 12 try {
12 const res = await fetch(endpoint); 13 const res = await safeFetch(endpoint);
13 if (!res.ok) { 14 if (!res.ok) {
14 error( 15 error(
15 'Android', 16 'Android',
web/src/utils/fetch-changelog.ts +4 −3
@@ -1,8 +1,9 @@
1import { error } from './logger'; 1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
2 3
3const changelogUrl = 4const changelogUrl =
4 // 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/.github/changelog.json'; 5 'https://raw.githubusercontent.com/Lissy93/awesome-privacy/main/.github/changelog.json';
5 'https://gist.githubusercontent.com/Lissy93/ddae176f3f21a0d3c0251f5f6cbd3b09/raw/9e62d21ea8866709520331dd2ec6a67494460707/changelog.json'; 6// 'https://gist.githubusercontent.com/Lissy93/ddae176f3f21a0d3c0251f5f6cbd3b09/raw/9e62d21ea8866709520331dd2ec6a67494460707/changelog.json';
6 7
7export interface ChangelogPr { 8export interface ChangelogPr {
8 number: number; 9 number: number;
@@ -74,7 +75,7 @@ export interface Changelog {
74 75
75export const fetchChangelog = async (): Promise<Changelog> => { 76export const fetchChangelog = async (): Promise<Changelog> => {
76 try { 77 try {
77 const res = await fetch(changelogUrl); 78 const res = await safeFetch(changelogUrl);
78 if (!res.ok) { 79 if (!res.ok) {
79 error('Changelog', `HTTP ${res.status} fetching changelog.json`); 80 error('Changelog', `HTTP ${res.status} fetching changelog.json`);
80 return { generatedAt: '', entries: [] }; 81 return { generatedAt: '', entries: [] };
web/src/utils/fetch-data.ts +2 −1
@@ -1,5 +1,6 @@
1import yaml from 'js-yaml'; 1import yaml from 'js-yaml';
2import { error } from './logger'; 2import { error } from './logger';
3import { safeFetch } from './safe-fetch';
3 4
4import type { AwesomePrivacy } from '../types/Service'; 5import type { AwesomePrivacy } from '../types/Service';
5 6
@@ -8,7 +9,7 @@ const awesomePrivacyData =
8 9
9export const fetchData = async (): Promise<AwesomePrivacy> => { 10export const fetchData = async (): Promise<AwesomePrivacy> => {
10 try { 11 try {
11 const res = await fetch(awesomePrivacyData); 12 const res = await safeFetch(awesomePrivacyData, {}, 15000);
12 if (!res.ok) { 13 if (!res.ok) {
13 error( 14 error(
14 'Data', 15 'Data',
web/src/utils/fetch-discord-info.ts +2 −1
@@ -1,11 +1,12 @@
1import { error } from './logger'; 1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
2 3
3export const fetchDiscordInfo = async ( 4export const fetchDiscordInfo = async (
4 discordInvite: string, 5 discordInvite: string,
5): Promise<DiscordInfo | null> => { 6): Promise<DiscordInfo | null> => {
6 const endpoint = `https://discord-invite-info.as93.net/${discordInvite}`; 7 const endpoint = `https://discord-invite-info.as93.net/${discordInvite}`;
7 try { 8 try {
8 const res = await fetch(endpoint); 9 const res = await safeFetch(endpoint);
9 if (!res.ok) { 10 if (!res.ok) {
10 error('Discord', `HTTP ${res.status} for ${discordInvite} (${endpoint})`); 11 error('Discord', `HTTP ${res.status} for ${discordInvite} (${endpoint})`);
11 return null; 12 return null;
web/src/utils/fetch-docker-instructions.ts +2 −1
@@ -1,11 +1,12 @@
1import { error } from './logger'; 1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
2 3
3export const fetchDockerData = async ( 4export const fetchDockerData = async (
4 serviceName: string, 5 serviceName: string,
5): Promise<TemplateResponse | null> => { 6): Promise<TemplateResponse | null> => {
6 const endpoint = `https://docker-info.as93.workers.dev/${serviceName}`; 7 const endpoint = `https://docker-info.as93.workers.dev/${serviceName}`;
7 try { 8 try {
8 const res = await fetch(endpoint); 9 const res = await safeFetch(endpoint);
9 if (!res.ok) { 10 if (!res.ok) {
10 error('Docker', `HTTP ${res.status} for ${serviceName} (${endpoint})`); 11 error('Docker', `HTTP ${res.status} for ${serviceName} (${endpoint})`);
11 return null; 12 return null;
web/src/utils/fetch-ios-info.ts +2 −1
@@ -1,11 +1,12 @@
1import { error } from './logger'; 1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
2 3
3export const fetchIosInfo = async ( 4export const fetchIosInfo = async (
4 iosUrl: string, 5 iosUrl: string,
5): Promise<IoSApiResponse | null> => { 6): Promise<IoSApiResponse | null> => {
6 const endpoint = `https://ios-app-info.as93.net?appStoreUrl=${iosUrl}`; 7 const endpoint = `https://ios-app-info.as93.net?appStoreUrl=${iosUrl}`;
7 try { 8 try {
8 const res = await fetch(endpoint); 9 const res = await safeFetch(endpoint);
9 if (!res.ok) { 10 if (!res.ok) {
10 error('iOS', `HTTP ${res.status} for ${iosUrl} (${endpoint})`); 11 error('iOS', `HTTP ${res.status} for ${iosUrl} (${endpoint})`);
11 return null; 12 return null;
web/src/utils/fetch-privacy-policy.ts +2 −1
@@ -1,11 +1,12 @@
1import { error } from './logger'; 1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
2 3
3export const fetchTosdrPrivacy = async ( 4export const fetchTosdrPrivacy = async (
4 serviceId: string, 5 serviceId: string,
5): Promise<PrivacyPolicyResponse | null> => { 6): Promise<PrivacyPolicyResponse | null> => {
6 const endpoint = `https://privacy-policies.as93.workers.dev/${serviceId}`; 7 const endpoint = `https://privacy-policies.as93.workers.dev/${serviceId}`;
7 try { 8 try {
8 const res = await fetch(endpoint); 9 const res = await safeFetch(endpoint);
9 if (!res.ok) { 10 if (!res.ok) {
10 error( 11 error(
11 'ToS;DR', 12 'ToS;DR',
web/src/utils/fetch-reddit-info.ts +2 −1
@@ -1,11 +1,12 @@
1import { error } from './logger'; 1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
2 3
3export const fetchRedditInfo = async ( 4export const fetchRedditInfo = async (
4 subreddit: string, 5 subreddit: string,
5): Promise<RedditData | null> => { 6): Promise<RedditData | null> => {
6 const endpoint = `https://subreddit-info.as93.net/${subreddit}`; 7 const endpoint = `https://subreddit-info.as93.net/${subreddit}`;
7 try { 8 try {
8 const res = await fetch(endpoint); 9 const res = await safeFetch(endpoint);
9 if (!res.ok) { 10 if (!res.ok) {
10 error('Reddit', `HTTP ${res.status} for r/${subreddit} (${endpoint})`); 11 error('Reddit', `HTTP ${res.status} for r/${subreddit} (${endpoint})`);
11 return null; 12 return null;
web/src/utils/fetch-repo-info.ts +7 −6
@@ -1,4 +1,5 @@
1import { error } from './logger'; 1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
2 3
3const githubHeaders = (): Record<string, string> => { 4const githubHeaders = (): Record<string, string> => {
4 const headers: Record<string, string> = { 5 const headers: Record<string, string> = {
@@ -18,11 +19,11 @@ const fetchFromGitHub = async (
18 19
19 const [infoRes, langsRes, tagsRes, contribRes, commitsRes] = 20 const [infoRes, langsRes, tagsRes, contribRes, commitsRes] =
20 await Promise.all([ 21 await Promise.all([
21 fetch(base, { headers }), 22 safeFetch(base, { headers }),
22 fetch(`${base}/languages`, { headers }), 23 safeFetch(`${base}/languages`, { headers }),
23 fetch(`${base}/tags`, { headers }), 24 safeFetch(`${base}/tags`, { headers }),
24 fetch(`${base}/contributors`, { headers }), 25 safeFetch(`${base}/contributors`, { headers }),
25 fetch(`${base}/commits`, { headers }), 26 safeFetch(`${base}/commits`, { headers }),
26 ]); 27 ]);
27 28
28 if (!infoRes.ok) { 29 if (!infoRes.ok) {
@@ -103,7 +104,7 @@ const fetchFromGitHub = async (
103const fetchFromWorker = async ( 104const fetchFromWorker = async (
104 github: string, 105 github: string,
105): Promise<GitHubStatsResponse | null> => { 106): 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}`);
107 if (!res.ok) return null; 108 if (!res.ok) return null;
108 return res.json(); 109 return res.json();
109}; 110};
web/src/utils/fetch-website-info.ts +2 −1
@@ -1,11 +1,12 @@
1import { error } from './logger'; 1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
2 3
3export const fetchWebsiteInfo = async ( 4export const fetchWebsiteInfo = async (
4 url: string, 5 url: string,
5): Promise<WebsiteData | null> => { 6): Promise<WebsiteData | null> => {
6 const endpoint = `https://site-info-fetch.as93.workers.dev/?url=${url}`; 7 const endpoint = `https://site-info-fetch.as93.workers.dev/?url=${url}`;
7 try { 8 try {
8 const res = await fetch(endpoint); 9 const res = await safeFetch(endpoint);
9 if (!res.ok) { 10 if (!res.ok) {
10 error('Website', `HTTP ${res.status} for ${url} (${endpoint})`); 11 error('Website', `HTTP ${res.status} for ${url} (${endpoint})`);
11 return null; 12 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 });