* 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
+43 -43
View File
@@ -1,43 +1,43 @@
import { Plugin } from "@typings/plugin";
import { FilterTypes, Filters } from "@libs/filterInputs";
import { defaultCover } from "@libs/defaultCover";
import { fetchApi, fetchFile } from "@libs/fetch";
import { NovelStatus } from "@libs/novelStatus";
import { load as parseHTML } from "cheerio";
import dayjs from "dayjs";
import { Plugin } from '@typings/plugin';
import { FilterTypes, Filters } from '@libs/filterInputs';
import { defaultCover } from '@libs/defaultCover';
import { fetchApi, fetchFile } from '@libs/fetch';
import { NovelStatus } from '@libs/novelStatus';
import { load as parseHTML } from 'cheerio';
import dayjs from 'dayjs';
class RNRF implements Plugin.PluginBase {
id = "RNRF";
name = "РанобэРФ";
site = "https://ранобэ.рф";
version = "1.0.0";
icon = "src/ru/ranoberf/icon.png";
id = 'RNRF';
name = 'РанобэРФ';
site = 'https://ранобэ.рф';
version = '1.0.0';
icon = 'src/ru/ranoberf/icon.png';
async popularNovels(
pageNo: number,
{ showLatestNovels, filters }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
let url = this.site + "/books?order=";
let url = this.site + '/books?order=';
url += showLatestNovels
? "lastPublishedChapter"
: filters?.sort?.value || "popular";
url += "&page=" + pageNo;
? 'lastPublishedChapter'
: filters?.sort?.value || 'popular';
url += '&page=' + pageNo;
const result = await fetchApi(url);
const body = await result.text();
const loadedCheerio = parseHTML(body);
const jsonRaw = loadedCheerio("#__NEXT_DATA__").html();
const json: response = JSON.parse(jsonRaw || "{}");
const jsonRaw = loadedCheerio('#__NEXT_DATA__').html();
const json: response = JSON.parse(jsonRaw || '{}');
const novels: Plugin.NovelItem[] = [];
json.props.pageProps?.totalData?.items?.forEach((novel) =>
json.props.pageProps?.totalData?.items?.forEach(novel =>
novels.push({
name: novel.title,
cover: novel?.verticalImage?.url
? this.site + novel.verticalImage.url
: defaultCover,
path: "/" + novel.slug,
path: '/' + novel.slug,
}),
);
@@ -49,19 +49,19 @@ class RNRF implements Plugin.PluginBase {
const body = await result.text();
const loadedCheerio = parseHTML(body);
const jsonRaw = loadedCheerio("#__NEXT_DATA__").html();
const book = (JSON.parse(jsonRaw || "{}") as response).props.pageProps.book;
const jsonRaw = loadedCheerio('#__NEXT_DATA__').html();
const book = (JSON.parse(jsonRaw || '{}') as response).props.pageProps.book;
const novel: Plugin.SourceNovel = {
path: novelPath,
name: book?.title || "",
name: book?.title || '',
cover: book?.verticalImage?.url
? this.site + book.verticalImage.url
: defaultCover,
summary: book?.description,
author: book?.author || "",
genres: book?.genres.map((item) => item.title).join(", "),
status: book?.additionalInfo.includes("Активен")
author: book?.author || '',
genres: book?.genres.map(item => item.title).join(', '),
status: book?.additionalInfo.includes('Активен')
? NovelStatus.Ongoing
: NovelStatus.Completed,
};
@@ -73,7 +73,7 @@ class RNRF implements Plugin.PluginBase {
chapters.push({
name: chapter.title,
path: chapter.url,
releaseTime: dayjs(chapter.publishedAt).format("LLL"),
releaseTime: dayjs(chapter.publishedAt).format('LLL'),
chapterNumber: book.chapters.length - chapterIndex,
});
}
@@ -84,22 +84,22 @@ class RNRF implements Plugin.PluginBase {
}
async parseChapter(chapterPath: string): Promise<string> {
const result = await fetchApi(this.site + chapterPath).then((res) =>
const result = await fetchApi(this.site + chapterPath).then(res =>
res.text(),
);
let loadedCheerio = parseHTML(result);
const jsonRaw = loadedCheerio("#__NEXT_DATA__").html();
const json: response = JSON.parse(jsonRaw || "{}");
const jsonRaw = loadedCheerio('#__NEXT_DATA__').html();
const json: response = JSON.parse(jsonRaw || '{}');
loadedCheerio = parseHTML(
json.props.pageProps?.chapter?.content?.text || "",
json.props.pageProps?.chapter?.content?.text || '',
);
loadedCheerio("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('img').each((index, element) => {
if (!loadedCheerio(element).attr('src')?.startsWith('http')) {
const src = loadedCheerio(element).attr('src');
loadedCheerio(element).attr('src', this.site + src);
}
});
@@ -113,13 +113,13 @@ class RNRF implements Plugin.PluginBase {
const body = (await result.json()) as { items: Item[] };
const novels: Plugin.NovelItem[] = [];
body.items.forEach((novel) =>
body.items.forEach(novel =>
novels.push({
name: novel.title,
cover: novel?.verticalImage?.url
? this.site + novel.verticalImage.url
: defaultCover,
path: "/" + novel.slug,
path: '/' + novel.slug,
}),
);
@@ -130,13 +130,13 @@ class RNRF implements Plugin.PluginBase {
filters = {
sort: {
label: "Сортировка",
value: "popular",
label: 'Сортировка',
value: 'popular',
options: [
{ label: "Рейтинг", value: "popular" },
{ label: "Дате добавления", value: "new" },
{ label: "Дате обновления", value: "lastPublishedChapter" },
{ label: "Законченные", value: "completed" },
{ label: 'Рейтинг', value: 'popular' },
{ label: 'Дате добавления', value: 'new' },
{ label: 'Дате обновления', value: 'lastPublishedChapter' },
{ label: 'Законченные', value: 'completed' },
],
type: FilterTypes.Picker,
},