* 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
+34 -32
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 HotNovelPubMetadata {
id: string;
@@ -32,23 +32,23 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
this.name = metadata.sourceName;
this.icon = `multisrc/hotnovelpub/icons/${metadata.id}.png`;
this.site = metadata.sourceSite;
this.apiSite = metadata.sourceSite.replace("://", "://api.");
this.version = "1.0.0";
this.apiSite = metadata.sourceSite.replace('://', '://api.');
this.version = '1.0.0';
this.filters = metadata.filters;
this.lang = metadata.options?.lang || "en";
this.lang = metadata.options?.lang || 'en';
}
async popularNovels(
pageNo: number,
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
): Promise<Plugin.NovelItem[]> {
let url = this.apiSite + "/books/";
url += showLatestNovels ? "new" : filters?.sort?.value || "hot";
let url = this.apiSite + '/books/';
url += showLatestNovels ? 'new' : filters?.sort?.value || 'hot';
if (filters?.category?.value) {
url = this.apiSite + "/category/" + filters.category.value;
url = this.apiSite + '/category/' + filters.category.value;
}
url += "/?page=" + (pageNo - 1) + "&limit=20";
url += '/?page=' + (pageNo - 1) + '&limit=20';
const result = await fetchApi(url, {
headers: {
@@ -59,11 +59,11 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
const novels: Plugin.NovelItem[] = [];
if (json.status && json.data.books.data?.length) {
json.data.books.data.forEach((novel) =>
json.data.books.data.forEach(novel =>
novels.push({
name: novel.name,
cover: this.site + novel.image,
path: "/" + novel.slug,
path: '/' + novel.slug,
}),
);
}
@@ -71,7 +71,7 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const result = await fetchApi(this.apiSite + "/book" + novelPath, {
const result = await fetchApi(this.apiSite + '/book' + novelPath, {
headers: {
lang: this.lang,
},
@@ -85,13 +85,13 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
summary: json.data.book.authorize.description,
author: json.data.book.authorize.name,
status:
json.data.book.status === "updating"
json.data.book.status === 'updating'
? NovelStatus.Ongoing
: NovelStatus.Completed,
};
if (json.data.tags.tags_name?.length) {
novel.genres = json.data.tags.tags_name.join(",");
novel.genres = json.data.tags.tags_name.join(',');
}
if (json.data.chapters?.length) {
@@ -99,7 +99,7 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
json.data.chapters.forEach((chapter, chapterIndex) =>
chapters.push({
name: chapter.title,
path: "/" + chapter.slug,
path: '/' + chapter.slug,
releaseTime: undefined,
chapterNumber: (chapter.index || chapterIndex) + 1,
}),
@@ -111,50 +111,52 @@ class HotNovelPubPlugin implements Plugin.PluginBase {
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchApi(this.site + chapterPath).then((res) => res.text());
const body = await fetchApi(this.site + chapterPath).then(res =>
res.text(),
);
const loadedCheerio = parseHTML(body);
let chapterText = loadedCheerio("#content-item").html() || "";
let chapterText = loadedCheerio('#content-item').html() || '';
if (chapterText) {
const result = await fetchApi(
this.site + "/server/getContent?slug=" + chapterPath,
this.site + '/server/getContent?slug=' + chapterPath,
);
const json = (await result.json()) as ChapterType;
if (json.data) {
chapterText += json.data
.map((item) => "<p>" + item + "</p>")
.join("")
.replace(/\n/g, "</p><p>")
.replace(/\s/g, " ");
.map(item => '<p>' + item + '</p>')
.join('')
.replace(/\n/g, '</p><p>')
.replace(/\s/g, ' ');
}
}
return chapterText.replace(/\.copy right hot novel pub/g, "");
return chapterText.replace(/\.copy right hot novel pub/g, '');
}
async searchNovels(
searchTerm: string,
pageNo: number,
): Promise<Plugin.NovelItem[]> {
const result = await fetchApi(this.apiSite + "/search", {
const result = await fetchApi(this.apiSite + '/search', {
headers: {
"Content-Type": "application/json;charset=utf-8",
'Content-Type': 'application/json;charset=utf-8',
Referer: this.site,
Origin: this.site,
lang: this.lang,
},
method: "POST",
method: 'POST',
body: JSON.stringify({ key_search: searchTerm }),
});
const json = (await result.json()) as responseSearch;
const novels: Plugin.NovelItem[] = [];
if (json.status && json.data.books?.length) {
json.data.books.forEach((novel) =>
json.data.books.forEach(novel =>
novels.push({
name: novel.name,
cover: undefined,
path: "/" + novel.slug,
path: '/' + novel.slug,
}),
);
}