* 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
+100 -97
View File
@@ -1,61 +1,64 @@
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 { 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';
const statusKey: { [key: string]: string } = {
"0": NovelStatus.Unknown,
"1": NovelStatus.Ongoing,
"2": NovelStatus.Completed,
"3": NovelStatus.OnHiatus,
"4": NovelStatus.Cancelled,
'0': NovelStatus.Unknown,
'1': NovelStatus.Ongoing,
'2': NovelStatus.Completed,
'3': NovelStatus.OnHiatus,
'4': NovelStatus.Cancelled,
};
class Neobook implements Plugin.PluginBase {
id = "neobook";
name = "Neobook";
site = "https://neobook.org";
version = "1.0.0";
icon = "src/ru/neobook/icon.png";
id = 'neobook';
name = 'Neobook';
site = 'https://neobook.org';
version = '1.0.0';
icon = 'src/ru/neobook/icon.png';
async fetchNovels(
page: number,
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions<typeof this.filters>,
{
filters,
showLatestNovels,
}: Plugin.PopularNovelsOptions<typeof this.filters>,
searchTerm?: string,
): Promise<Plugin.NovelItem[]> {
const formData = new FormData();
formData.append("version", "4.0");
formData.append("uid", "0");
formData.append("utoken", "");
formData.append("resource", "general");
formData.append("action", "get_bundle");
formData.append("bundle", "bundle_books");
formData.append("target", "feed");
formData.append("page", page.toString());
formData.append("filter_category_id", filters?.category?.value || "0");
formData.append("filter_completed", "-1");
formData.append("filter_search", searchTerm || "");
formData.append("filter_tags", filters?.tags?.value || "");
formData.append('version', '4.0');
formData.append('uid', '0');
formData.append('utoken', '');
formData.append('resource', 'general');
formData.append('action', 'get_bundle');
formData.append('bundle', 'bundle_books');
formData.append('target', 'feed');
formData.append('page', page.toString());
formData.append('filter_category_id', filters?.category?.value || '0');
formData.append('filter_completed', '-1');
formData.append('filter_search', searchTerm || '');
formData.append('filter_tags', filters?.tags?.value || '');
formData.append(
"filter_sort",
showLatestNovels ? "new" : filters?.sort?.value || "popular",
'filter_sort',
showLatestNovels ? 'new' : filters?.sort?.value || 'popular',
);
formData.append("filter_timeread", filters?.timeread?.value || "0-999999");
formData.append('filter_timeread', filters?.timeread?.value || '0-999999');
const result = await fetchApi("https://api.neobook.org/", {
method: "post",
const result = await fetchApi('https://api.neobook.org/', {
method: 'post',
body: formData,
});
const json = (await result.json()) as { bundle_books: BundleBooks };
const novels: Plugin.NovelItem[] = [];
if (json.bundle_books.feed?.length) {
json.bundle_books.feed?.forEach((novel) =>
json.bundle_books.feed?.forEach(novel =>
novels.push({
name: novel.title,
cover: novel?.attachment?.image?.m || defaultCover,
path: novel.token + "/",
path: novel.token + '/',
}),
);
}
@@ -77,12 +80,13 @@ class Neobook implements Plugin.PluginBase {
}
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const body = await fetchApi(this.resolveUrl(novelPath, true))
.then((res) => res.text());
const body = await fetchApi(this.resolveUrl(novelPath, true)).then(res =>
res.text(),
);
const novel: Plugin.SourceNovel = {
path: novelPath,
name: "",
name: '',
cover: defaultCover,
};
@@ -91,22 +95,22 @@ class Neobook implements Plugin.PluginBase {
const book = JSON.parse(bookRaw[1]) as Novels;
novel.name = book.title;
novel.summary = book.text?.replace?.(/<br>/g, "\n") || book.text_fix;
novel.summary = book.text?.replace?.(/<br>/g, '\n') || book.text_fix;
novel.author =
book.user && book.user.firstname && book.user.lastname
? book.user.firstname + " " + book.user.lastname
: book.user?.initials || "";
novel.status = statusKey[book.status || "0"] || NovelStatus.Unknown;
? book.user.firstname + ' ' + book.user.lastname
: book.user?.initials || '';
novel.status = statusKey[book.status || '0'] || NovelStatus.Unknown;
if (book.attachment?.image?.m) novel.cover = book.attachment.image.m;
if (book.tags?.length) novel.genres = book.tags.join(",");
if (book.tags?.length) novel.genres = book.tags.join(',');
const chapters: Plugin.ChapterItem[] = [];
book.chapters?.forEach((chapter, chapterIndex) => {
if (chapter.access == "1" && chapter.status == "1") {
if (chapter.access == '1' && chapter.status == '1') {
chapters.push({
name: chapter.title || "Глава " + (chapterIndex + 1),
name: chapter.title || 'Глава ' + (chapterIndex + 1),
path: `?book=${book.token}&chapter=${chapter.token}`,
releaseTime: null,
chapterNumber: Number(chapter.sort) || chapterIndex + 1,
@@ -120,19 +124,18 @@ class Neobook implements Plugin.PluginBase {
}
async parseChapter(chapterPath: string): Promise<string> {
const body = await fetchApi(this.resolveUrl(chapterPath))
.then((res) => res.text());
const body = await fetchApi(this.resolveUrl(chapterPath)).then(res =>
res.text(),
);
const bookRaw = body.match(/var data = ({.*?});/);
let chapterText = "";
let chapterText = '';
if (bookRaw instanceof Array && bookRaw.length >= 2) {
const book = JSON.parse(bookRaw[1]) as Novels;
const token = chapterPath.split("=")[2];
const chapter = book.chapters?.find?.(
(chapter) => chapter.token == token,
);
chapterText = (chapter?.data?.html || "").replace(/<br>/g, "");
const token = chapterPath.split('=')[2];
const chapter = book.chapters?.find?.(chapter => chapter.token == token);
chapterText = (chapter?.data?.html || '').replace(/<br>/g, '');
}
return chapterText;
@@ -140,67 +143,67 @@ class Neobook implements Plugin.PluginBase {
fetchImage = fetchFile;
resolveUrl = (path: string, isNovel?: boolean) =>
this.site + (isNovel ? "/book/" : "/reader/") + path;
this.site + (isNovel ? '/book/' : '/reader/') + path;
filters = {
sort: {
label: "Сортировка:",
value: "popular",
label: 'Сортировка:',
value: 'popular',
options: [
{ label: "Сначала популярные", value: "popular" },
{ label: "Сначала новые", value: "new" },
{ label: "В случайном порядке", value: "rand" },
{ label: 'Сначала популярные', value: 'popular' },
{ label: 'Сначала новые', value: 'new' },
{ label: 'В случайном порядке', value: 'rand' },
],
type: FilterTypes.Picker,
},
timeread: {
label: "Время прочтения:",
value: "0-999999",
label: 'Время прочтения:',
value: '0-999999',
options: [
{ label: "Все", value: "0-999999" },
{ label: "Менее 15 минут", value: "0-900" },
{ label: "15-30 минут", value: "900-1800" },
{ label: "30-60 минут", value: "1800-3600" },
{ label: "1-2 часа", value: "3600-7200" },
{ label: "Более 2 часов", value: "7200-999999" },
{ label: 'Все', value: '0-999999' },
{ label: 'Менее 15 минут', value: '0-900' },
{ label: '15-30 минут', value: '900-1800' },
{ label: '30-60 минут', value: '1800-3600' },
{ label: '1-2 часа', value: '3600-7200' },
{ label: 'Более 2 часов', value: '7200-999999' },
],
type: FilterTypes.Picker,
},
category: {
label: "Жанр:",
value: "",
label: 'Жанр:',
value: '',
options: [
{ label: "Все", value: "" },
{ label: "Антиутопия", value: "10" },
{ label: "Детектив", value: "13" },
{ label: "Детские книги", value: "14" },
{ label: "Драма", value: "15" },
{ label: "Другое", value: "16" },
{ label: "История", value: "18" },
{ label: "Мелодрама", value: "21" },
{ label: "Мистика", value: "22" },
{ label: "Научная фантастика", value: "23" },
{ label: "Нон-фикшн", value: "35" },
{ label: "Подростки и молодежь", value: "26" },
{ label: "Постапокалипсис", value: "27" },
{ label: "Поэзия", value: "28" },
{ label: "Приключения", value: "29" },
{ label: "Рассказ", value: "34" },
{ label: "Роман", value: "36" },
{ label: "Творчество", value: "40" },
{ label: "Триллер", value: "91" },
{ label: "Ужасы", value: "90" },
{ label: "Фантастика", value: "41" },
{ label: "Фанфик", value: "42" },
{ label: "Фэнтези", value: "44" },
{ label: "Эротика", value: "46" },
{ label: "Юмор", value: "47" },
{ label: 'Все', value: '' },
{ label: 'Антиутопия', value: '10' },
{ label: 'Детектив', value: '13' },
{ label: 'Детские книги', value: '14' },
{ label: 'Драма', value: '15' },
{ label: 'Другое', value: '16' },
{ label: 'История', value: '18' },
{ label: 'Мелодрама', value: '21' },
{ label: 'Мистика', value: '22' },
{ label: 'Научная фантастика', value: '23' },
{ label: 'Нон-фикшн', value: '35' },
{ label: 'Подростки и молодежь', value: '26' },
{ label: 'Постапокалипсис', value: '27' },
{ label: 'Поэзия', value: '28' },
{ label: 'Приключения', value: '29' },
{ label: 'Рассказ', value: '34' },
{ label: 'Роман', value: '36' },
{ label: 'Творчество', value: '40' },
{ label: 'Триллер', value: '91' },
{ label: 'Ужасы', value: '90' },
{ label: 'Фантастика', value: '41' },
{ label: 'Фанфик', value: '42' },
{ label: 'Фэнтези', value: '44' },
{ label: 'Эротика', value: '46' },
{ label: 'Юмор', value: '47' },
],
type: FilterTypes.Picker,
},
tags: {
label: "Тэги:",
value: "",
label: 'Тэги:',
value: '',
type: FilterTypes.TextInput,
},
} satisfies Filters;
@@ -401,7 +404,7 @@ interface Price {
deadline: string;
}
type Currency = "NEO";
type Currency = 'NEO';
interface Rating {
value: string;