Skip to content

Commit

Permalink
Kakao : change api url (#954)
Browse files Browse the repository at this point in the history
* Kakao : change api url

and minor code changes.

Closes #951
  • Loading branch information
MikeZeDev authored Jan 3, 2025
1 parent f0e5a03 commit bf772ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
40 changes: 20 additions & 20 deletions web/src/engine/websites/Kakaopage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type APiPages = {
@Common.MangasNotSupported()
@Common.ImageAjax()
export default class extends DecoratableMangaScraper {
private readonly apiUrl = 'https://bff-page.kakao.com';

public constructor() {
super('kakaopage', `Page Kakao (카카오페이지)`, 'https://page.kakao.com', Tags.Media.Manga, Tags.Media.Manhwa, Tags.Media.Manhua, Tags.Language.Korean, Tags.Source.Official);
}
Expand All @@ -49,13 +51,14 @@ export default class extends DecoratableMangaScraper {
}

public override async FetchManga(provider: MangaPlugin, url: string): Promise<Manga> {
const id = new URL(url).pathname.match(/content\/(\d+)/)[1];
const id = new URL(url).pathname.match(/content\/(\d+)/).at(1);
const data = await FetchCSS<HTMLTitleElement>(new Request(url), 'title');
return new Manga(this, provider, id, data[0].text.split(' - ')[0].trim());
return new Manga(this, provider, id, data[0].text.split(' - ').at(0).trim());
}

public override async FetchChapters(manga: Manga): Promise<Chapter[]> {
let nextCursor = null;
let hasNextPage: boolean = false;
let nextCursor: string | undefined = undefined;
const chapterList: Chapter[] = [];

const gql = `
Expand Down Expand Up @@ -98,25 +101,18 @@ export default class extends DecoratableMangaScraper {
`;

do {
const request = new Request(new URL('/graphql', this.URI).href, {
headers: {
Referer: this.URI.href,
Origin: this.URI.href
}
});

const vars: JSONObject = {
seriesId: parseInt(manga.Identifier),
boughtOnly: false,
sortType: 'asc',
after: nextCursor
};

const data = await FetchGraphQL<APIChapters>(request, 'contentHomeProductList', gql, vars);
const chapters = data.contentHomeProductList.edges.map(chapter => new Chapter(this, manga, chapter.node.single.productId.toString(), chapter.node.single.title.replace(manga.Title, '').trim()));
nextCursor = data.contentHomeProductList.pageInfo.hasNextPage ? data.contentHomeProductList.pageInfo.endCursor : null;
const { contentHomeProductList: { edges, pageInfo: { hasNextPage, endCursor } } } = await FetchGraphQL<APIChapters>(this.CreateRequest(), 'contentHomeProductList', gql, vars);
const chapters = edges.map(chapter => new Chapter(this, manga, chapter.node.single.productId.toString(), chapter.node.single.title.replace(manga.Title, '').trim()));
nextCursor = hasNextPage ? endCursor : undefined;
chapterList.push(...chapters);
} while (nextCursor);
} while (hasNextPage);

return chapterList;
}
Expand Down Expand Up @@ -146,15 +142,19 @@ export default class extends DecoratableMangaScraper {
productId: parseInt(chapter.Identifier),
seriesId: parseInt(chapter.Parent.Identifier)
};
const request = new Request(new URL('/graphql', this.URI).href, {

const { viewerInfo: { viewerData: { imageDownloadData: { files } } } } = await FetchGraphQL<APiPages>(this.CreateRequest(), 'viewerInfo', gql, vars);
return files.map(page => new Page(this, chapter, new URL(page.secureUrl)));

}

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

const data = await FetchGraphQL<APiPages>(request, 'viewerInfo', gql, vars);
return data.viewerInfo.viewerData.imageDownloadData.files.map(page => new Page(this, chapter, new URL(page.secureUrl)));

}

}
3 changes: 2 additions & 1 deletion web/src/engine/websites/Kakaopage_e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const config = {
container: {
url: 'https://page.kakao.com/content/49361421',
id: '49361421',
title: '정령왕 엘퀴네스'
title: '정령왕 엘퀴네스',
timeout: 15000
},
child: {
id: '49402089',
Expand Down

0 comments on commit bf772ac

Please sign in to comment.