Files
vega-providers/providers/flixhq/posts.ts
himanshu8443 2a4aa2a680 renaming
2025-06-16 22:26:38 +05:30

72 lines
1.8 KiB
TypeScript

import { Post, ProviderContext } from "../types";
export const getPosts = async function ({
filter,
signal,
providerContext,
}: {
filter: string;
page: number;
providerValue: string;
signal: AbortSignal;
providerContext: ProviderContext;
}): Promise<Post[]> {
const { getBaseUrl } = providerContext;
const urlRes = await getBaseUrl("consumet");
const baseUrl = urlRes + "/movies/flixhq";
const url = `${baseUrl + filter}`;
return posts({ url, signal, providerContext });
};
export const getSearchPosts = async function ({
searchQuery,
page,
signal,
providerContext,
}: {
searchQuery: string;
page: number;
providerValue: string;
signal: AbortSignal;
providerContext: ProviderContext;
}): Promise<Post[]> {
const { getBaseUrl } = providerContext;
const urlRes = await getBaseUrl("consumet");
const baseUrl = urlRes + "/movies/flixhq";
const url = `${baseUrl}/${searchQuery}?page=${page}`;
return posts({ url, signal, providerContext });
};
async function posts({
url,
signal,
providerContext,
}: {
url: string;
signal: AbortSignal;
providerContext: ProviderContext;
}): Promise<Post[]> {
try {
const { axios } = providerContext;
const res = await axios.get(url, { signal });
const data = res.data?.results || res.data;
const catalog: Post[] = [];
data?.map((element: any) => {
const title = element.title;
const link = element.id;
const image = element.image;
if (title && link && image) {
catalog.push({
title: title,
link: link,
image: image,
});
}
});
return catalog;
} catch (err) {
console.error("flixhq error ", err);
return [];
}
}