refactor: clean code and remove unnecessary dependencies

This commit is contained in:
ner committed 2024-09-30 18:54:13 +03:00
1 parent eceae6fec7
commit ebf599eed6
92 files changed
+1152 -2842

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
class Http {
base = 'https://api.themoviedb.org/3';
get<T>(url: string, { params }: { params?: Record<string, unknown> } = {}): Promise<T> {
const serializedParams = Object.entries(params || {}).reduce((params, [key, value]) => {
if (!['', undefined, null].includes(value as string)) {
params.set(key, value as string);
}
return params;
}, new URLSearchParams());
return fetch(`${this.base}${url}?${serializedParams}`, {
headers: {
Authorization: `Bearer ${process.env.MOVIE_DB_TOKEN}`
},
next: { revalidate: 3600 }
}).then((response) => {
if (!response.ok) return Promise.reject(response);
return response.json();
});
}
}
const http = new Http();
export default http;