fc52a6e665
* fix * test * sync * nitromanga -> madara * test wuxiaworld * xm * add chapterNumber * fix chapterNumber > 0 * test filters * nice * tunovelaligera -> madara * Squashed commit of the following: commit4c7bee5855Author: nyagami <hoangquan05112002@gmail.com> Date: Mon Jan 29 17:56:23 2024 +0700 fix: use english lang in plugin item consistent commitb26d1129deAuthor: uy/sun <hmy0119@hotmail.com> Date: Sun Jan 28 20:22:43 2024 +0800 Chinese: support showLatestNovels (#733) * improve: better chapterText * feat: support latest page commit6ff206eab3Author: nyagami <hoangquan05112002@gmail.com> Date: Sat Jan 27 09:26:19 2024 +0700 Refactor: Using English key (#728) * fix: use english key instead of native * fix: ukrainian * fix: web test with new plugins map commit62fc988019Author: Marcin Majewski <skilletssgames@gmail.com> Date: Fri Jan 26 14:42:54 2024 +0100 Fix search box styles (#727) commit3a1e0c43ebAuthor: uy/sun <hmy0119@hotmail.com> Date: Fri Jan 26 19:46:47 2024 +0800 Add 69shu and 69xinshu (#726) * fix(linovelib): use NovelStatus and translate filter label * feat(69xinshu): add 69xinshu * feat(69shu): add 69shu * remove: empty userAgent * updated the filters and removed dead sites. Error: net::ERR_NAME_NOT_RESOLVED at https://cratenovel.com/novel Error: net::ERR_CONNECTION_REFUSED at https://clicknovel.net/novel Error: net::ERR_NAME_NOT_RESOLVED at https://noobchan.xyz/novel Error: net::ERR_CONNECTION_TIMED_OUT at https://sugarbbscan.com/series * test * Squashed commit of the following: commitcadf7a72feAuthor: Felipe Bonfim <felipebonfim2006@gmail.com> Date: Tue Jan 30 14:55:34 2024 -0400 kiniga added (#739) * kiniga added * kiniga updated icon commit38fc1860daAuthor: K1ngfish3r <trulyihu@gmail.com> Date: Mon Jan 29 23:27:42 2024 +0800 (add src) LNMTL & ScribbleHub (#738) * quick * quick panda fix * remove console.log commit4c7bee5855Author: nyagami <hoangquan05112002@gmail.com> Date: Mon Jan 29 17:56:23 2024 +0700 fix: use english lang in plugin item consistent commitb26d1129deAuthor: uy/sun <hmy0119@hotmail.com> Date: Sun Jan 28 20:22:43 2024 +0800 Chinese: support showLatestNovels (#733) * improve: better chapterText * feat: support latest page commit6ff206eab3Author: nyagami <hoangquan05112002@gmail.com> Date: Sat Jan 27 09:26:19 2024 +0700 Refactor: Using English key (#728) * fix: use english key instead of native * fix: ukrainian * fix: web test with new plugins map commit62fc988019Author: Marcin Majewski <skilletssgames@gmail.com> Date: Fri Jan 26 14:42:54 2024 +0100 Fix search box styles (#727) commit3a1e0c43ebAuthor: uy/sun <hmy0119@hotmail.com> Date: Fri Jan 26 19:46:47 2024 +0800 Add 69shu and 69xinshu (#726) * fix(linovelib): use NovelStatus and translate filter label * feat(69xinshu): add 69xinshu * feat(69shu): add 69shu * remove: empty userAgent * add wuxiamtl, fannovel * fix * Update ranobelib.ts * parseMadaraDate deleted * remove multisrc name from Plugin item --------- Co-authored-by: nyagami <hoangquan05112002@gmail.com>
82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
import fs from "fs";
|
|
import { languages } from "@libs/languages";
|
|
import path from "path";
|
|
import { PluginList } from "@typings/types";
|
|
import { Plugin, isPlugin } from "@typings/plugin";
|
|
import { Filters } from "@libs/filterInputs";
|
|
const root = path.dirname(require?.main?.filename || "");
|
|
|
|
export const fetchHeaders: Record<string, string> = {}
|
|
|
|
export const all_plugins = (): PluginList => {
|
|
const res: PluginList = {};
|
|
for (let languageEnglish in languages) {
|
|
//language with English name
|
|
const languageNative =
|
|
languages[languageEnglish as keyof typeof languages];
|
|
const langPath = path.join(
|
|
root,
|
|
"plugins",
|
|
languageEnglish.toLowerCase()
|
|
);
|
|
if (!fs.existsSync(langPath)) continue;
|
|
const plugins = fs.readdirSync(langPath);
|
|
res[languageEnglish] = [];
|
|
plugins.forEach((plugin) => {
|
|
if (plugin.startsWith(".")) return;
|
|
const requirePath = `@plugins/${languageEnglish.toLowerCase()}/${
|
|
plugin.split(".")[0]
|
|
}`;
|
|
const instance = require(requirePath).default;
|
|
const { id, name, version, icon } = instance;
|
|
const info: Plugin.PluginItem = {
|
|
id,
|
|
name: name + (plugin.match(/(\[.+\])/)?.[1] || ''),
|
|
lang: languageNative,
|
|
version,
|
|
requirePath,
|
|
icon,
|
|
}; // lang: language with native name
|
|
res[languageEnglish].push(info);
|
|
});
|
|
}
|
|
return res;
|
|
};
|
|
|
|
const getPlugin = async (
|
|
requirePath: string
|
|
): Promise<Plugin.PluginBase | null> => {
|
|
console.log("loading plugin", requirePath);
|
|
const plugin = await require(requirePath).default;
|
|
console.log(plugin);
|
|
if (isPlugin(plugin)) return plugin;
|
|
console.log("Not a plugin!");
|
|
return null;
|
|
};
|
|
|
|
export const getFilter = async (pluginRequirePath: string) =>
|
|
(await getPlugin(pluginRequirePath))?.filters;
|
|
|
|
export const popularNovels = async (
|
|
pluginRequirePath: string,
|
|
options: Plugin.PopularNovelsOptions<Filters>
|
|
) => (await getPlugin(pluginRequirePath))?.popularNovels(1, options);
|
|
|
|
export const searchNovels = async (
|
|
pluginRequirePath: string,
|
|
searchTerm: string
|
|
) => (await getPlugin(pluginRequirePath))?.searchNovels(searchTerm, 1);
|
|
|
|
export const parseNovelAndChapters = async (
|
|
pluginRequirePath: string,
|
|
novelUrl: string
|
|
) => (await getPlugin(pluginRequirePath))?.parseNovelAndChapters(novelUrl);
|
|
|
|
export const parseChapter = async (
|
|
pluginRequirePath: string,
|
|
chapterUrl: string
|
|
) => (await getPlugin(pluginRequirePath))?.parseChapter(chapterUrl);
|
|
|
|
export const fetchImage = async (pluginRequirePath: string, url: string) =>
|
|
(await getPlugin(pluginRequirePath))?.fetchImage(url);
|