react-native-consumet 2.0.0 → 3.0.1

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.
Files changed (211) hide show
  1. package/android/src/main/java/com/consumet/HttpRequestModule.kt +88 -33
  2. package/android/src/main/java/com/consumet/WebViewTask.kt +18 -3
  3. package/ios/Consumet.mm +172 -72
  4. package/lib/commonjs/NativeConsumet.ts +11 -5
  5. package/lib/commonjs/extension-registry.json +6 -6
  6. package/lib/commonjs/extension-registry.json.sig +1 -1
  7. package/lib/commonjs/extractors/kwik.js +28 -29
  8. package/lib/commonjs/extractors/kwik.js.map +1 -1
  9. package/lib/commonjs/index.js +18 -0
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/models/types.js +6 -0
  12. package/lib/commonjs/models/types.js.map +1 -1
  13. package/lib/commonjs/providers/anime/animepahe/create-animepahe.js +12 -13
  14. package/lib/commonjs/providers/anime/animepahe/create-animepahe.js.map +1 -1
  15. package/lib/commonjs/providers/manga/asurascans.js +160 -96
  16. package/lib/commonjs/providers/manga/asurascans.js.map +1 -1
  17. package/lib/commonjs/providers/manga/flamescans.js +173 -91
  18. package/lib/commonjs/providers/manga/flamescans.js.map +1 -1
  19. package/lib/commonjs/providers/manga/index.js +1 -15
  20. package/lib/commonjs/providers/manga/index.js.map +1 -1
  21. package/lib/commonjs/providers/manga/mangadex.js +234 -227
  22. package/lib/commonjs/providers/manga/mangadex.js.map +1 -1
  23. package/lib/commonjs/providers/manga/mangahere.js +279 -135
  24. package/lib/commonjs/providers/manga/mangahere.js.map +1 -1
  25. package/lib/commonjs/providers/manga/mangakakalot.js +206 -107
  26. package/lib/commonjs/providers/manga/mangakakalot.js.map +1 -1
  27. package/lib/commonjs/providers/manga/mangapill.js +126 -38
  28. package/lib/commonjs/providers/manga/mangapill.js.map +1 -1
  29. package/lib/commonjs/providers/meta/anilist.js +41 -12
  30. package/lib/commonjs/providers/meta/anilist.js.map +1 -1
  31. package/lib/commonjs/utils/index.js +19 -0
  32. package/lib/commonjs/utils/index.js.map +1 -1
  33. package/lib/commonjs/utils/manga.js +60 -0
  34. package/lib/commonjs/utils/manga.js.map +1 -0
  35. package/lib/module/NativeConsumet.ts +11 -5
  36. package/lib/module/extension-registry.json +6 -6
  37. package/lib/module/extension-registry.json.sig +1 -1
  38. package/lib/module/extractors/kwik.js +28 -29
  39. package/lib/module/extractors/kwik.js.map +1 -1
  40. package/lib/module/index.js +2 -2
  41. package/lib/module/index.js.map +1 -1
  42. package/lib/module/models/types.js +9 -0
  43. package/lib/module/models/types.js.map +1 -1
  44. package/lib/module/providers/anime/animepahe/create-animepahe.js +12 -13
  45. package/lib/module/providers/anime/animepahe/create-animepahe.js.map +1 -1
  46. package/lib/module/providers/manga/asurascans.js +161 -96
  47. package/lib/module/providers/manga/asurascans.js.map +1 -1
  48. package/lib/module/providers/manga/flamescans.js +174 -91
  49. package/lib/module/providers/manga/flamescans.js.map +1 -1
  50. package/lib/module/providers/manga/index.js +1 -15
  51. package/lib/module/providers/manga/index.js.map +1 -1
  52. package/lib/module/providers/manga/mangadex.js +236 -228
  53. package/lib/module/providers/manga/mangadex.js.map +1 -1
  54. package/lib/module/providers/manga/mangahere.js +276 -132
  55. package/lib/module/providers/manga/mangahere.js.map +1 -1
  56. package/lib/module/providers/manga/mangakakalot.js +207 -107
  57. package/lib/module/providers/manga/mangakakalot.js.map +1 -1
  58. package/lib/module/providers/manga/mangapill.js +128 -39
  59. package/lib/module/providers/manga/mangapill.js.map +1 -1
  60. package/lib/module/providers/meta/anilist.js +41 -12
  61. package/lib/module/providers/meta/anilist.js.map +1 -1
  62. package/lib/module/utils/index.js +1 -0
  63. package/lib/module/utils/index.js.map +1 -1
  64. package/lib/module/utils/manga.js +54 -0
  65. package/lib/module/utils/manga.js.map +1 -0
  66. package/lib/typescript/commonjs/src/NativeConsumet.d.ts +11 -5
  67. package/lib/typescript/commonjs/src/NativeConsumet.d.ts.map +1 -1
  68. package/lib/typescript/commonjs/src/extractors/kwik.d.ts +1 -1
  69. package/lib/typescript/commonjs/src/extractors/kwik.d.ts.map +1 -1
  70. package/lib/typescript/commonjs/src/index.d.ts +2 -2
  71. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  72. package/lib/typescript/commonjs/src/models/types.d.ts +38 -5
  73. package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
  74. package/lib/typescript/commonjs/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/src/providers/manga/asurascans.d.ts +14 -4
  76. package/lib/typescript/commonjs/src/providers/manga/asurascans.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/src/providers/manga/flamescans.d.ts +18 -3
  78. package/lib/typescript/commonjs/src/providers/manga/flamescans.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/src/providers/manga/index.d.ts +0 -14
  80. package/lib/typescript/commonjs/src/providers/manga/index.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/src/providers/manga/mangadex.d.ts +22 -5
  82. package/lib/typescript/commonjs/src/providers/manga/mangadex.d.ts.map +1 -1
  83. package/lib/typescript/commonjs/src/providers/manga/mangahere.d.ts +15 -3
  84. package/lib/typescript/commonjs/src/providers/manga/mangahere.d.ts.map +1 -1
  85. package/lib/typescript/commonjs/src/providers/manga/mangakakalot.d.ts +26 -4
  86. package/lib/typescript/commonjs/src/providers/manga/mangakakalot.d.ts.map +1 -1
  87. package/lib/typescript/commonjs/src/providers/manga/mangapill.d.ts +16 -2
  88. package/lib/typescript/commonjs/src/providers/manga/mangapill.d.ts.map +1 -1
  89. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
  90. package/lib/typescript/commonjs/src/utils/index.d.ts +1 -0
  91. package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -1
  92. package/lib/typescript/commonjs/src/utils/manga.d.ts +19 -0
  93. package/lib/typescript/commonjs/src/utils/manga.d.ts.map +1 -0
  94. package/lib/typescript/module/src/NativeConsumet.d.ts +11 -5
  95. package/lib/typescript/module/src/NativeConsumet.d.ts.map +1 -1
  96. package/lib/typescript/module/src/extractors/kwik.d.ts +1 -1
  97. package/lib/typescript/module/src/extractors/kwik.d.ts.map +1 -1
  98. package/lib/typescript/module/src/index.d.ts +2 -2
  99. package/lib/typescript/module/src/index.d.ts.map +1 -1
  100. package/lib/typescript/module/src/models/types.d.ts +38 -5
  101. package/lib/typescript/module/src/models/types.d.ts.map +1 -1
  102. package/lib/typescript/module/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
  103. package/lib/typescript/module/src/providers/manga/asurascans.d.ts +14 -4
  104. package/lib/typescript/module/src/providers/manga/asurascans.d.ts.map +1 -1
  105. package/lib/typescript/module/src/providers/manga/flamescans.d.ts +18 -3
  106. package/lib/typescript/module/src/providers/manga/flamescans.d.ts.map +1 -1
  107. package/lib/typescript/module/src/providers/manga/index.d.ts +0 -14
  108. package/lib/typescript/module/src/providers/manga/index.d.ts.map +1 -1
  109. package/lib/typescript/module/src/providers/manga/mangadex.d.ts +22 -5
  110. package/lib/typescript/module/src/providers/manga/mangadex.d.ts.map +1 -1
  111. package/lib/typescript/module/src/providers/manga/mangahere.d.ts +15 -3
  112. package/lib/typescript/module/src/providers/manga/mangahere.d.ts.map +1 -1
  113. package/lib/typescript/module/src/providers/manga/mangakakalot.d.ts +26 -4
  114. package/lib/typescript/module/src/providers/manga/mangakakalot.d.ts.map +1 -1
  115. package/lib/typescript/module/src/providers/manga/mangapill.d.ts +16 -2
  116. package/lib/typescript/module/src/providers/manga/mangapill.d.ts.map +1 -1
  117. package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
  118. package/lib/typescript/module/src/utils/index.d.ts +1 -0
  119. package/lib/typescript/module/src/utils/index.d.ts.map +1 -1
  120. package/lib/typescript/module/src/utils/manga.d.ts +19 -0
  121. package/lib/typescript/module/src/utils/manga.d.ts.map +1 -0
  122. package/package.json +1 -1
  123. package/src/NativeConsumet.ts +11 -5
  124. package/src/extension-registry.json +6 -6
  125. package/src/extension-registry.json.sig +1 -1
  126. package/src/extractors/kwik.ts +30 -43
  127. package/src/index.tsx +6 -0
  128. package/src/models/types.ts +38 -3
  129. package/src/providers/anime/animepahe/create-animepahe.ts +15 -14
  130. package/src/providers/manga/asurascans.ts +200 -135
  131. package/src/providers/manga/flamescans.ts +221 -118
  132. package/src/providers/manga/index.ts +0 -14
  133. package/src/providers/manga/mangadex.ts +335 -282
  134. package/src/providers/manga/mangahere.ts +309 -156
  135. package/src/providers/manga/mangakakalot.ts +249 -152
  136. package/src/providers/manga/mangapill.ts +163 -64
  137. package/src/providers/meta/anilist.ts +50 -14
  138. package/src/utils/index.ts +1 -0
  139. package/src/utils/manga.ts +58 -0
  140. package/lib/commonjs/providers/manga/brmangas.js +0 -110
  141. package/lib/commonjs/providers/manga/brmangas.js.map +0 -1
  142. package/lib/commonjs/providers/manga/comick.js +0 -154
  143. package/lib/commonjs/providers/manga/comick.js.map +0 -1
  144. package/lib/commonjs/providers/manga/mangahost.js +0 -113
  145. package/lib/commonjs/providers/manga/mangahost.js.map +0 -1
  146. package/lib/commonjs/providers/manga/mangapark.js +0 -97
  147. package/lib/commonjs/providers/manga/mangapark.js.map +0 -1
  148. package/lib/commonjs/providers/manga/mangareader.js +0 -106
  149. package/lib/commonjs/providers/manga/mangareader.js.map +0 -1
  150. package/lib/commonjs/providers/manga/mangasee123.js +0 -161
  151. package/lib/commonjs/providers/manga/mangasee123.js.map +0 -1
  152. package/lib/commonjs/providers/manga/readmanga.js +0 -269
  153. package/lib/commonjs/providers/manga/readmanga.js.map +0 -1
  154. package/lib/commonjs/providers/manga/vyvymanga.js +0 -166
  155. package/lib/commonjs/providers/manga/vyvymanga.js.map +0 -1
  156. package/lib/module/providers/manga/brmangas.js +0 -105
  157. package/lib/module/providers/manga/brmangas.js.map +0 -1
  158. package/lib/module/providers/manga/comick.js +0 -149
  159. package/lib/module/providers/manga/comick.js.map +0 -1
  160. package/lib/module/providers/manga/mangahost.js +0 -108
  161. package/lib/module/providers/manga/mangahost.js.map +0 -1
  162. package/lib/module/providers/manga/mangapark.js +0 -92
  163. package/lib/module/providers/manga/mangapark.js.map +0 -1
  164. package/lib/module/providers/manga/mangareader.js +0 -101
  165. package/lib/module/providers/manga/mangareader.js.map +0 -1
  166. package/lib/module/providers/manga/mangasee123.js +0 -156
  167. package/lib/module/providers/manga/mangasee123.js.map +0 -1
  168. package/lib/module/providers/manga/readmanga.js +0 -264
  169. package/lib/module/providers/manga/readmanga.js.map +0 -1
  170. package/lib/module/providers/manga/vyvymanga.js +0 -161
  171. package/lib/module/providers/manga/vyvymanga.js.map +0 -1
  172. package/lib/typescript/commonjs/src/providers/manga/brmangas.d.ts +0 -18
  173. package/lib/typescript/commonjs/src/providers/manga/brmangas.d.ts.map +0 -1
  174. package/lib/typescript/commonjs/src/providers/manga/comick.d.ts +0 -39
  175. package/lib/typescript/commonjs/src/providers/manga/comick.d.ts.map +0 -1
  176. package/lib/typescript/commonjs/src/providers/manga/mangahost.d.ts +0 -18
  177. package/lib/typescript/commonjs/src/providers/manga/mangahost.d.ts.map +0 -1
  178. package/lib/typescript/commonjs/src/providers/manga/mangapark.d.ts +0 -14
  179. package/lib/typescript/commonjs/src/providers/manga/mangapark.d.ts.map +0 -1
  180. package/lib/typescript/commonjs/src/providers/manga/mangareader.d.ts +0 -18
  181. package/lib/typescript/commonjs/src/providers/manga/mangareader.d.ts.map +0 -1
  182. package/lib/typescript/commonjs/src/providers/manga/mangasee123.d.ts +0 -17
  183. package/lib/typescript/commonjs/src/providers/manga/mangasee123.d.ts.map +0 -1
  184. package/lib/typescript/commonjs/src/providers/manga/readmanga.d.ts +0 -31
  185. package/lib/typescript/commonjs/src/providers/manga/readmanga.d.ts.map +0 -1
  186. package/lib/typescript/commonjs/src/providers/manga/vyvymanga.d.ts +0 -17
  187. package/lib/typescript/commonjs/src/providers/manga/vyvymanga.d.ts.map +0 -1
  188. package/lib/typescript/module/src/providers/manga/brmangas.d.ts +0 -18
  189. package/lib/typescript/module/src/providers/manga/brmangas.d.ts.map +0 -1
  190. package/lib/typescript/module/src/providers/manga/comick.d.ts +0 -39
  191. package/lib/typescript/module/src/providers/manga/comick.d.ts.map +0 -1
  192. package/lib/typescript/module/src/providers/manga/mangahost.d.ts +0 -18
  193. package/lib/typescript/module/src/providers/manga/mangahost.d.ts.map +0 -1
  194. package/lib/typescript/module/src/providers/manga/mangapark.d.ts +0 -14
  195. package/lib/typescript/module/src/providers/manga/mangapark.d.ts.map +0 -1
  196. package/lib/typescript/module/src/providers/manga/mangareader.d.ts +0 -18
  197. package/lib/typescript/module/src/providers/manga/mangareader.d.ts.map +0 -1
  198. package/lib/typescript/module/src/providers/manga/mangasee123.d.ts +0 -17
  199. package/lib/typescript/module/src/providers/manga/mangasee123.d.ts.map +0 -1
  200. package/lib/typescript/module/src/providers/manga/readmanga.d.ts +0 -31
  201. package/lib/typescript/module/src/providers/manga/readmanga.d.ts.map +0 -1
  202. package/lib/typescript/module/src/providers/manga/vyvymanga.d.ts +0 -17
  203. package/lib/typescript/module/src/providers/manga/vyvymanga.d.ts.map +0 -1
  204. package/src/providers/manga/brmangas.ts +0 -148
  205. package/src/providers/manga/comick.ts +0 -285
  206. package/src/providers/manga/mangahost.ts +0 -134
  207. package/src/providers/manga/mangapark.ts +0 -115
  208. package/src/providers/manga/mangareader.ts +0 -132
  209. package/src/providers/manga/mangasee123.ts +0 -187
  210. package/src/providers/manga/readmanga.ts +0 -380
  211. package/src/providers/manga/vyvymanga.ts +0 -237
