JellyfinWishlistApp/be/src/jellyfinApiHelper.ts
Nikhil Nawgiri a3646e51d5 Refactor
2024-10-26 18:49:49 +02:00

28 lines
845 B
TypeScript

import fetch from "node-fetch";
import { API_BASE, API_TOKEN } from "../config.ts";
const API_ENDPOINT_WITH_PARAMS = "/Items?isMovie=true&isSeries=true&recursive=true&fields=ProviderIds&filters=&mediaTypes=Video&enableTotalRecordCount=true&enableImages=false";
const API_URL = API_BASE + API_ENDPOINT_WITH_PARAMS;
export const fetchFromJellyfinApi = async () => {
const init = {
method: "GET",
headers: {
accept: "application/json",
"Content-Type": "application/json",
Authorization: `MediaBrowser Token=${API_TOKEN}`,
},
};
const response = await fetch(API_URL, init)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.catch(error => console.error('Error:', error));
return response;
}