fix: Novelfire URL Parsing + Chapter Sorting (#1927)
* Add handling for extra slashes * Add chapterNumber data * Remove unused lib * NovelFire Version Bump * Sort chapters array * Decode characters
This commit is contained in:
@@ -4,12 +4,11 @@ import { Plugin } from '@/types/plugin';
|
|||||||
import { NovelStatus } from '@libs/novelStatus';
|
import { NovelStatus } from '@libs/novelStatus';
|
||||||
import { Filters, FilterTypes } from '@libs/filterInputs';
|
import { Filters, FilterTypes } from '@libs/filterInputs';
|
||||||
import { defaultCover } from '@/types/constants';
|
import { defaultCover } from '@/types/constants';
|
||||||
import { storage } from '@libs/storage';
|
|
||||||
|
|
||||||
class NovelFire implements Plugin.PluginBase {
|
class NovelFire implements Plugin.PluginBase {
|
||||||
id = 'novelfire';
|
id = 'novelfire';
|
||||||
name = 'Novel Fire';
|
name = 'Novel Fire';
|
||||||
version = '1.1.3';
|
version = '1.1.4';
|
||||||
icon = 'src/en/novelfire/icon.png';
|
icon = 'src/en/novelfire/icon.png';
|
||||||
site = 'https://novelfire.net/';
|
site = 'https://novelfire.net/';
|
||||||
|
|
||||||
@@ -65,9 +64,12 @@ class NovelFire implements Plugin.PluginBase {
|
|||||||
const novelName =
|
const novelName =
|
||||||
loadedCheerio(ele).find('.novel-title > a').text() ||
|
loadedCheerio(ele).find('.novel-title > a').text() ||
|
||||||
'No Title Found';
|
'No Title Found';
|
||||||
const novelCover = loadedCheerio(ele)
|
const novelCover =
|
||||||
.find('.novel-cover > img')
|
this.site +
|
||||||
.attr('data-src');
|
deSlash(
|
||||||
|
loadedCheerio(ele).find('.novel-cover > img').attr('data-src') ||
|
||||||
|
'',
|
||||||
|
);
|
||||||
const novelPath = loadedCheerio(ele)
|
const novelPath = loadedCheerio(ele)
|
||||||
.find('.novel-title > a')
|
.find('.novel-title > a')
|
||||||
.attr('href');
|
.attr('href');
|
||||||
@@ -77,7 +79,7 @@ class NovelFire implements Plugin.PluginBase {
|
|||||||
return {
|
return {
|
||||||
name: novelName,
|
name: novelName,
|
||||||
cover: novelCover,
|
cover: novelCover,
|
||||||
path: novelPath.replace(this.site, ''),
|
path: deSlash(novelPath.replace(this.site, '')),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.get()
|
.get()
|
||||||
@@ -105,28 +107,34 @@ class NovelFire implements Plugin.PluginBase {
|
|||||||
const json = JSON.parse(body);
|
const json = JSON.parse(body);
|
||||||
const chapters = json.data
|
const chapters = json.data
|
||||||
.map(index => {
|
.map(index => {
|
||||||
const chapterName = index.title || index.slug;
|
const chapterName = load(index.title || index.slug).text();
|
||||||
const chapterPath = `${novelPath}/chapter-${index.n_sort}`;
|
const chapterPath = `${novelPath}/chapter-${index.n_sort}`;
|
||||||
|
const sortNumber = index.n_sort;
|
||||||
|
|
||||||
if (!chapterPath) return null;
|
if (!chapterPath) return null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: chapterName,
|
name: chapterName,
|
||||||
path: chapterPath,
|
path: chapterPath,
|
||||||
|
chapterNumber: Number(sortNumber),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(chapter => chapter !== null) as Plugin.ChapterItem[];
|
.filter(chapter => chapter !== null) as Plugin.ChapterItem[];
|
||||||
|
const sortedChapters = chapters.sort(function (a, b) {
|
||||||
|
return a.chapterNumber - b.chapterNumber;
|
||||||
|
});
|
||||||
|
|
||||||
return chapters;
|
return sortedChapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
async parseNovel(novelPath: string): Promise<Plugin.SourceNovel> {
|
async parseNovel(novelPathRaw: string): Promise<Plugin.SourceNovel> {
|
||||||
|
const novelPath = deSlash(novelPathRaw);
|
||||||
const $ = await this.getCheerio(this.site + novelPath, false);
|
const $ = await this.getCheerio(this.site + novelPath, false);
|
||||||
const baseUrl = this.site;
|
const baseUrl = this.site;
|
||||||
|
|
||||||
let post_id = '0';
|
let post_id = '0';
|
||||||
|
|
||||||
const novel: Partial<Plugin.SourceNovel & { totalPages: number }> = {
|
const novel: Partial<Plugin.SourceNovel> = {
|
||||||
path: novelPath,
|
path: novelPath,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -207,9 +215,11 @@ class NovelFire implements Plugin.PluginBase {
|
|||||||
.map((index, ele) => {
|
.map((index, ele) => {
|
||||||
const novelName =
|
const novelName =
|
||||||
loadedCheerio(ele).find('a').attr('title') || 'No Title Found';
|
loadedCheerio(ele).find('a').attr('title') || 'No Title Found';
|
||||||
const novelCover = loadedCheerio(ele)
|
const novelCover =
|
||||||
.find('.novel-cover > img')
|
this.site +
|
||||||
.attr('src');
|
deSlash(
|
||||||
|
loadedCheerio(ele).find('.novel-cover > img').attr('src') || '',
|
||||||
|
);
|
||||||
const novelPath = loadedCheerio(ele).find('a').attr('href');
|
const novelPath = loadedCheerio(ele).find('a').attr('href');
|
||||||
|
|
||||||
if (!novelPath) return null;
|
if (!novelPath) return null;
|
||||||
@@ -217,7 +227,7 @@ class NovelFire implements Plugin.PluginBase {
|
|||||||
return {
|
return {
|
||||||
name: novelName,
|
name: novelName,
|
||||||
cover: novelCover,
|
cover: novelCover,
|
||||||
path: novelPath.replace(this.site, ''),
|
path: deSlash(novelPath.replace(this.site, '')),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.get()
|
.get()
|
||||||
@@ -393,3 +403,15 @@ class NovelFireAjaxNotFound extends Error {
|
|||||||
this.name = 'NovelFireAjaxError';
|
this.name = 'NovelFireAjaxError';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deSlash(url: string): string {
|
||||||
|
let clean: string;
|
||||||
|
|
||||||
|
if (url.charAt(0) == '/') {
|
||||||
|
clean = url.substring(1);
|
||||||
|
} else {
|
||||||
|
clean = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return clean;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user