20efcf404c
* set target to ES5 * refactor types * use .gitkeep * use dot to make dist/js dirs on top * add hako * add Hako * add madara * fix: url path js -> .js * fix: branch * freestyle for using UA, cookie * add parseNovels for Hako * update readme * fix: conflict types * add Kolnovel, remove node-fetch * add bestlightnovel * add plugins * WQMangaStreamScraper * PandaMTL * NobleMTL * LightNovelBrasil * WPMangaStream * add filters for popularNovels * fix undefined json * Linovelib (#26) * linovelib CN * icon for linovelib * fix undefined chapter * add check * fix: add artist * TuNovelaLigera ES + Madara Fix (#28) * app repo test * POST is now working * update madara template + run generator * template fix didnt get pushed commited idk why * template update POST * generated * fix: useNewChapterEndpoint update (#29) * useNewChapterEndpoint update * Update Selectors --------- Co-authored-by: K1ngfish3r <trulyihu@gmail.com>
77 lines
2.5 KiB
TypeScript
77 lines
2.5 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";
|
|
const root = path.dirname(require?.main?.filename || "");
|
|
|
|
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[languageNative] = [];
|
|
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,
|
|
lang: languageNative,
|
|
version,
|
|
requirePath,
|
|
icon,
|
|
}; // lang: language with native name
|
|
res[info.lang].push(info);
|
|
});
|
|
}
|
|
return res;
|
|
};
|
|
|
|
const getPlugin = async (
|
|
requirePath: string
|
|
): Promise<Plugin.PluginBase | null> => {
|
|
const plugin = await require(requirePath).default;
|
|
if (isPlugin(plugin)) return plugin;
|
|
return null;
|
|
};
|
|
|
|
export const getFilter = async (
|
|
pluginRequirePath: string
|
|
) => (await getPlugin(pluginRequirePath))?.filters;
|
|
|
|
export const popularNovels = async (
|
|
pluginRequirePath: string,
|
|
options: Plugin.PopularNovelsOptions
|
|
) => (await getPlugin(pluginRequirePath))?.popularNovels(1, options);
|
|
|
|
export const searchNovels = async (
|
|
pluginRequirePath: string,
|
|
searchTerm: string
|
|
) => (await getPlugin(pluginRequirePath))?.searchNovels(searchTerm);
|
|
|
|
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);
|