UNPKG

rsshub

Version:
50 lines (48 loc) 1.68 kB
import "./esm-shims-CzJ_djXG.mjs"; import { n as setConfig } from "./config-C37vj7VH.mjs"; import { t as ViewType } from "./types-D84BRIt4.mjs"; import "./dist-BInvbO1W.mjs"; import "./logger-Czu8UMNd.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { n as parseRelativeDate, t as parseDate } from "./parse-date-BrP7mxXf.mjs"; //#region lib/pkg.ts let app = null; function ensureAppInitialized(app$1) { if (!app$1) throw new Error("RSSHub not initialized. Please call init() first."); } async function init(conf) { setConfig(Object.assign({ IS_PACKAGE: true }, conf)); app = (await import("./app-B8RpBkYX.mjs")).default; } async function request(path) { ensureAppInitialized(app); return (await app.request(path)).json(); } async function registerRoute(namespace, route, namespaceConfig) { ensureAppInitialized(app); const { namespaces } = await import("./registry-CEfF2f_C.mjs"); if (!namespaces[namespace]) namespaces[namespace] = { ...namespaceConfig, name: namespaceConfig?.name || namespace, routes: {}, apiRoutes: {} }; const paths = Array.isArray(route.path) ? route.path : [route.path]; const subApp = app.basePath(`/${namespace}`); const wrappedHandler = async (ctx) => { if (!ctx.get("data")) { const response = await route.handler(ctx); if (response instanceof Response) return response; ctx.set("data", response); } }; for (const path of paths) { namespaces[namespace].routes[path] = { ...route, location: `custom/${namespace}` }; subApp.get(path, wrappedHandler); } } //#endregion export { ViewType, init, ofetch_default as ofetch, parseDate, parseRelativeDate, registerRoute, request };