You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
738 B
39 lines
738 B
import ky from "ky";
|
|
|
|
import Adapter, { ApiType } from "@/client/adapters";
|
|
|
|
import Trending, { TrendingModel } from "./typings/trending";
|
|
|
|
import Transformer from "./transformer";
|
|
|
|
export const getTrending = async (
|
|
apiBaseUrl: string,
|
|
region = "US"
|
|
): Promise<Trending[]> => {
|
|
const url = new URL("/trending", apiBaseUrl);
|
|
|
|
const response = await ky.get(url, {
|
|
searchParams: { region: region.toUpperCase() }
|
|
});
|
|
|
|
const json = await response.json();
|
|
|
|
const data = TrendingModel.array().parse(json);
|
|
|
|
return data;
|
|
};
|
|
|
|
const adapter: Adapter = {
|
|
apiType: ApiType.Piped,
|
|
|
|
connect(url) {
|
|
return {
|
|
getTrending(region) {
|
|
return getTrending(url, region).then(Transformer.trending);
|
|
}
|
|
};
|
|
}
|
|
};
|
|
|
|
export default adapter;
|