Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 118 additions & 8 deletions src/web/mjs/connectors/WestManga.mjs
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";
Copy link
Contributor

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 ?


// 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 }) => ({
Copy link
Contributor

Choose a reason for hiding this comment

The 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}`;
Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is that? is there something i missed in haruneko?
Can you provide sample url?

Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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/[^/]+$`,
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}
}
Loading