import axios from 'axios'; import type { Manga, Chapter, SearchResult, ChapterPages } from '../types'; const API_BASE = import.meta.env.VITE_API_BASE; const baseURL = API_BASE && API_BASE !== '' ? API_BASE : (typeof window !== 'undefined' ? window.location.origin : ''); const api = axios.create({ baseURL, timeout: 30000, }); export const searchManga = async (query: string): Promise => { const response = await api.get('/api/search', { params: { q: query } }); return response.data; }; export const getMangaDetails = async (id: string): Promise => { const response = await api.get(`/api/manga/${id}`); return response.data; }; export const getMangaChapters = async (id: string): Promise => { const response = await api.get(`/api/manga/${id}/chapters`); return response.data; }; export const getChapterPages = async (chapterId: string): Promise => { const response = await api.get(`/api/chapter/${chapterId}/pages`); return response.data; }; export const getImageUrl = (chapterId: string, filename: string): string => { const base = API_BASE && API_BASE !== '' ? API_BASE : (typeof window !== 'undefined' ? window.location.origin : ''); return `${base}/api/image/${chapterId}/${filename}`; }; export const checkServerHealth = async (): Promise => { try { await api.get('/api/search', { params: { q: 'test' }, timeout: 5000 }); return true; } catch { return false; } };