1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
Files
tooot/src/utils/fetches/searchFetch.ts
2020-12-15 00:01:48 +01:00

37 lines
688 B
TypeScript

import client from '@api/client'
export const searchFetch = async (
{} = {},
{
type,
term,
limit = 20
}: {
type?: 'accounts' | 'hashtags' | 'statuses'
term: string
limit?: number
}
): Promise<
| Mastodon.Account[]
| Mastodon.Tag[]
| Mastodon.Status[]
| {
accounts: Mastodon.Account[]
hashtags: Mastodon.Tag[]
statuses: Mastodon.Status[]
}
> => {
const res = await client({
version: 'v2',
method: 'get',
instance: 'local',
url: 'search',
params: { ...(type && { type }), q: term, limit }
})
if (type) {
return Promise.resolve(res.body[type])
} else {
return Promise.resolve(res.body)
}
}