1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-20 14:37:43 +01:00

clean up requests

This commit is contained in:
adrifcastr 2023-06-21 14:04:37 +02:00
parent 09f6a3125b
commit 1c17ef679d

View file

@ -101,10 +101,13 @@ const headers = {
Authorization: `Bearer ${conf().TMDB_API_KEY}`, Authorization: `Bearer ${conf().TMDB_API_KEY}`,
}; };
async function get<T>(url: string): Promise<T> { async function get<T>(url: string, params?: object): Promise<T> {
const res = await mwFetch<any>(url, { const res = await mwFetch<any>(encodeURI(url), {
headers, headers,
baseURL, baseURL,
params: {
...params,
},
}); });
return res; return res;
} }
@ -117,14 +120,20 @@ export async function searchMedia(
switch (type) { switch (type) {
case "movie": case "movie":
data = await get<TMDBMovieResponse>( data = await get<TMDBMovieResponse>("search/movie", {
`search/movie?query=${query}&include_adult=false&language=en-US&page=1` query,
); include_adult: false,
language: "en-US",
page: 1,
});
break; break;
case "show": case "show":
data = await get<TMDBShowResponse>( data = await get<TMDBShowResponse>("search/tv", {
`search/tv?query=${query}&include_adult=false&language=en-US&page=1` query,
); include_adult: false,
language: "en-US",
page: 1,
});
break; break;
default: default:
throw new Error("Invalid media type"); throw new Error("Invalid media type");