* add prettier

* lint-staged

* prettier

* upgrade husky
This commit is contained in:
nyagami
2024-03-23 22:00:29 +07:00
committed by GitHub
parent c22979b10f
commit 5f9a067ab9
113 changed files with 79244 additions and 50841 deletions
+78 -74
View File
@@ -1,9 +1,9 @@
import { fetchFile, fetchApi } from "@libs/fetch";
import { Filters, FilterTypes } from "@libs/filterInputs";
import { Plugin } from "@typings/plugin";
import { NovelStatus } from "@libs/novelStatus";
import { load as parseHTML } from "cheerio";
import dayjs from "dayjs";
import { fetchFile, fetchApi } from '@libs/fetch';
import { Filters, FilterTypes } from '@libs/filterInputs';
import { Plugin } from '@typings/plugin';
import { NovelStatus } from '@libs/novelStatus';
import { load as parseHTML } from 'cheerio';
import dayjs from 'dayjs';
export interface RulateMetadata {
id: string;
@@ -25,7 +25,7 @@ class RulatePlugin implements Plugin.PluginBase {
this.name = metadata.sourceName;
this.icon = `multisrc/rulate/icons/${metadata.id}.png`;
this.site = metadata.sourceSite;
this.version = "1.0.0";
this.version = '1.0.0';
this.filters = metadata.filters;
}
@@ -34,35 +34,37 @@ class RulatePlugin implements Plugin.PluginBase {
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
let url = this.site + "/search?t=";
url += "&cat=" + (filters?.cat?.value || "0");
url += "&s_lang=" + (filters?.s_lang?.value || "0");
url += "&t_lang=" + (filters?.t_lang?.value || "0");
url += "&type=" + (filters?.type?.value || "0");
url += "&sort=" + (showLatestNovels ? "4" : filters?.sort?.value || "6");
url += "&atmosphere=" + (filters?.atmosphere?.value || "0");
url += "&adult=" + (filters?.adult?.value || "0");
let url = this.site + '/search?t=';
url += '&cat=' + (filters?.cat?.value || '0');
url += '&s_lang=' + (filters?.s_lang?.value || '0');
url += '&t_lang=' + (filters?.t_lang?.value || '0');
url += '&type=' + (filters?.type?.value || '0');
url += '&sort=' + (showLatestNovels ? '4' : filters?.sort?.value || '6');
url += '&atmosphere=' + (filters?.atmosphere?.value || '0');
url += '&adult=' + (filters?.adult?.value || '0');
Object.entries(filters || {}).forEach(([type, { value }]) => {
if (value instanceof Array && value.length) {
url += "&" + value
.map((val) => (type == "extra" ? val + "=1" : type + "[]=" + val))
.join("&");
url +=
'&' +
value
.map(val => (type == 'extra' ? val + '=1' : type + '[]=' + val))
.join('&');
}
});
url += "&Book_page=" + pageNo;
url += '&Book_page=' + pageNo;
const body = await fetchApi(url).then((res) => res.text());
const body = await fetchApi(url).then(res => res.text());
const loadedCheerio = parseHTML(body);
loadedCheerio(
'ul[class="search-results"] > li:not([class="ad_type_catalog"])',
).each((index, element) => {
loadedCheerio(element).find("p > a").text();
const name = loadedCheerio(element).find("p > a").text();
const cover = loadedCheerio(element).find("img").attr("src");
const path = loadedCheerio(element).find("p > a").attr("href");
loadedCheerio(element).find('p > a').text();
const name = loadedCheerio(element).find('p > a').text();
const cover = loadedCheerio(element).find('img').attr('src');
const path = loadedCheerio(element).find('p > a').attr('href');
if (!name || !path) return;
novels.push({ name, cover: this.site + cover, path });
@@ -73,13 +75,13 @@ class RulatePlugin implements Plugin.PluginBase {
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
let result = await fetchApi(this.site + novelPath);
if (result.url.includes("mature?path=")) {
if (result.url.includes('mature?path=')) {
const formData = new FormData();
formData.append("path", novelPath);
formData.append("ok", "Да");
formData.append('path', novelPath);
formData.append('ok', 'Да');
await fetchApi(result.url, {
method: "POST",
method: 'POST',
body: formData,
});
@@ -96,41 +98,41 @@ class RulatePlugin implements Plugin.PluginBase {
.text()
.trim(),
};
if (novel.name?.includes?.("[")) {
novel.name = novel.name.split("[")[0].trim();
if (novel.name?.includes?.('[')) {
novel.name = novel.name.split('[')[0].trim();
}
novel.cover =
this.site + loadedCheerio('div[class="images"] > div img').attr("src");
novel.summary = loadedCheerio("#Info > div:nth-child(3), .book-description")
this.site + loadedCheerio('div[class="images"] > div img').attr('src');
novel.summary = loadedCheerio('#Info > div:nth-child(3), .book-description')
.text()
.trim();
novel.author = loadedCheerio(
".book-stats-icons_author > span:nth-child(2) > a:nth-child(1)",
'.book-stats-icons_author > span:nth-child(2) > a:nth-child(1)',
).text();
const genres: string[] = [];
loadedCheerio("div.span5 > p, .span5 > div:nth-child(2) > p").each(
loadedCheerio('div.span5 > p, .span5 > div:nth-child(2) > p').each(
function () {
switch (loadedCheerio(this).find("strong").text()) {
case "Автор:":
novel.author = loadedCheerio(this).find("em > a").text().trim();
switch (loadedCheerio(this).find('strong').text()) {
case 'Автор:':
novel.author = loadedCheerio(this).find('em > a').text().trim();
break;
case "Выпуск:":
case 'Выпуск:':
novel.status =
loadedCheerio(this).find("em").text().trim() === "продолжается"
loadedCheerio(this).find('em').text().trim() === 'продолжается'
? NovelStatus.Ongoing
: NovelStatus.Completed;
break;
case "Тэги:":
case 'Тэги:':
loadedCheerio(this)
.find("em > a")
.find('em > a')
.each(function () {
genres.push(loadedCheerio(this).text());
});
break;
case "Жанры:":
case 'Жанры:':
loadedCheerio(this)
.find("em > a")
.find('em > a')
.each(function () {
genres.push(loadedCheerio(this).text());
});
@@ -140,23 +142,23 @@ class RulatePlugin implements Plugin.PluginBase {
);
if (genres.length) {
novel.genres = genres.reverse().join(",");
novel.genres = genres.reverse().join(',');
}
const chapters: Plugin.ChapterItem[] = [];
loadedCheerio("table > tbody > tr.chapter_row").each(
loadedCheerio('table > tbody > tr.chapter_row').each(
(chapterIndex, element) => {
const chapterName = loadedCheerio(element)
.find('td[class="t"] > a')
.text()
.trim();
const releaseDate = loadedCheerio(element)
.find("td > span")
.attr("title")
.find('td > span')
.attr('title')
?.trim();
const chapterUrl = loadedCheerio(element)
.find('td[class="t"] > a')
.attr("href");
.attr('href');
if (
!loadedCheerio(element).find('td > span[class="disabled"]').length &&
@@ -179,12 +181,12 @@ class RulatePlugin implements Plugin.PluginBase {
async parseChapter(chapterPath: string): Promise<string> {
let result = await fetchApi(this.site + chapterPath);
if (result.url.includes("mature?path=")) {
if (result.url.includes('mature?path=')) {
const formData = new FormData();
formData.append("ok", "Да");
formData.append('ok', 'Да');
await fetchApi(result.url, {
method: "POST",
method: 'POST',
body: formData,
});
@@ -193,26 +195,26 @@ class RulatePlugin implements Plugin.PluginBase {
const body = await result.text();
const loadedCheerio = parseHTML(body);
loadedCheerio(".content-text img").each((index, element) => {
if (!loadedCheerio(element).attr("src")?.startsWith("http")) {
const src = loadedCheerio(element).attr("src");
loadedCheerio(element).attr("src", this.site + src);
loadedCheerio('.content-text img').each((index, element) => {
if (!loadedCheerio(element).attr('src')?.startsWith('http')) {
const src = loadedCheerio(element).attr('src');
loadedCheerio(element).attr('src', this.site + src);
}
});
const chapterText = loadedCheerio(".content-text").html();
return chapterText || "";
const chapterText = loadedCheerio('.content-text').html();
return chapterText || '';
}
async searchNovels(searchTerm: string): Promise<Plugin.NovelItem[]> {
const novels: Plugin.NovelItem[] = [];
const result = await fetchApi(
this.site + "/search/autocomplete?query=" + searchTerm,
this.site + '/search/autocomplete?query=' + searchTerm,
);
const json = (await result.json()) as response[];
json.forEach((novel) => {
const name = novel.title_one + " / " + novel.title_two;
json.forEach(novel => {
const name = novel.title_one + ' / ' + novel.title_two;
if (!novel.url) return;
novels.push({
@@ -225,24 +227,26 @@ class RulatePlugin implements Plugin.PluginBase {
return novels;
}
parseDate = (dateString: string | undefined = "") => {
parseDate = (dateString: string | undefined = '') => {
const months: { [key: string]: number } = {
"янв.": 1,
"февр.": 2,
"мар.": 3,
"апр.": 4,
'янв.': 1,
'февр.': 2,
'мар.': 3,
'апр.': 4,
мая: 5,
"июн.": 6,
"июл.": 7,
"авг.": 8,
"сент.": 9,
"окт.": 10,
"нояб.": 11,
"дек.": 12,
'июн.': 6,
'июл.': 7,
'авг.': 8,
'сент.': 9,
'окт.': 10,
'нояб.': 11,
'дек.': 12,
};
const [day, month, year, , time] = dateString.split(" ");
const [day, month, year, , time] = dateString.split(' ');
if (day && months[month] && year && time) {
return dayjs(year + "-" + months[month] + "-" + day + " " + time).format("LLL");
return dayjs(year + '-' + months[month] + '-' + day + ' ' + time).format(
'LLL',
);
}
return dateString || null;
};