init site

This commit is contained in:
ld3zian 2025-01-13 17:44:11 -07:00
parent 40a7e60a8b
commit c765ca9c85
20 changed files with 6860 additions and 1 deletions

47
src/lib/api.ts Normal file
View file

@ -0,0 +1,47 @@
import type { Comic } from './types';
const languages = new Set(["en", "fr", "es", "it", "pl", "tr", "ja", "zh", "sv"]);
const contentTypes = new Set(["sfw", "nsfw"]);
const urlBase = "https://api.comick.fun/chapter"; // Removed trailing slash
export async function fetchComics(language: string = 'en', contentType: string = 'sfw'): Promise<Comic[]> {
try {
const apiUrl = `${urlBase}?lang=${language}&page=1&order=new&accept_erotic_content=${contentType === 'nsfw'}`;
// console.log('Fetching from:', apiUrl); // Debug log
const response = await fetch(apiUrl, {
headers: {
'Accept': 'application/json',
'User-Agent': 'Mozilla/5.0 (compatible; ComicReader/1.0)',
},
});
if (!response.ok) {
throw new Error(`API responded with status: ${response.status}`);
}
const data = await response.json();
// console.log('API response:', data); // Debug log
if (!Array.isArray(data)) {
console.error('Unexpected API response format:', data);
return [];
}
return data;
} catch (error) {
console.error('Error fetching comics:', error);
return [];
}
}
export function isValidLanguage(lang: string): boolean {
return languages.has(lang);
}
export function isValidContentType(type: string): boolean {
return contentTypes.has(type);
}
export const availableLanguages = Array.from(languages);
export const availableContentTypes = Array.from(contentTypes);