env-specific search endpoint

This commit is contained in:
bryan newbold
2023-05-09 16:26:11 -07:00
parent 7a176b3fdf
commit d9c6553b44
2 changed files with 17 additions and 5 deletions
+7 -5
View File
@@ -3,9 +3,7 @@
* 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'
import {SEARCH_HOST} from 'lib/constants'
export interface ProfileSearchItem {
$type: string
@@ -35,11 +33,15 @@ export interface PostSearchItem {
export async function searchProfiles(
query: string,
): Promise<ProfileSearchItem[]> {
return await doFetch<ProfileSearchItem[]>(PROFILES_ENDPOINT, query)
const host = SEARCH_HOST(this.rootStore.session.currentSession?.service || '')
const endpoint = `${host}/search/profiles`
return await doFetch<ProfileSearchItem[]>(endpoint, query)
}
export async function searchPosts(query: string): Promise<PostSearchItem[]> {
return await doFetch<PostSearchItem[]>(POSTS_ENDPOINT, query)
const host = SEARCH_HOST(this.rootStore.session.currentSession?.service || '')
const endpoint = `${host}/search/posts`
return await doFetch<PostSearchItem[]>(endpoint, query)
}
async function doFetch<T>(endpoint: string, query: string): Promise<T> {
+10
View File
@@ -86,6 +86,16 @@ export function SUGGESTED_FOLLOWS(serviceUrl: string) {
}
}
export function SEARCH_HOST(serviceUrl: string) {
if (serviceUrl.includes('localhost')) {
return 'http://localhost:2470'
} else if (serviceUrl.includes('staging.bsky.dev')) {
return 'https://search.staging.bsky.dev'
} else {
return 'https://search.bsky.social'
}
}
export const POST_IMG_MAX = {
width: 2000,
height: 2000,