Tranga-Website/Website/modules/Manga.tsx

54 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-10-18 02:10:58 +02:00
import IManga from './interfaces/IManga';
import { getData } from '../App';
export default class Manga
2024-10-18 02:10:58 +02:00
{
2024-10-20 20:12:27 +02:00
static async GetAllManga(apiUri: string): Promise<IManga[]> {
2024-10-20 20:16:32 +02:00
//console.info("Getting all Manga");
2024-10-20 20:12:27 +02:00
return getData(`${apiUri}/v2/Mangas`)
2024-10-18 02:10:58 +02:00
.then((json) => {
2024-10-20 20:16:32 +02:00
//console.info("Got all Manga");
const ret = json as IManga[];
2024-10-20 20:12:27 +02:00
//console.debug(ret);
return (ret);
2024-10-18 02:10:58 +02:00
});
}
2024-10-20 20:12:27 +02:00
static async SearchManga(apiUri: string, name: string): Promise<IManga[]> {
2024-10-20 20:16:32 +02:00
//console.info(`Getting Manga ${name} from all Connectors`);
2024-10-20 20:12:27 +02:00
return await getData(`${apiUri}/v2/Manga/Search?title=${name}`)
2024-10-18 02:10:58 +02:00
.then((json) => {
2024-10-20 20:16:32 +02:00
//console.info(`Got Manga ${name}`);
const ret = json as IManga[];
2024-10-20 20:12:27 +02:00
//console.debug(ret);
return (ret);
2024-10-18 02:10:58 +02:00
});
}
2024-10-20 20:12:27 +02:00
static async GetMangaById(apiUri: string, internalId: string): Promise<IManga> {
2024-10-20 20:16:32 +02:00
//console.info(`Getting Manga ${internalId}`);
2024-10-20 20:12:27 +02:00
return await getData(`${apiUri}/v2/Manga/${internalId}`)
2024-10-18 02:10:58 +02:00
.then((json) => {
2024-10-20 20:16:32 +02:00
//console.info(`Got Manga ${internalId}`);
const ret = json as IManga;
2024-10-20 20:12:27 +02:00
//console.debug(ret);
return (ret);
2024-10-18 02:10:58 +02:00
});
}
2024-10-20 20:12:27 +02:00
static async GetMangaByIds(apiUri: string, internalIds: string[]): Promise<IManga[]> {
2024-10-20 20:16:32 +02:00
//console.debug(`Getting Mangas ${internalIds.join(",")}`);
2024-10-20 20:12:27 +02:00
return await getData(`${apiUri}/v2/Manga?mangaIds=${internalIds.join(",")}`)
2024-10-18 02:10:58 +02:00
.then((json) => {
2024-10-20 20:16:32 +02:00
//console.debug(`Got Manga ${internalIds.join(",")}`);
const ret = json as IManga[];
2024-10-20 20:12:27 +02:00
//console.debug(ret);
return (ret);
2024-10-18 02:10:58 +02:00
});
}
2024-10-31 21:40:01 +01:00
static GetMangaCoverUrl(apiUri: string, internalId: string, ref: HTMLElement): string {
2024-10-20 20:16:32 +02:00
//console.debug(`Getting Manga Cover-Url ${internalId}`);
return `${apiUri}/v2/Manga/${internalId}/Cover?dimensions=${ref.clientWidth*1.5}x${ref.clientHeight*1.5}`;
2024-10-18 02:10:58 +02:00
}
}