fix: linter issues
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { fetchApi } from '@libs/fetch';
|
||||
import { Plugin } from '@/types/plugin';
|
||||
import { Node } from 'domhandler';
|
||||
import { load as loadCheerio } from 'cheerio';
|
||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||
import { storage } from '@libs/storage';
|
||||
@@ -13,6 +12,10 @@ type APINovel = {
|
||||
description: string;
|
||||
status: string;
|
||||
genres: { name: string }[];
|
||||
user?: {
|
||||
username?: string;
|
||||
name?: string;
|
||||
};
|
||||
};
|
||||
|
||||
type APIChapter = {
|
||||
@@ -35,12 +38,44 @@ type ChapterInfo = {
|
||||
chapterNumber: number;
|
||||
};
|
||||
|
||||
type Chapter = {
|
||||
type: string;
|
||||
content: {
|
||||
type: string;
|
||||
attrs?: Attrs;
|
||||
content: {
|
||||
type: string;
|
||||
text?: string;
|
||||
marks?: {
|
||||
type: string;
|
||||
attrs?: Attrs;
|
||||
}[];
|
||||
}[];
|
||||
}[];
|
||||
};
|
||||
|
||||
type Attrs = {
|
||||
textAlign?: string;
|
||||
href?: string;
|
||||
level?: number;
|
||||
};
|
||||
|
||||
type Nodes = {
|
||||
type: string;
|
||||
nodes?: {
|
||||
type: string;
|
||||
// couldnt find the sveltekit so disable eslint here
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
data: any[];
|
||||
}[];
|
||||
};
|
||||
|
||||
class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
id = 'fenrir';
|
||||
name = 'Fenrir Realm';
|
||||
icon = 'src/en/fenrirrealm/icon.png';
|
||||
site = 'https://fenrirealm.com';
|
||||
version = '1.0.13';
|
||||
version = '1.1.0';
|
||||
imageRequestInit?: Plugin.ImageRequestInit | undefined = undefined;
|
||||
|
||||
hideLocked = storage.get('hideLocked');
|
||||
@@ -62,14 +97,16 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
filters,
|
||||
}: Plugin.PopularNovelsOptions<typeof this.filters>,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
// let sort = "updated";
|
||||
let sort = filters.sort.value;
|
||||
if (showLatestNovels) sort = 'latest';
|
||||
const genresFilter = filters.genres.value
|
||||
.map(g => '&genres%5B%5D=' + g)
|
||||
.join('');
|
||||
const params = new URLSearchParams({
|
||||
page: pageNo.toString(),
|
||||
per_page: '20',
|
||||
status: filters.status.value,
|
||||
order: showLatestNovels ? 'latest' : filters.sort.value,
|
||||
});
|
||||
filters.genres.value.forEach(g => params.append('genres[]', g));
|
||||
|
||||
const res = await fetchApi(
|
||||
`${this.site}/api/series/filter?page=${pageNo}&per_page=20&status=${filters.status.value}&order=${sort}${genresFilter}`,
|
||||
`${this.site}/api/series/filter?${params.toString()}`,
|
||||
).then(r =>
|
||||
r.json().catch(() => {
|
||||
throw new Error(
|
||||
@@ -90,7 +127,7 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
|
||||
if (!apiRes.ok) {
|
||||
const slugMatch = novelPath.match(/^\d+-(.+)$/);
|
||||
let searchSlug = slugMatch ? slugMatch[1] : novelPath;
|
||||
const searchSlug = slugMatch ? slugMatch[1] : novelPath;
|
||||
apiRes = await fetchApi(
|
||||
`${this.site}/api/new/v2/series/${searchSlug}/chapters`,
|
||||
{},
|
||||
@@ -120,7 +157,7 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
}
|
||||
}
|
||||
|
||||
const seriesData = await fetchApi(
|
||||
const seriesData: APINovel = await fetchApi(
|
||||
`${this.site}/api/new/v2/series/${cleanNovelPath}`,
|
||||
).then(r => r.json());
|
||||
const summaryCheerio = loadCheerio(seriesData.description || '');
|
||||
@@ -131,7 +168,7 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
summary:
|
||||
summaryCheerio('p').length > 0
|
||||
? summaryCheerio('p')
|
||||
.map((i, el) => loadCheerio(el).text())
|
||||
.map((_, el) => loadCheerio(el).text())
|
||||
.get()
|
||||
.join('\n\n')
|
||||
: summaryCheerio.text() || '',
|
||||
@@ -139,7 +176,7 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
cover: seriesData.cover
|
||||
? this.site + '/' + seriesData.cover
|
||||
: defaultCover,
|
||||
genres: (seriesData.genres || []).map((g: any) => g.name).join(','),
|
||||
genres: (seriesData.genres || []).map(g => g.name).join(','),
|
||||
status: seriesData.status || 'Unknown',
|
||||
};
|
||||
|
||||
@@ -184,14 +221,14 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
const content = json.content;
|
||||
|
||||
if (content) {
|
||||
const parsedContent = JSON.parse(content);
|
||||
const parsedContent: Chapter = JSON.parse(content);
|
||||
if (parsedContent.type === 'doc') {
|
||||
return parsedContent.content
|
||||
.map((node: any) => {
|
||||
.map(node => {
|
||||
if (node.type === 'paragraph') {
|
||||
const innerHtml =
|
||||
node.content
|
||||
?.map((c: any) => {
|
||||
?.map(c => {
|
||||
if (c.type === 'text') {
|
||||
let text = c.text;
|
||||
if (c.marks) {
|
||||
@@ -216,8 +253,7 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
}
|
||||
if (node.type === 'heading') {
|
||||
const level = node.attrs?.level || 1;
|
||||
const innerHtml =
|
||||
node.content?.map((c: any) => c.text).join('') || '';
|
||||
const innerHtml = node.content?.map(c => c.text).join('') || '';
|
||||
return `<h${level}>${innerHtml}</h${level}>`;
|
||||
}
|
||||
return '';
|
||||
@@ -235,7 +271,7 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
const loadedCheerio = loadCheerio(body);
|
||||
|
||||
let chapterText = loadedCheerio('div.content-area p')
|
||||
.map((i, el) => `<p>${loadCheerio(el).html()}</p>`)
|
||||
.map((_, el) => `<p>${loadCheerio(el).html()}</p>`)
|
||||
.get()
|
||||
.join('\n');
|
||||
|
||||
@@ -247,24 +283,24 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
try {
|
||||
const jsonUrl = `${this.site}/series/${chapterPath.split('~~')[0]}/__data.json?x-sveltekit-invalidated=001`;
|
||||
const jsonRes = await fetchApi(jsonUrl);
|
||||
const json = await jsonRes.json();
|
||||
const json: Nodes = await jsonRes.json();
|
||||
|
||||
const nodes = json.nodes;
|
||||
const data = nodes?.find((n: any) => n.type === 'data')?.data;
|
||||
const data = nodes?.find(n => n.type === 'data')?.data;
|
||||
if (data) {
|
||||
const contentStr = data.find(
|
||||
(d: any) => typeof d === 'string' && d.includes('{"type":"doc"'),
|
||||
d => typeof d === 'string' && d.includes('{"type":"doc"'),
|
||||
);
|
||||
|
||||
if (contentStr) {
|
||||
const contentJson = JSON.parse(contentStr);
|
||||
const contentJson: Chapter = JSON.parse(contentStr);
|
||||
if (contentJson.type === 'doc') {
|
||||
chapterText = contentJson.content
|
||||
.map((node: any) => {
|
||||
.map(node => {
|
||||
if (node.type === 'paragraph') {
|
||||
const innerHtml =
|
||||
node.content
|
||||
?.map((c: any) => {
|
||||
?.map(c => {
|
||||
if (c.type === 'text') {
|
||||
let text = c.text;
|
||||
if (c.marks) {
|
||||
@@ -330,8 +366,8 @@ class FenrirRealmPlugin implements Plugin.PluginBase {
|
||||
};
|
||||
}
|
||||
|
||||
resolveUrl = (path: string, isNovel?: boolean) =>
|
||||
this.site + '/series/' + path.split('~~')[0];
|
||||
// resolveUrl = (path: string, isNovel?: boolean) =>
|
||||
// this.site + '/series/' + path.split('~~')[0];
|
||||
|
||||
filters = {
|
||||
status: {
|
||||
|
||||
Reference in New Issue
Block a user