ente/src/services/searchService.ts

36 lines
885 B
TypeScript
Raw Normal View History

2021-05-20 07:50:20 +00:00
import HTTPService from './HTTPService';
2021-05-20 08:19:37 +00:00
import * as chrono from 'chrono-node';
import { getEndpoint } from 'utils/common/apiUtil';
2021-05-26 11:49:28 +00:00
import { getToken } from 'utils/common/key';
const ENDPOINT = getEndpoint();
2021-05-20 07:50:20 +00:00
export type Bbox = [number, number, number, number];
export interface LocationSearchResponse {
place: string;
bbox: Bbox;
}
2021-05-20 07:50:20 +00:00
export const getMapboxToken = () => {
return process.env.NEXT_PUBLIC_MAPBOX_TOKEN;
};
2021-05-20 08:19:37 +00:00
export function parseHumanDate(humanDate: string) {
return chrono.parseDate(humanDate);
}
2021-05-20 07:50:20 +00:00
export async function searchLocation(
searchPhrase: string
): Promise<LocationSearchResponse[]> {
2021-05-26 11:49:28 +00:00
const resp = await HTTPService.get(
`${ENDPOINT}/search/location`,
{
query: searchPhrase,
limit: 4,
},
{
'X-Auth-Token': getToken(),
}
);
return resp.data.results;
2021-05-20 07:50:20 +00:00
}