From 231c528c8871a7e14ec208a8cb274b9463e8dd22 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Wed, 10 Jan 2024 22:52:22 -0800 Subject: [PATCH] remove deprecated search.bsky.social code (#2461) --- src/lib/api/search.ts | 69 ------------------------------------------- 1 file changed, 69 deletions(-) delete mode 100644 src/lib/api/search.ts diff --git a/src/lib/api/search.ts b/src/lib/api/search.ts deleted file mode 100644 index dfe9b688..00000000 --- a/src/lib/api/search.ts +++ /dev/null @@ -1,69 +0,0 @@ -/** - * This is a temporary off-spec search endpoint - * TODO removeme when we land this in proto! - */ -import {AppBskyFeedPost} from '@atproto/api' - -const PROFILES_ENDPOINT = 'https://search.bsky.social/search/profiles' -const POSTS_ENDPOINT = 'https://search.bsky.social/search/posts' - -export interface ProfileSearchItem { - $type: string - avatar: { - cid: string - mimeType: string - } - banner: { - cid: string - mimeType: string - } - description: string | undefined - displayName: string | undefined - did: string -} - -export interface PostSearchItem { - tid: string - cid: string - user: { - did: string - handle: string - } - post: AppBskyFeedPost.Record -} - -export async function searchProfiles( - query: string, -): Promise { - return await doFetch(PROFILES_ENDPOINT, query) -} - -export async function searchPosts(query: string): Promise { - return await doFetch(POSTS_ENDPOINT, query) -} - -async function doFetch(endpoint: string, query: string): Promise { - const controller = new AbortController() - const to = setTimeout(() => controller.abort(), 15e3) - - const uri = new URL(endpoint) - uri.searchParams.set('q', query) - - const res = await fetch(String(uri), { - method: 'get', - headers: { - accept: 'application/json', - }, - signal: controller.signal, - }) - - const resHeaders: Record = {} - res.headers.forEach((value: string, key: string) => { - resHeaders[key] = value - }) - let resBody = await res.json() - - clearTimeout(to) - - return resBody as unknown as T -}