@@ -1,4 +1,4 @@
1
- import { type CheerioAPI, load } from 'cheerio';
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 type { AxiosResponse } from 'axios';
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://asuracomic.net';
19
- protected override logo = 'https://asuracomic.net/images/logo.png';
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
- try {
29
- const { data }: AxiosResponse = await this.ctx.axios.get(`${this.baseUrl}/${mangaId}`);
30
- const $: CheerioAPI = load(data);
31
-
32
- const dom = $('html');
33
- const topInfoWrapper = dom.find('.relative.col-span-12.space-y-3.px-6');
34
-
35
- const info: IMangaInfo = {
36
- id: mangaId,
37
- title: dom.find('.text-xl.font-bold:nth-child(1)').text().trim(),
38
- image: $(topInfoWrapper).find('img').attr('src'),
39
- rating: $(topInfoWrapper).find('div > div.px-2.py-1 > p').text().trim(),
40
- status: this.determineMediaState(
41
- $(topInfoWrapper).find('div > div.flex.flex-row > div:nth-child(1) > h3:nth-child(2)').text().trim()
42
- ),
43
- description: dom.find('span.font-medium.text-sm').text().trim(),
44
- authors: dom
45
- .find('.grid.grid-cols-1.gap-5.mt-8 > div:nth-child(2) > h3:nth-child(2)')
46
- .text()
47
- .trim()
48
- .split('/')
49
- .map((ele) => ele.trim()),
50
- artist: dom.find('.grid.grid-cols-1.gap-5.mt-8 > div:nth-child(3) > h3:nth-child(2)').text().trim(),
51
- updatedOn: dom.find('.grid.grid-cols-1.gap-5.mt-8 > div:nth-child(5) > h3:nth-child(2)').text().trim(),
52
- genres: dom
53
- .find('.space-y-1.pt-4 > div > button')
54
- .map((index, ele) => $(ele).text().trim())
55
- .get(),
56
- recommendations: dom
57
- .find('.grid.grid-cols-2.gap-3.p-4 > a')
58
- .map((index, ele): IMangaResult => {
59
- return {
60
- id: $(ele).attr('href') as string,
61
- title: $(ele).find('div > h2.font-bold').text().trim(),
62
- image: $(ele).find('div > div > img').attr('src'),
63
- latestChapter: $(ele).find('div > h2:nth-child(3)').text().trim(),
64
- status: this.determineMediaState($(ele).find('div > div:nth-child(1) > span').text().trim()),
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
- try {
98
- const { data }: AxiosResponse = await this.ctx.axios.get(`${this.baseUrl}/series/${chapterId}`);
99
- const chapMatch = data.replace(/\\/g, '').match(/pages.*:(\[{['"]order["'].*?}\])/);
100
- if (!chapMatch) throw new Error('Parsing error');
101
- const chap: { order: string; url: string }[] = JSON.parse(chapMatch[1]);
102
- return chap.map(
103
- (page, index): IMangaChapterPage => ({
104
- page: index + 1,
105
- img: page.url,
106
- })
107
- );
108
- } catch (err) {
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 formattedQuery = encodeURI(query.toLowerCase());
120
- const { data }: AxiosResponse = await this.ctx.axios.get(
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
- throw new Error((err as Error).message);
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
- private determineMediaState(state: string): MediaStatus {
159
- switch (state.toLowerCase().trim()) {
160
- case 'completed':
161
- return MediaStatus.COMPLETED;
162
- case 'ongoing':
163
- return MediaStatus.ONGOING;
164
- case 'dropped':
165
- return MediaStatus.CANCELLED;
166
- default:
167
- return MediaStatus.UNKNOWN;
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
+ };