UNPKG

rsshub

Version:
96 lines (94 loc) 3.26 kB
import { n as init_esm_shims, t as __dirname } from "./esm-shims-CzJ_djXG.mjs"; import { t as ofetch_default } from "./ofetch-BIyrKU3Y.mjs"; import { t as parseDate } from "./parse-date-BrP7mxXf.mjs"; import { t as art } from "./render-BQo6B4tL.mjs"; import { t as timezone } from "./timezone-D8cuwzTY.mjs"; import path from "node:path"; //#region lib/routes/aibase/util.ts init_esm_shims(); const defaultSrc = "_static/ee6af7e.js"; const defaultToken = "djflkdsoisknfoklsyhownfrlewfknoiaewf"; const rootUrl = "https://top.aibase.com"; const apiRootUrl = "https://app.chinaz.com"; /** * Converts a string to an array. * If the string starts with '[', it is assumed to be a JSON array and is parsed accordingly. * Otherwise, the string is wrapped in an array. * * @param str - The input string to convert to an array. * @returns An array created from the input string. */ const strToArray = (str) => { if (str.startsWith("[")) return JSON.parse(str); return [str]; }; art.defaults.imports.strToArray = strToArray; /** * Retrieve a token asynchronously using a CheerioAPI instance. * @param $ - The CheerioAPI instance. * @returns A Promise that resolves to a string representing the token. */ const getToken = async ($) => { const scriptUrl = new URL($("script[src]").last()?.prop("src") ?? defaultSrc, rootUrl).href; return (await ofetch_default(scriptUrl, { responseType: "text" })).match(/"\/(\w+)\/ai\/.*?\.aspx"/)?.[1] ?? defaultToken; }; /** * Build API URLs asynchronously using a CheerioAPI instance. * @param $ - The CheerioAPI instance. * @returns An object containing API URLs. */ const buildApiUrl = async ($) => { const token = await getToken($); return { apiRecommListUrl: new URL(`${token}/ai/GetAIProcRecommList.aspx`, apiRootUrl).href, apiRecommProcUrl: new URL(`${token}/ai/GetAIProcListByRecomm.aspx`, apiRootUrl).href, apiTagProcUrl: new URL(`${token}/ai/GetAiProductOfTag.aspx`, apiRootUrl).href, apiInfoListUrl: new URL(`${token}/ai/GetAiInfoList.aspx`, apiRootUrl).href, aILogListUrl: new URL(`${token}/ai/v2/GetAILogList.aspx`, apiRootUrl).href }; }; /** * Process an array of items to generate a new array of processed items for RSS. * @param items - An array of items to process. * @returns An array of processed items. */ const processItems = (items) => items.map((item) => { const title = item.name; const image = item.imgurl; const description = art(path.join(__dirname, "templates/description-39dca137.art"), { images: image ? [{ src: image, alt: title }] : void 0, item }); const guid = `aibase-${item.zurl}`; return { title, description, pubDate: timezone(parseDate(item.addtime), 8), link: new URL(`tool/${item.zurl}`, rootUrl).href, category: [...new Set([ ...strToArray(item.categories), ...strToArray(item.tags), item.catname, item.procattrname, item.procformname, item.proctypename ])].filter(Boolean), guid, id: guid, content: { html: description, text: item.desc }, image, banner: image, updated: parseDate(item.UpdTime), enclosure_url: item.logo, enclosure_type: item.logo ? `image/${item.logo.split(/\./).pop()}` : void 0, enclosure_title: title }; }); //#endregion export { processItems as n, rootUrl as r, buildApiUrl as t };