-
Notifications
You must be signed in to change notification settings - Fork 543
Fix Westmanga: change template #8177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,123 @@ | ||
| import WordPressMangastream from './templates/WordPressMangastream.mjs'; | ||
|
|
||
| export default class WestManga extends WordPressMangastream { | ||
| import Connector from "../engine/Connector.mjs"; | ||
| import Manga from "../engine/Manga.mjs"; | ||
|
|
||
| export default class WestManga extends Connector { | ||
| constructor() { | ||
| super(); | ||
| super.id = 'westmanga'; | ||
| super.label = 'WestManga'; | ||
| this.tags = [ 'manga', 'indonesian' ]; | ||
| this.url = 'https://westmanga.me'; | ||
| this.path = '/manga/list-mode/'; | ||
| super.id = "westmanga"; | ||
| super.label = "WestManga"; | ||
| this.tags = ["manga", "manhua", "manhwa", "indonesian"]; | ||
| this.url = "https://westmanga.me"; | ||
| this.queryMangaTitle = "h1"; | ||
|
|
||
| // API configuration | ||
| this.api = { | ||
| url: "https://data.westmanga.me/api/", | ||
| nonce: "wm-api-request", | ||
| accessKey: "WM_WEB_FRONT_END", | ||
| secretKey: "xxxoidj", | ||
| }; | ||
| } | ||
|
|
||
| cleanTitle(title) { | ||
| return title.replace(/bahasa indonesia/i, "").trim(); | ||
| } | ||
|
|
||
| async _getMangas() { | ||
| const mangaList = []; | ||
| for (let page = 1; ; page++) { | ||
| const mangas = await this.getMangasFromPage(page); | ||
| if (mangas.length === 0) break; | ||
| mangaList.push(...mangas); | ||
| } | ||
| return mangaList; | ||
| } | ||
|
|
||
| async getMangasFromPage(page) { | ||
| const { data } = await this.fetchAPI(`./contents?page=${page}`); | ||
| return data | ||
| ? data.map(({ slug, title }) => ({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure that Hakuneko stable 6.1.7 is ok with the ? : syntax . Perhaps i am just too careful. |
||
| id: slug, | ||
| title: this.cleanTitle(title), | ||
| })) | ||
| : []; | ||
| } | ||
|
|
||
| async _getChapters(manga) { | ||
| const { | ||
| data: { chapters }, | ||
| } = await this.fetchAPI(`./comic/${manga.id}`); | ||
| return chapters.map(({ slug, number }) => { | ||
| let title = number.toString().trim(); | ||
| if (/^\d+(\.\d+)?$/.test(title)) { | ||
| title = `Chapter ${title}`; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefixing with chapter will lead to inconsistencies with haruneko and. .. can you explain what you are doing with the title? |
||
| } | ||
|
|
||
| return { | ||
| id: slug, | ||
| title: title, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| async _getPages(chapter) { | ||
| const { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inline this |
||
| data: { images }, | ||
| } = await this.fetchAPI(`./v/${chapter.id}`); | ||
|
|
||
| return images.map((img) => { | ||
| let url = typeof img === "string" ? img : img.url || img.source; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is that? is there something i missed in haruneko?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plus if img is a string how can it have an "url" property? |
||
| if (url && !url.match(/\.(jpe?g|png|webp)$/i)) { | ||
| url += "#.jpg"; | ||
| } | ||
| return url; | ||
| }); | ||
| } | ||
|
|
||
| async _getMangaFromURI(uri) { | ||
| const slug = uri.pathname.split("/").pop(); | ||
| const { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inline this |
||
| data: { title }, | ||
| } = await this.fetchAPI(`./comic/${slug}`); | ||
| return new Manga(this, slug, this.cleanTitle(title)); | ||
| } | ||
|
|
||
| async fetchAPI(endpoint) { | ||
| const url = new URL(endpoint, this.api.url); | ||
| const timestamp = `${Date.now()}`.slice(0, -3); | ||
|
|
||
| const signature = await this.generateHMAC256( | ||
| this.api.nonce, | ||
| timestamp, | ||
| "GET", | ||
| url.pathname, | ||
| this.api.accessKey, | ||
| this.api.secretKey, | ||
| ); | ||
|
|
||
| const request = new Request(url, { | ||
| ...this.requestOptions, | ||
| headers: { | ||
| ...this.requestOptions.headers, | ||
| Referer: this.url, | ||
| "X-Wm-Request-Time": timestamp, | ||
| "X-Wm-Accses-Key": this.api.accessKey, | ||
| "X-Wm-Request-Signature": signature, | ||
| }, | ||
| }); | ||
|
|
||
| return this.fetchJSON(request); | ||
| } | ||
|
|
||
| async generateHMAC256(data, ...keyData) { | ||
| const key = keyData.join(""); | ||
| const hash = CryptoJS.HmacSHA256(data, key); | ||
| return CryptoJS.enc.Hex.stringify(hash); | ||
| } | ||
|
|
||
| canHandleURI(uri) { | ||
| return new RegExp( | ||
| `^${this.url.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&")}/comic/[^/]+$`, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove canHandleURI entirely. We dont use such precise control in hakuneko. Plus that regexp is way too complex . |
||
| ).test(uri.href); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why using a class property for that ?