an independent Bluesky client using Constellation, PDS Queries, and other services reddwarf.app
frontend spa bluesky reddwarf microcosm client app
at main 35 lines 1.2 kB view raw
1import type { QueryLabelsResponse } from "~/types/moderation"; 2 3export const fetchLabelsBatch = async ( 4 serviceUrl: string, 5 opaqueIdentifierStringsToBeModerated: string[], 6): Promise<QueryLabelsResponse> => { 7 const url = new URL(`${serviceUrl}/xrpc/com.atproto.label.queryLabels`); 8 opaqueIdentifierStringsToBeModerated.forEach((opaqueIdentifierStringToBeModerated) => url.searchParams.append("uriPatterns", opaqueIdentifierStringToBeModerated)); 9 10 // 1. Setup Timeout (5 seconds) 11 const controller = new AbortController(); 12 const timeoutId = setTimeout(() => controller.abort(), 5000); 13 14 try { 15 const response = await fetch(url.toString(), { 16 signal: controller.signal, 17 }); 18 19 if (!response.ok) { 20 throw new Error(`HTTP ${response.status}: ${response.statusText}`); 21 } 22 23 const data = await response.json(); 24 return data as QueryLabelsResponse; 25 } catch (error: any) { 26 if (error.name === 'AbortError') { 27 console.error(`[fetchLabelsBatch] Timeout querying ${serviceUrl}`); 28 } else { 29 console.error(`[fetchLabelsBatch] Error querying ${serviceUrl}:`, error); 30 } 31 throw error; 32 } finally { 33 clearTimeout(timeoutId); 34 } 35};