Skip to content

Commit

Permalink
minify type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronny committed Feb 20, 2025
1 parent b204bf5 commit 4de26b4
Showing 1 changed file with 14 additions and 27 deletions.
41 changes: 14 additions & 27 deletions web/src/engine/websites/PerfScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,17 @@ import { Chapter, DecoratableMangaScraper, Manga, type MangaPlugin, Page } from
import * as Common from './decorators/Common';
import { FetchJSON } from '../platform/FetchProvider';

type APIResult<T> = {
data : T
}

type APIManga = {
id: string,
title: string
Chapter: APIChapter[]
}

type APIChapter = {
id: string,
index: number,
content: {
value : string
}[]
}
type APIResult<T> = { data: T };
type APIManga = APIResult<{ id: string, title: string }>;
type APIMangas = APIResult<{ id: string, title: string }[]>;
type APIChapters = APIResult<{ Chapter: { id: string, index: number }[] }>;
type APIPages = APIResult<{ content: { value: string }[] }>;

@Common.ImageAjax(true)
export default class extends DecoratableMangaScraper {
private readonly apiUrl = 'https://api.perf-scan.fr/';
private readonly CdnUrl = 'https://api.perf-scan.fr/cdn/';

private readonly apiUrl = 'https://api.perf-scan.fr';
private readonly cdnUrl = this.apiUrl + '/cdn/';

public constructor() {
super('perfscan', 'Perf Scan', 'https://perf-scan.fr', Tags.Media.Manhwa, Tags.Media.Manhua, Tags.Language.French, Tags.Source.Scanlator);
Expand All @@ -40,33 +29,31 @@ export default class extends DecoratableMangaScraper {
}

public override async FetchManga(provider: MangaPlugin, url: string): Promise<Manga> {
const mangaId = url.split('/').at(-1);
const { data: { id, title } } = await FetchJSON<APIResult<APIManga>>(this.CreateRequest(`./series/${mangaId}`));
const { data: { id, title } } = await FetchJSON<APIManga>(this.CreateRequest(`/series/${ url.split('/').at(-1) }`));
return new Manga(this, provider, id, title);
}

public override async FetchMangas(provider: MangaPlugin): Promise<Manga[]> {
const { data } = await FetchJSON<APIResult<APIManga[]>>(this.CreateRequest(`./series?type=COMIC&take=9999&page=1&dataForPage=HOME`));
const { data } = await FetchJSON<APIMangas>(this.CreateRequest('/series?type=COMIC&take=9999&page=1&dataForPage=HOME'));
return data.map(manga => new Manga(this, provider, manga.id, manga.title));
}

public override async FetchChapters(manga: Manga): Promise<Chapter[]> {
const chapters = (await FetchJSON<APIResult<APIManga>>(this.CreateRequest(`./series/${manga.Identifier}`))).data.Chapter;
const { data: { Chapter: chapters } } = await FetchJSON<APIChapters>(this.CreateRequest(`/series/${manga.Identifier}`));
return chapters.map(chapter => new Chapter(this, manga, chapter.id, chapter.index.toString()));
}

public override async FetchPages(chapter: Chapter): Promise<Page[]> {
const { data: { content } } = await FetchJSON<APIResult<APIChapter>>(this.CreateRequest(`./series/${chapter.Parent.Identifier}/chapter/${chapter.Identifier}`));
return content.map(page => new Page(this, chapter, new URL(page.value, this.CdnUrl)));
const { data: { content } } = await FetchJSON<APIPages>(this.CreateRequest(`/series/${chapter.Parent.Identifier}/chapter/${chapter.Identifier}`));
return content.map(page => new Page(this, chapter, new URL(page.value, this.cdnUrl)));
}

private CreateRequest(endpoint: string): Request {
return new Request(new URL(endpoint, this.apiUrl), {
headers: {
Referer: this.URI.href,
Origin: this.URI.origin
Origin: this.URI.origin,
}
});
}

}

0 comments on commit 4de26b4

Please sign in to comment.