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