fix: Revert NovelFire to Standard Plugin (#1913)

- kept the paged version as a separate plugin
 - add Cloudflare check
 - removed nbsp from chapter text
This commit is contained in:
Justin COLLON
2025-12-11 04:16:40 +01:00
committed by GitHub
parent 1a62ada59c
commit f5cb6eb444
2 changed files with 395 additions and 37 deletions
+13 -37
View File
@@ -6,23 +6,13 @@ import { Filters, FilterTypes } from '@libs/filterInputs';
import { defaultCover } from '@/types/constants';
import { storage } from '@libs/storage';
class NovelFire implements Plugin.PagePlugin {
class NovelFire implements Plugin.PluginBase {
id = 'novelfire';
name = 'Novel Fire';
version = '1.1.1';
version = '1.1.2';
icon = 'src/en/novelfire/icon.png';
site = 'https://novelfire.net/';
singlePage = storage.get('singlePage');
pluginSettings = {
singlePage: {
value: '',
label:
'Have all the chapters in a single page (Will be slower & use more internet data)',
type: FilterTypes.Switch,
},
};
async getCheerio(url: string, search: boolean): Promise<CheerioAPI> {
const r = await fetchApi(url);
if (!r.ok && search != true)
@@ -31,6 +21,10 @@ class NovelFire implements Plugin.PagePlugin {
);
const $ = load(await r.text());
if ($('title').text().includes('Cloudflare')) {
throw new Error('Cloudflare is blocking requests. Try again later.');
}
return $;
}
@@ -191,9 +185,7 @@ class NovelFire implements Plugin.PagePlugin {
return Math.ceil(parseInt(totalChapters) / 100);
}
async parseNovel(
novelPath: string,
): Promise<Plugin.SourceNovel & { totalPages: number }> {
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
const $ = await this.getCheerio(this.site + novelPath, false);
const baseUrl = this.site;
@@ -246,28 +238,12 @@ class NovelFire implements Plugin.PagePlugin {
novel.rating = parseFloat($('.nub').text().trim());
if (this.singlePage) {
novel.totalPages = 1;
} else {
novel.totalPages = this.getTotalPages($);
}
novel.chapters = await this.getAllChapters(
novelPath,
this.getTotalPages(await this.getCheerio(this.site + novelPath, false)),
);
return novel as Plugin.SourceNovel & { totalPages: number };
}
async parsePage(novelPath: string, page: string): Promise<Plugin.SourcePage> {
let chapters: Plugin.ChapterItem[];
if (this.singlePage)
chapters = await this.getAllChapters(
novelPath,
this.getTotalPages(await this.getCheerio(this.site + novelPath, false)),
);
else chapters = await this.getChaptersOnPage(novelPath, page);
return {
chapters,
};
return novel as Plugin.SourceNovel;
}
async parseChapter(chapterPath: string): Promise<string> {
@@ -278,7 +254,7 @@ class NovelFire implements Plugin.PagePlugin {
loadedCheerio(chapterText).find('div').remove();
return chapterText.html() || '';
return chapterText.html()?.replace(/&nbsp;/g, ' ') || '';
}
async searchNovels(