One Calendar is a privacy-first calendar web app built with Next.js. It has modern security features, including e2ee, password-protected sharing, and self-destructing share links 馃搮 calendar.xyehr.cn
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 35 lines 892 B view raw
1const inflight = new Map<string, Promise<unknown>>() 2 3export async function fetchJson<T>( 4 url: string, 5 init?: RequestInit, 6): Promise<T> { 7 const method = (init?.method ?? 'GET').toUpperCase() 8 const key = `${method}:${url}:${init?.body ? String(init.body) : ''}` 9 10 if (method === 'GET' && inflight.has(key)) { 11 return inflight.get(key) as Promise<T> 12 } 13 14 const request = fetch(url, { 15 ...init, 16 headers: { 17 Accept: 'application/json', 18 ...(init?.headers ?? {}), 19 }, 20 }).then(async (response) => { 21 if (!response.ok) { 22 const error = new Error(`Request failed: ${response.status}`) 23 ;(error as Error & { status?: number }).status = response.status 24 throw error 25 } 26 return (await response.json()) as T 27 }) 28 29 if (method === 'GET') { 30 inflight.set(key, request) 31 request.finally(() => inflight.delete(key)) 32 } 33 34 return request 35}