ATProto forum built with ESAV
at main 23 lines 601 B view raw
1export async function esavQuery<T = unknown>( 2 esQuery: object, 3 options?: { 4 endpoint?: string; 5 signal?: AbortSignal; 6 } 7): Promise<T> { 8 const endpoint = options?.endpoint ?? "https://esav.whey.party/xrpc/com.example.prototypeESQuery"; 9 const q = encodeURIComponent(JSON.stringify(esQuery)); 10 const url = `${endpoint}?q=${q}`; 11 12 const res = await fetch(url, { 13 method: "GET", 14 signal: options?.signal, 15 }); 16 17 if (!res.ok) { 18 const errText = await res.text(); 19 throw new Error(`ESAV query failed: ${res.status} ${res.statusText} - ${errText}`); 20 } 21 22 return res.json(); 23}