Skip to content
Closed
Changes from 3 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,

Check failure on line 40 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 16 spaces but found 20

Check failure on line 40 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 16 spaces but found 20
title: this.cleanTitle(title),

Check failure on line 41 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 16 spaces but found 20

Check failure on line 41 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 16 spaces but found 20
}))

Check failure on line 42 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 12 spaces but found 16

Check failure on line 42 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 12 spaces but found 16
: [];
}

async _getChapters(manga) {
const {
data: { chapters },

Check failure on line 48 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 12 spaces but found 16

Check failure on line 48 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 12 spaces but found 16
} = await this.fetchAPI(`./comic/${manga.id}`);

Check failure on line 49 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 8 spaces but found 12

Check failure on line 49 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 8 spaces but found 12
return chapters.map(({ slug, number }) => {

Check failure on line 50 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 8 spaces but found 12

Check failure on line 50 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 8 spaces but found 12
let title = number.toString().trim();

Check failure on line 51 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 12 spaces but found 16

Check failure on line 51 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 12 spaces but found 16
if (/^\d+(\.\d+)?$/.test(title)) {

Check failure on line 52 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 12 spaces but found 16

Check failure on line 52 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 12 spaces but found 16
title = `Chapter ${title}`;

Check failure on line 53 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 16 spaces but found 20

Check failure on line 53 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 16 spaces but found 20
}

Check failure on line 54 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 12 spaces but found 16

Check failure on line 54 in src/web/mjs/connectors/WestManga.mjs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Expected indentation of 12 spaces but found 16

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