react-native-consumet 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/extension-registry.json.sig +1 -1
- package/lib/commonjs/index.js +18 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/types.js +6 -0
- package/lib/commonjs/models/types.js.map +1 -1
- package/lib/commonjs/providers/manga/asurascans.js +160 -96
- package/lib/commonjs/providers/manga/asurascans.js.map +1 -1
- package/lib/commonjs/providers/manga/flamescans.js +173 -91
- package/lib/commonjs/providers/manga/flamescans.js.map +1 -1
- package/lib/commonjs/providers/manga/index.js +1 -15
- package/lib/commonjs/providers/manga/index.js.map +1 -1
- package/lib/commonjs/providers/manga/mangadex.js +234 -227
- package/lib/commonjs/providers/manga/mangadex.js.map +1 -1
- package/lib/commonjs/providers/manga/mangahere.js +279 -135
- package/lib/commonjs/providers/manga/mangahere.js.map +1 -1
- package/lib/commonjs/providers/manga/mangakakalot.js +206 -107
- package/lib/commonjs/providers/manga/mangakakalot.js.map +1 -1
- package/lib/commonjs/providers/manga/mangapill.js +126 -38
- package/lib/commonjs/providers/manga/mangapill.js.map +1 -1
- package/lib/commonjs/providers/meta/anilist.js +41 -12
- package/lib/commonjs/providers/meta/anilist.js.map +1 -1
- package/lib/commonjs/utils/index.js +19 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/manga.js +60 -0
- package/lib/commonjs/utils/manga.js.map +1 -0
- package/lib/module/extension-registry.json.sig +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/types.js +9 -0
- package/lib/module/models/types.js.map +1 -1
- package/lib/module/providers/manga/asurascans.js +161 -96
- package/lib/module/providers/manga/asurascans.js.map +1 -1
- package/lib/module/providers/manga/flamescans.js +174 -91
- package/lib/module/providers/manga/flamescans.js.map +1 -1
- package/lib/module/providers/manga/index.js +1 -15
- package/lib/module/providers/manga/index.js.map +1 -1
- package/lib/module/providers/manga/mangadex.js +236 -228
- package/lib/module/providers/manga/mangadex.js.map +1 -1
- package/lib/module/providers/manga/mangahere.js +276 -132
- package/lib/module/providers/manga/mangahere.js.map +1 -1
- package/lib/module/providers/manga/mangakakalot.js +207 -107
- package/lib/module/providers/manga/mangakakalot.js.map +1 -1
- package/lib/module/providers/manga/mangapill.js +128 -39
- package/lib/module/providers/manga/mangapill.js.map +1 -1
- package/lib/module/providers/meta/anilist.js +41 -12
- package/lib/module/providers/meta/anilist.js.map +1 -1
- package/lib/module/utils/index.js +1 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/manga.js +54 -0
- package/lib/module/utils/manga.js.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +2 -2
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/models/types.d.ts +38 -5
- package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/asurascans.d.ts +14 -4
- package/lib/typescript/commonjs/src/providers/manga/asurascans.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/flamescans.d.ts +18 -3
- package/lib/typescript/commonjs/src/providers/manga/flamescans.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/index.d.ts +0 -14
- package/lib/typescript/commonjs/src/providers/manga/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/mangadex.d.ts +22 -5
- package/lib/typescript/commonjs/src/providers/manga/mangadex.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/mangahere.d.ts +15 -3
- package/lib/typescript/commonjs/src/providers/manga/mangahere.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/mangakakalot.d.ts +26 -4
- package/lib/typescript/commonjs/src/providers/manga/mangakakalot.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/manga/mangapill.d.ts +16 -2
- package/lib/typescript/commonjs/src/providers/manga/mangapill.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/index.d.ts +1 -0
- package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/utils/manga.d.ts +19 -0
- package/lib/typescript/commonjs/src/utils/manga.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +2 -2
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/models/types.d.ts +38 -5
- package/lib/typescript/module/src/models/types.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/asurascans.d.ts +14 -4
- package/lib/typescript/module/src/providers/manga/asurascans.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/flamescans.d.ts +18 -3
- package/lib/typescript/module/src/providers/manga/flamescans.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/index.d.ts +0 -14
- package/lib/typescript/module/src/providers/manga/index.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/mangadex.d.ts +22 -5
- package/lib/typescript/module/src/providers/manga/mangadex.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/mangahere.d.ts +15 -3
- package/lib/typescript/module/src/providers/manga/mangahere.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/mangakakalot.d.ts +26 -4
- package/lib/typescript/module/src/providers/manga/mangakakalot.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/manga/mangapill.d.ts +16 -2
- package/lib/typescript/module/src/providers/manga/mangapill.d.ts.map +1 -1
- package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/index.d.ts +1 -0
- package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/module/src/utils/manga.d.ts +19 -0
- package/lib/typescript/module/src/utils/manga.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/extension-registry.json.sig +1 -1
- package/src/index.tsx +6 -0
- package/src/models/types.ts +38 -3
- package/src/providers/manga/asurascans.ts +200 -135
- package/src/providers/manga/flamescans.ts +221 -118
- package/src/providers/manga/index.ts +0 -14
- package/src/providers/manga/mangadex.ts +335 -282
- package/src/providers/manga/mangahere.ts +309 -156
- package/src/providers/manga/mangakakalot.ts +249 -152
- package/src/providers/manga/mangapill.ts +163 -64
- package/src/providers/meta/anilist.ts +50 -14
- package/src/utils/index.ts +1 -0
- package/src/utils/manga.ts +58 -0
- package/lib/commonjs/providers/manga/brmangas.js +0 -110
- package/lib/commonjs/providers/manga/brmangas.js.map +0 -1
- package/lib/commonjs/providers/manga/comick.js +0 -154
- package/lib/commonjs/providers/manga/comick.js.map +0 -1
- package/lib/commonjs/providers/manga/mangahost.js +0 -113
- package/lib/commonjs/providers/manga/mangahost.js.map +0 -1
- package/lib/commonjs/providers/manga/mangapark.js +0 -97
- package/lib/commonjs/providers/manga/mangapark.js.map +0 -1
- package/lib/commonjs/providers/manga/mangareader.js +0 -106
- package/lib/commonjs/providers/manga/mangareader.js.map +0 -1
- package/lib/commonjs/providers/manga/mangasee123.js +0 -161
- package/lib/commonjs/providers/manga/mangasee123.js.map +0 -1
- package/lib/commonjs/providers/manga/readmanga.js +0 -269
- package/lib/commonjs/providers/manga/readmanga.js.map +0 -1
- package/lib/commonjs/providers/manga/vyvymanga.js +0 -166
- package/lib/commonjs/providers/manga/vyvymanga.js.map +0 -1
- package/lib/module/providers/manga/brmangas.js +0 -105
- package/lib/module/providers/manga/brmangas.js.map +0 -1
- package/lib/module/providers/manga/comick.js +0 -149
- package/lib/module/providers/manga/comick.js.map +0 -1
- package/lib/module/providers/manga/mangahost.js +0 -108
- package/lib/module/providers/manga/mangahost.js.map +0 -1
- package/lib/module/providers/manga/mangapark.js +0 -92
- package/lib/module/providers/manga/mangapark.js.map +0 -1
- package/lib/module/providers/manga/mangareader.js +0 -101
- package/lib/module/providers/manga/mangareader.js.map +0 -1
- package/lib/module/providers/manga/mangasee123.js +0 -156
- package/lib/module/providers/manga/mangasee123.js.map +0 -1
- package/lib/module/providers/manga/readmanga.js +0 -264
- package/lib/module/providers/manga/readmanga.js.map +0 -1
- package/lib/module/providers/manga/vyvymanga.js +0 -161
- package/lib/module/providers/manga/vyvymanga.js.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/brmangas.d.ts +0 -18
- package/lib/typescript/commonjs/src/providers/manga/brmangas.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/comick.d.ts +0 -39
- package/lib/typescript/commonjs/src/providers/manga/comick.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/mangahost.d.ts +0 -18
- package/lib/typescript/commonjs/src/providers/manga/mangahost.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/mangapark.d.ts +0 -14
- package/lib/typescript/commonjs/src/providers/manga/mangapark.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/mangareader.d.ts +0 -18
- package/lib/typescript/commonjs/src/providers/manga/mangareader.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/mangasee123.d.ts +0 -17
- package/lib/typescript/commonjs/src/providers/manga/mangasee123.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/readmanga.d.ts +0 -31
- package/lib/typescript/commonjs/src/providers/manga/readmanga.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/providers/manga/vyvymanga.d.ts +0 -17
- package/lib/typescript/commonjs/src/providers/manga/vyvymanga.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/brmangas.d.ts +0 -18
- package/lib/typescript/module/src/providers/manga/brmangas.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/comick.d.ts +0 -39
- package/lib/typescript/module/src/providers/manga/comick.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/mangahost.d.ts +0 -18
- package/lib/typescript/module/src/providers/manga/mangahost.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/mangapark.d.ts +0 -14
- package/lib/typescript/module/src/providers/manga/mangapark.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/mangareader.d.ts +0 -18
- package/lib/typescript/module/src/providers/manga/mangareader.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/mangasee123.d.ts +0 -17
- package/lib/typescript/module/src/providers/manga/mangasee123.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/readmanga.d.ts +0 -31
- package/lib/typescript/module/src/providers/manga/readmanga.d.ts.map +0 -1
- package/lib/typescript/module/src/providers/manga/vyvymanga.d.ts +0 -17
- package/lib/typescript/module/src/providers/manga/vyvymanga.d.ts.map +0 -1
- package/src/providers/manga/brmangas.ts +0 -148
- package/src/providers/manga/comick.ts +0 -285
- package/src/providers/manga/mangahost.ts +0 -134
- package/src/providers/manga/mangapark.ts +0 -115
- package/src/providers/manga/mangareader.ts +0 -132
- package/src/providers/manga/mangasee123.ts +0 -187
- package/src/providers/manga/readmanga.ts +0 -380
- package/src/providers/manga/vyvymanga.ts +0 -237
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { load } from 'cheerio';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
MangaParser,
|
|
@@ -11,12 +11,53 @@ import {
|
|
|
11
11
|
type ProviderContext,
|
|
12
12
|
} from '../../models';
|
|
13
13
|
import { createProviderContext } from '../../utils/create-provider-context';
|
|
14
|
-
import
|
|
14
|
+
import { sortChaptersForReading } from '../../utils/manga';
|
|
15
15
|
|
|
16
|
+
/** The JSON API behind asurascans.com (the site's own pages call it). */
|
|
17
|
+
const API_URL = 'https://api.asurascans.com/api';
|
|
18
|
+
const PAGE_SIZE = 20;
|
|
19
|
+
|
|
20
|
+
/** A series as the API lists it (search, browse and series detail). */
|
|
21
|
+
type ApiSeries = {
|
|
22
|
+
slug: string;
|
|
23
|
+
title: string;
|
|
24
|
+
alt_titles?: string[] | null;
|
|
25
|
+
description?: string | null;
|
|
26
|
+
cover?: string | null;
|
|
27
|
+
cover_url?: string | null;
|
|
28
|
+
status?: string | null;
|
|
29
|
+
type?: string | null;
|
|
30
|
+
author?: string | null;
|
|
31
|
+
artist?: string | null;
|
|
32
|
+
rating?: number | null;
|
|
33
|
+
public_url?: string | null;
|
|
34
|
+
genres?: { name: string }[] | null;
|
|
35
|
+
latest_chapters?: { number: number }[] | null;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type ApiChapter = {
|
|
39
|
+
number: number;
|
|
40
|
+
title?: string | null;
|
|
41
|
+
is_premium?: boolean;
|
|
42
|
+
early_access_until?: string | null;
|
|
43
|
+
published_at?: string | null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type ApiChapterRead = {
|
|
47
|
+
access_gate?: string;
|
|
48
|
+
is_locked?: boolean;
|
|
49
|
+
unlock_time?: string | null;
|
|
50
|
+
chapter?: { pages?: { url: string }[] | null };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* AsuraScans (asurascans.com, formerly asuracomic.net). Ids are the site's series slug
|
|
55
|
+
* (`omniscient-readers-viewpoint`) and `<slug>/chapter/<number>` for chapters.
|
|
56
|
+
*/
|
|
16
57
|
export class AsuraScans extends MangaParser {
|
|
17
58
|
override readonly name = 'AsuraScans';
|
|
18
|
-
protected override baseUrl = 'https://
|
|
19
|
-
protected override logo = 'https://
|
|
59
|
+
protected override baseUrl = 'https://asurascans.com';
|
|
60
|
+
protected override logo = 'https://asurascans.com/images/logo.webp';
|
|
20
61
|
protected override classPath = 'MANGA.AsuraScans';
|
|
21
62
|
|
|
22
63
|
/** @param ctx provider context; requests go through its axios (default: `createProviderContext()`) */
|
|
@@ -24,147 +65,171 @@ export class AsuraScans extends MangaParser {
|
|
|
24
65
|
super();
|
|
25
66
|
}
|
|
26
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @param query Search query
|
|
70
|
+
* @param page Page number (default: 1), 20 results per page
|
|
71
|
+
*/
|
|
72
|
+
override search = async (query: string, page: number = 1): Promise<ISearch<IMangaResult>> => {
|
|
73
|
+
const currentPage = Math.max(1, Math.floor(page) || 1);
|
|
74
|
+
const offset = (currentPage - 1) * PAGE_SIZE;
|
|
75
|
+
const { data, meta } = await this.api<{
|
|
76
|
+
data: ApiSeries[] | null;
|
|
77
|
+
meta?: { total?: number; has_more?: boolean };
|
|
78
|
+
}>(`/series?search=${encodeURIComponent(query)}&limit=${PAGE_SIZE}&offset=${offset}`);
|
|
79
|
+
const results = (data ?? []).map((series) => this.toResult(series));
|
|
80
|
+
return {
|
|
81
|
+
currentPage,
|
|
82
|
+
hasNextPage: meta?.has_more ?? (typeof meta?.total === 'number' && offset + results.length < meta.total),
|
|
83
|
+
results,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** @param mangaId series slug from `search` (`series/<slug>-<hash>` ids from asuracomic.net work too) */
|
|
27
88
|
override fetchMangaInfo = async (mangaId: string): Promise<IMangaInfo> => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
.
|
|
48
|
-
.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
rating: $(ele).find('div > div.block > span > label').text().trim(),
|
|
66
|
-
};
|
|
67
|
-
})
|
|
68
|
-
.get(),
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const chapMatch = data
|
|
72
|
-
.replace(/\n/g, '')
|
|
73
|
-
.replace(/\\/g, '')
|
|
74
|
-
.match(/"chapters".*:(\[\{.*?\}\]),/);
|
|
75
|
-
if (chapMatch) {
|
|
76
|
-
const chap: {
|
|
77
|
-
name: string;
|
|
78
|
-
title: string;
|
|
79
|
-
id: string;
|
|
80
|
-
published_at: string;
|
|
81
|
-
}[] = JSON.parse(chapMatch[1]);
|
|
82
|
-
info.chapters = chap.map((ele): IMangaChapter => {
|
|
83
|
-
return {
|
|
84
|
-
id: ele.name,
|
|
85
|
-
title: ele.title !== '' ? ele.title : `Chapter ${ele.name}`,
|
|
86
|
-
releaseDate: ele.published_at,
|
|
87
|
-
};
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return info;
|
|
91
|
-
} catch (err) {
|
|
92
|
-
throw new Error((err as Error).message);
|
|
93
|
-
}
|
|
89
|
+
const slug = encodeURIComponent(mangaId.replace(/^\/?(?:series|comics)\//, '').replace(/\/+$/, ''));
|
|
90
|
+
const [detail, list] = await Promise.all([
|
|
91
|
+
this.api<{ series: ApiSeries; recommended_series?: ApiSeries[] | null }>(`/series/${slug}`),
|
|
92
|
+
this.api<{ data: ApiChapter[] | null }>(`/series/${slug}/chapters`),
|
|
93
|
+
]);
|
|
94
|
+
// A 200 without the JSON the API normally sends (a challenge or error page) has no series.
|
|
95
|
+
const series = detail?.series;
|
|
96
|
+
if (!series?.slug) throw new Error(`AsuraScans: the API sent no series for "${mangaId}"`);
|
|
97
|
+
const seriesUrl = this.absolute(series.public_url);
|
|
98
|
+
const genres = (series.genres ?? []).map((genre) => genre.name?.trim()).filter(Boolean);
|
|
99
|
+
const authors = names(series.author);
|
|
100
|
+
const artists = names(series.artist);
|
|
101
|
+
|
|
102
|
+
// The API lists newest first; early-access chapters can't be read until they unlock.
|
|
103
|
+
const chapters = (list?.data ?? [])
|
|
104
|
+
.filter((chapter) => Number.isFinite(chapter.number) && !isLocked(chapter))
|
|
105
|
+
.reverse()
|
|
106
|
+
.map((chapter): IMangaChapter => {
|
|
107
|
+
const result: IMangaChapter = {
|
|
108
|
+
id: `${series.slug}/chapter/${chapter.number}`,
|
|
109
|
+
title: chapter.title?.replace(/\s+/g, ' ').trim() || `Chapter ${chapter.number}`,
|
|
110
|
+
chapterNumber: chapter.number,
|
|
111
|
+
};
|
|
112
|
+
const releaseDate = isoDate(chapter.published_at);
|
|
113
|
+
if (releaseDate) result.releaseDate = releaseDate;
|
|
114
|
+
if (seriesUrl) result.url = `${seriesUrl}/chapter/${chapter.number}`;
|
|
115
|
+
return result;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
const info: IMangaInfo = this.toResult(series);
|
|
119
|
+
if (genres.length > 0) info.genres = genres;
|
|
120
|
+
if (authors) info.authors = authors;
|
|
121
|
+
if (artists) info.artists = artists;
|
|
122
|
+
const recommendations = (detail.recommended_series ?? []).map((item) => this.toResult(item));
|
|
123
|
+
if (recommendations.length > 0) info.recommendations = recommendations;
|
|
124
|
+
info.chapters = sortChaptersForReading(chapters);
|
|
125
|
+
return info;
|
|
94
126
|
};
|
|
95
127
|
|
|
128
|
+
/** @param chapterId chapter id from `fetchMangaInfo` (`<slug>/chapter/<number>`) */
|
|
96
129
|
override fetchChapterPages = async (chapterId: string): Promise<IMangaChapterPage[]> => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
throw new Error((err as Error).message);
|
|
130
|
+
const match = /^\/?(?:(?:series|comics)\/)?([^/]+)\/chapters?\/([^/?#]+)\/?$/.exec(chapterId);
|
|
131
|
+
if (!match) throw new Error(`AsuraScans: invalid chapter id "${chapterId}"`);
|
|
132
|
+
const [, slug, number] = match;
|
|
133
|
+
const read = await this.api<{ data?: ApiChapterRead }>(
|
|
134
|
+
`/series/${encodeURIComponent(slug!)}/chapters/${encodeURIComponent(number!)}`
|
|
135
|
+
);
|
|
136
|
+
const data = read?.data;
|
|
137
|
+
if (!data) throw new Error(`AsuraScans: the API sent no chapter for "${chapterId}"`);
|
|
138
|
+
if (data.access_gate) throw new Error(`AsuraScans: chapter needs ${data.access_gate} on the site`);
|
|
139
|
+
if (data.is_locked) {
|
|
140
|
+
const until = data.unlock_time ? ` until ${data.unlock_time}` : '';
|
|
141
|
+
throw new Error(`AsuraScans: chapter is in early access${until}`);
|
|
110
142
|
}
|
|
143
|
+
const pages = (data.chapter?.pages ?? []).filter((page) => page?.url);
|
|
144
|
+
if (pages.length === 0) throw new Error('AsuraScans: chapter has no pages');
|
|
145
|
+
return pages.map((page, index): IMangaChapterPage => ({ page: index + 1, img: this.absolute(page.url)! }));
|
|
111
146
|
};
|
|
112
147
|
|
|
113
|
-
/**
|
|
114
|
-
|
|
115
|
-
* @param query Search query
|
|
116
|
-
*/
|
|
117
|
-
override search = async (query: string, page: number = 1): Promise<ISearch<IMangaResult>> => {
|
|
148
|
+
/** GET a path of the JSON API; failures carry the API's own error message. */
|
|
149
|
+
private async api<T>(path: string): Promise<T> {
|
|
118
150
|
try {
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
`${this.baseUrl}/series?page=${page}&name=${formattedQuery}`
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
const $: CheerioAPI = load(data);
|
|
125
|
-
const dom = $('html');
|
|
126
|
-
|
|
127
|
-
const results = dom
|
|
128
|
-
.find('.grid.grid-cols-2.gap-3.p-4 > a')
|
|
129
|
-
.map((index, ele): IMangaResult => {
|
|
130
|
-
return {
|
|
131
|
-
id: $(ele).attr('href') as string,
|
|
132
|
-
title: $(ele).find('div > div > div:nth-child(2) > span:nth-child(1)').text().trim() as string,
|
|
133
|
-
image: $(ele).find('div > div > div:nth-child(1) > img').attr('src') as string,
|
|
134
|
-
status: this.determineMediaState($(ele).find('div > div > div:nth-child(1) > span').text().trim()),
|
|
135
|
-
latestChapter: $(ele).find('div > div > div:nth-child(2) > span:nth-child(2)').text().trim(),
|
|
136
|
-
rating: $(ele).find('div > div > div:nth-child(2) > span:nth-child(3) > label').text().trim(),
|
|
137
|
-
};
|
|
138
|
-
})
|
|
139
|
-
.get();
|
|
140
|
-
|
|
141
|
-
const searchResults: ISearch<IMangaResult> = {
|
|
142
|
-
currentPage: page,
|
|
143
|
-
hasNextPage:
|
|
144
|
-
(dom.find('.flex.items-center.justify-center > a').attr('style') as string)
|
|
145
|
-
.split('pointer-events:')[1]!
|
|
146
|
-
.slice(1, -1) === 'auto'
|
|
147
|
-
? true
|
|
148
|
-
: false,
|
|
149
|
-
results: results,
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
return searchResults;
|
|
151
|
+
const { data } = await this.ctx.axios.get(`${API_URL}${path}`, { headers: { Accept: 'application/json' } });
|
|
152
|
+
return data as T;
|
|
153
153
|
} catch (err) {
|
|
154
|
-
|
|
154
|
+
const response = (err as { response?: { status?: number; data?: { error?: unknown } } }).response;
|
|
155
|
+
const reason = typeof response?.data?.error === 'string' ? response.data.error : (err as Error).message;
|
|
156
|
+
throw new Error(`AsuraScans: ${reason}${response?.status ? ` (${response.status})` : ''}`);
|
|
155
157
|
}
|
|
156
|
-
}
|
|
158
|
+
}
|
|
157
159
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
160
|
+
/** The fields search, info and recommendations share. */
|
|
161
|
+
private toResult(series: ApiSeries): IMangaResult {
|
|
162
|
+
const result: IMangaResult = { id: series.slug, title: series.title.trim() };
|
|
163
|
+
const altTitles = (series.alt_titles ?? []).map((title) => title?.trim()).filter(Boolean);
|
|
164
|
+
if (altTitles.length > 0) result.altTitles = altTitles;
|
|
165
|
+
const image = this.absolute(series.cover ?? series.cover_url);
|
|
166
|
+
if (image) result.image = image;
|
|
167
|
+
const url = this.absolute(series.public_url);
|
|
168
|
+
if (url) result.url = url;
|
|
169
|
+
const description = plainText(series.description);
|
|
170
|
+
if (description) result.description = description;
|
|
171
|
+
const status = mediaStatus(series.status);
|
|
172
|
+
if (status) result.status = status;
|
|
173
|
+
// Site extras: manga / manhwa / manhua, the 0-10 user rating, the newest chapter's number.
|
|
174
|
+
if (series.type) result.type = series.type;
|
|
175
|
+
if (series.rating) result.rating = Math.round(series.rating * 100) / 100;
|
|
176
|
+
const latestChapter = series.latest_chapters?.[0]?.number;
|
|
177
|
+
if (typeof latestChapter === 'number') result.latestChapter = latestChapter;
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private absolute(url: string | null | undefined): string | undefined {
|
|
182
|
+
if (!url) return undefined;
|
|
183
|
+
if (url.startsWith('//')) return `https:${url}`;
|
|
184
|
+
return url.startsWith('/') ? `${this.baseUrl}${url}` : url;
|
|
169
185
|
}
|
|
170
186
|
}
|
|
187
|
+
|
|
188
|
+
/** Early-access chapters stay locked until `early_access_until`, as the site's chapter list shows. */
|
|
189
|
+
const isLocked = (chapter: ApiChapter): boolean =>
|
|
190
|
+
chapter.early_access_until ? Date.parse(chapter.early_access_until) > Date.now() : chapter.is_premium === true;
|
|
191
|
+
|
|
192
|
+
const mediaStatus = (status: string | null | undefined): MediaStatus | undefined => {
|
|
193
|
+
switch (status?.toLowerCase().trim()) {
|
|
194
|
+
case 'ongoing':
|
|
195
|
+
return MediaStatus.ONGOING;
|
|
196
|
+
case 'completed':
|
|
197
|
+
return MediaStatus.COMPLETED;
|
|
198
|
+
case 'hiatus':
|
|
199
|
+
return MediaStatus.HIATUS;
|
|
200
|
+
case 'dropped':
|
|
201
|
+
case 'axed':
|
|
202
|
+
return MediaStatus.CANCELLED;
|
|
203
|
+
default:
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
/** `Ahn Soseol/ Sunghyun` or `Fit, Geonjin` → separate names; undefined when there are none. */
|
|
209
|
+
const names = (value: string | null | undefined): string[] | undefined => {
|
|
210
|
+
const list = (value ?? '')
|
|
211
|
+
.split(/[/,]/)
|
|
212
|
+
.map((name) => name.trim())
|
|
213
|
+
.filter(Boolean);
|
|
214
|
+
return list.length > 0 ? list : undefined;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/** The API's ISO timestamps, normalized; its zero date (`0001-01-01`) means none. */
|
|
218
|
+
const isoDate = (value: string | null | undefined): string | undefined => {
|
|
219
|
+
if (!value || value.startsWith('0001-')) return undefined;
|
|
220
|
+
const time = Date.parse(value);
|
|
221
|
+
return Number.isNaN(time) ? value : new Date(time).toISOString();
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/** The API's HTML synopsis as plain text, one paragraph per line. */
|
|
225
|
+
const plainText = (html: string | null | undefined): string | undefined => {
|
|
226
|
+
if (!html) return undefined;
|
|
227
|
+
const $ = load(html.replace(/<br\s*\/?>/gi, '\n').replace(/<\/p>/gi, '\n'));
|
|
228
|
+
const text = $.root()
|
|
229
|
+
.text()
|
|
230
|
+
.split('\n')
|
|
231
|
+
.map((line) => line.replace(/\s+/g, ' ').trim())
|
|
232
|
+
.filter(Boolean)
|
|
233
|
+
.join('\n');
|
|
234
|
+
return text || undefined;
|
|
235
|
+
};
|