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:
parent
09f6a3125b
commit
1c17ef679d
1 changed files with 17 additions and 8 deletions
|
@ -101,10 +101,13 @@ const headers = {
|
|||
Authorization: `Bearer ${conf().TMDB_API_KEY}`,
|
||||
};
|
||||
|
||||
async function get<T>(url: string): Promise<T> {
|
||||
const res = await mwFetch<any>(url, {
|
||||
async function get<T>(url: string, params?: object): Promise<T> {
|
||||
const res = await mwFetch<any>(encodeURI(url), {
|
||||
headers,
|
||||
baseURL,
|
||||
params: {
|
||||
...params,
|
||||
},
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
@ -117,14 +120,20 @@ export async function searchMedia(
|
|||
|
||||
switch (type) {
|
||||
case "movie":
|
||||
data = await get<TMDBMovieResponse>(
|
||||
`search/movie?query=${query}&include_adult=false&language=en-US&page=1`
|
||||
);
|
||||
data = await get<TMDBMovieResponse>("search/movie", {
|
||||
query,
|
||||
include_adult: false,
|
||||
language: "en-US",
|
||||
page: 1,
|
||||
});
|
||||
break;
|
||||
case "show":
|
||||
data = await get<TMDBShowResponse>(
|
||||
`search/tv?query=${query}&include_adult=false&language=en-US&page=1`
|
||||
);
|
||||
data = await get<TMDBShowResponse>("search/tv", {
|
||||
query,
|
||||
include_adult: false,
|
||||
language: "en-US",
|
||||
page: 1,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new Error("Invalid media type");
|
||||
|
|
Loading…
Reference in a new issue