ente/src/services/searchService.ts

29 lines
744 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';
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[]> {
const resp = await HTTPService.get(`${ENDPOINT}/search/location`, {
query: searchPhrase,
limit: 4,
});
2021-05-26 11:41:55 +00:00
return resp.data.result;
2021-05-20 07:50:20 +00:00
}