fix: linter issues
This commit is contained in:
@@ -2,7 +2,7 @@ require('module-alias/register');
|
||||
import * as fs from 'fs';
|
||||
import * as cheerio from 'cheerio';
|
||||
import * as path from 'path';
|
||||
import { FilterTypes, FilterOption } from '@libs/filterInputs';
|
||||
import { Filters, FilterTypes, FilterOption } from '@libs/filterInputs';
|
||||
const type: string[] = ['genres', 'status', 'sort'];
|
||||
|
||||
async function getFilters(name: string, url: string) {
|
||||
@@ -10,7 +10,7 @@ async function getFilters(name: string, url: string) {
|
||||
res.text(),
|
||||
);
|
||||
const $: cheerio.CheerioAPI = cheerio.load(html);
|
||||
const filters: any = {
|
||||
const filters: Filters = {
|
||||
'sort': {
|
||||
type: FilterTypes.Picker,
|
||||
label: 'Sort By',
|
||||
@@ -76,9 +76,9 @@ async function getFilters(name: string, url: string) {
|
||||
.map((index, element) => loadedCheerio(element).attr('href'))
|
||||
.get();
|
||||
// ===================== tags ======================
|
||||
for (let i = 0; i < allPage.length; i++) {
|
||||
console.log('fetch', url + allPage[i]);
|
||||
const resTags = await fetch(url + allPage[i]).then(res => res.text());
|
||||
for (const page of allPage) {
|
||||
console.log('fetch', url + page);
|
||||
const resTags = await fetch(url + page).then(res => res.text());
|
||||
const $: cheerio.CheerioAPI = cheerio.load(resTags);
|
||||
$('.tag-items > li > a').each((index, element) =>
|
||||
filters['tags'].options.push({
|
||||
@@ -97,10 +97,10 @@ async function getFilters(name: string, url: string) {
|
||||
await sleep(3000);
|
||||
console.log(
|
||||
'fetch',
|
||||
url + allPage[i].replace('-0.html', `-${pageNo + 1}.html`),
|
||||
url + page.replace('-0.html', `-${pageNo + 1}.html`),
|
||||
);
|
||||
const resTags = await fetch(
|
||||
url + allPage[i].replace('-0.html', `-${pageNo + 1}.html`),
|
||||
url + page.replace('-0.html', `-${pageNo + 1}.html`),
|
||||
).then(res => res.text());
|
||||
const $: cheerio.CheerioAPI = cheerio.load(resTags);
|
||||
|
||||
@@ -141,9 +141,9 @@ async function askGetFilter() {
|
||||
async (url: string) => {
|
||||
try {
|
||||
await getFilters(name, url);
|
||||
} catch (e: any) {
|
||||
} catch (e: unknown) {
|
||||
console.error('Error while getting filters from', url);
|
||||
console.log(e.message || e);
|
||||
console.log(e instanceof Error ? e.message : e);
|
||||
}
|
||||
readline.close();
|
||||
},
|
||||
|
||||
@@ -13,11 +13,11 @@ export type ReadwnMetadata = {
|
||||
id: string;
|
||||
sourceSite: string;
|
||||
sourceName: string;
|
||||
filters?: any;
|
||||
filters?: Filters;
|
||||
options?: ReadwnOptions;
|
||||
};
|
||||
|
||||
class ReadwnPlugin implements Plugin.PluginBase {
|
||||
export class ReadwnPlugin implements Plugin.PluginBase {
|
||||
id: string;
|
||||
name: string;
|
||||
icon: string;
|
||||
@@ -31,13 +31,16 @@ class ReadwnPlugin implements Plugin.PluginBase {
|
||||
this.icon = `multisrc/readwn/${metadata.id.toLowerCase()}/icon.png`;
|
||||
this.site = metadata.sourceSite;
|
||||
const versionIncrements = metadata.options?.versionIncrements || 0;
|
||||
this.version = `1.0.${2 + versionIncrements}`;
|
||||
this.version = `1.0.${3 + versionIncrements}`;
|
||||
this.filters = metadata.filters;
|
||||
}
|
||||
|
||||
async popularNovels(
|
||||
pageNo: number,
|
||||
{ filters, showLatestNovels }: Plugin.PopularNovelsOptions,
|
||||
{
|
||||
filters,
|
||||
showLatestNovels,
|
||||
}: Plugin.PopularNovelsOptions<typeof this.filters>,
|
||||
): Promise<Plugin.NovelItem[]> {
|
||||
let url = this.site + '/list/';
|
||||
url += (filters?.genres?.value || 'all') + '/';
|
||||
@@ -50,7 +53,7 @@ class ReadwnPlugin implements Plugin.PluginBase {
|
||||
url = this.site + '/tags/' + filters.tags.value + '-0.html';
|
||||
}
|
||||
|
||||
const body = await fetchApi(url).then(res => res.text());
|
||||
const body = await fetchApi(url).then((res: Response) => res.text());
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const novels: Plugin.NovelItem[] = loadedCheerio('li.novel-item')
|
||||
@@ -68,7 +71,9 @@ class ReadwnPlugin implements Plugin.PluginBase {
|
||||
}
|
||||
|
||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
||||
const body = await fetchApi(this.site + novelPath).then(res => res.text());
|
||||
const body = await fetchApi(this.site + novelPath).then((res: Response) =>
|
||||
res.text(),
|
||||
);
|
||||
const loadedCheerio = parseHTML(body);
|
||||
|
||||
const novel: Plugin.SourceNovel = {
|
||||
@@ -186,7 +191,7 @@ class ReadwnPlugin implements Plugin.PluginBase {
|
||||
}
|
||||
|
||||
async parseChapter(chapterPath: string): Promise<string> {
|
||||
const body = await fetchApi(this.site + chapterPath).then(res =>
|
||||
const body = await fetchApi(this.site + chapterPath).then((res: Response) =>
|
||||
res.text(),
|
||||
);
|
||||
const loadedCheerio = parseHTML(body);
|
||||
@@ -205,11 +210,11 @@ class ReadwnPlugin implements Plugin.PluginBase {
|
||||
method: 'POST',
|
||||
body: new URLSearchParams({
|
||||
show: 'title',
|
||||
tempid: 1,
|
||||
tempid: '1',
|
||||
tbname: 'news',
|
||||
keyboard: searchTerm,
|
||||
}).toString(),
|
||||
}).then(res => res.text());
|
||||
}).then((res: Response) => res.text());
|
||||
const loadedCheerio = parseHTML(result);
|
||||
|
||||
const novels: Plugin.NovelItem[] = loadedCheerio('li.novel-item')
|
||||
|
||||
Reference in New Issue
Block a user