Initial commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
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<SearchResult[]> => {
|
||||
const response = await api.get('/api/search', { params: { q: query } });
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getMangaDetails = async (id: string): Promise<Manga> => {
|
||||
const response = await api.get(`/api/manga/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getMangaChapters = async (id: string): Promise<Chapter[]> => {
|
||||
const response = await api.get(`/api/manga/${id}/chapters`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getChapterPages = async (chapterId: string): Promise<ChapterPages> => {
|
||||
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<boolean> => {
|
||||
try {
|
||||
await api.get('/api/search', { params: { q: 'test' }, timeout: 5000 });
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user