Spaces:
Running
Running
File size: 1,611 Bytes
cc2caf9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
// Client for the search API
type RawSearchResponse = {
films: string[];
series: string[];
episodes: {
series: string;
title: string;
path: string;
season: string;
}[];
};
const API_BASE_URL = 'https://hans-den-search.hf.space'; // Change this to your actual API URL
export const searchAPI = {
search: async (query: string): Promise<RawSearchResponse> => {
try {
const response = await fetch(`${API_BASE_URL}/api/search`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query }),
});
if (!response.ok) {
throw new Error(`Search API returned ${response.status}`);
}
const data = await response.json();
console.log('Search API response:', data);
return data;
} catch (error) {
console.error('Error searching:', error);
return { films: [], series: [], episodes: [] };
}
},
healthCheck: async (): Promise<boolean> => {
try {
const response = await fetch(`${API_BASE_URL}/health`);
return response.ok;
} catch (error) {
console.error('API health check failed:', error);
return false;
}
},
getData: async () => {
try {
const response = await fetch(`${API_BASE_URL}/api/data`);
if (!response.ok) {
throw new Error(`API returned ${response.status}`);
}
return await response.json();
} catch (error) {
console.error('Error fetching API data:', error);
return null;
}
}
};
|