plugin-books-pro
Version:
[](https://badge.fury.io/js/plugin-books-pro)
108 lines (107 loc) • 4.44 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const t2_browser_worker_1 = require("t2-browser-worker");
const base_1 = require("../models/base");
class Metruyencv extends base_1.BaseBook {
constructor() {
super(...arguments);
this.API_ENDPOINTS = {
RANKING: (month, year, type) => `https://backend.${this.domain}/api/books/ranking?gender=1&kind=1&limit=${this.LIMIT_ITEMS}&month=${month}&page=1&type=${type}&year=${year}`,
NEW: `https://backend.${this.domain}/api/books?filter[gender]=1&filter[state]=published&include=author,genres,creator&limit=${this.LIMIT_ITEMS}&page=1&sort=-new_chap_at`
};
}
getCurrentDate() {
const date = new Date();
return {
month: date.getMonth() + 1,
year: date.getFullYear()
};
}
passLogin(page) {
return __awaiter(this, void 0, void 0, function* () {
yield page.setExtraHTTPHeaders({
"User-Agent": "Googlebot/2.1 (+http://www.google.com/bot.html)",
});
yield page.goto(this.baseUrl, { waitUntil: "domcontentloaded" });
});
}
transformBookData(book, index) {
var _a;
const bookData = book.book || book;
return {
rank: index + 1,
identifier: this.getIdentifier(bookData.name),
name: bookData.name,
link: bookData.link,
imageUrlThumbnail: bookData.poster.default,
view: bookData.view_count,
like: bookData.like_count,
comment: bookData.comment_count,
follow: bookData.bookmark_count,
author: (_a = bookData.author) === null || _a === void 0 ? void 0 : _a.name,
tags: bookData.genres.map((item) => item.name).join(","),
description: bookData.synopsis,
};
}
getInfoABook(page, url, dataType) {
return __awaiter(this, void 0, void 0, function* () {
const result = {
dataType,
data: [],
status: "SUCCESS",
};
try {
const res = yield (0, t2_browser_worker_1.usePageFetch)(page, url);
result.data = res.data.map((book, index) => this.transformBookData(book, index));
}
catch (error) {
console.error(`Error fetching ${dataType}:`, error);
result.status = "ERROR";
}
return result;
});
}
getTop(page) {
return __awaiter(this, void 0, void 0, function* () {
const { month, year } = this.getCurrentDate();
return this.getInfoABook(page, this.API_ENDPOINTS.RANKING(month, year, 'view'), "Top");
});
}
getNew(page) {
return __awaiter(this, void 0, void 0, function* () {
return this.getInfoABook(page, this.API_ENDPOINTS.NEW, "New");
});
}
getFavorite(page) {
return __awaiter(this, void 0, void 0, function* () {
const { month, year } = this.getCurrentDate();
return this.getInfoABook(page, this.API_ENDPOINTS.RANKING(month, year, 'vote'), "Favorite");
});
}
crawl(page) {
const _super = Object.create(null, {
crawl: { get: () => super.crawl }
});
return __awaiter(this, void 0, void 0, function* () {
(0, t2_browser_worker_1.useBlockResource)(page, [
"image",
"media",
"font",
"script",
"stylesheet",
]);
yield this.passLogin(page);
return _super.crawl.call(this, page);
});
}
}
exports.default = Metruyencv;