From b52e12cd168d14aa747fd441c68c12052a9da646 Mon Sep 17 00:00:00 2001 From: nczitzk <42264778+nczitzk@users.noreply.github.com> Date: Thu, 26 Sep 2024 14:08:25 +0800 Subject: [PATCH 1/3] feat(route): add AIbase --- lib/routes/aibase/discover.ts | 388 +++++++++++++ lib/routes/aibase/namespace.ts | 8 + lib/routes/aibase/templates/description.art | 100 ++++ lib/routes/aibase/topic.ts | 614 ++++++++++++++++++++ lib/routes/aibase/util.ts | 106 ++++ 5 files changed, 1216 insertions(+) create mode 100644 lib/routes/aibase/discover.ts create mode 100644 lib/routes/aibase/namespace.ts create mode 100644 lib/routes/aibase/templates/description.art create mode 100644 lib/routes/aibase/topic.ts create mode 100644 lib/routes/aibase/util.ts diff --git a/lib/routes/aibase/discover.ts b/lib/routes/aibase/discover.ts new file mode 100644 index 00000000000000..f7b919f8daf8a7 --- /dev/null +++ b/lib/routes/aibase/discover.ts @@ -0,0 +1,388 @@ +import { Route } from '@/types'; + +import { ofetch } from 'ofetch'; +import { load } from 'cheerio'; + +import { rootUrl, buildApiUrl, processItems } from './util'; + +export const handler = async (ctx) => { + const { id } = ctx.req.param(); + + const [pid, sid] = id?.split(/-/) ?? [undefined, undefined]; + + const limit = Number.parseInt(ctx.req.query('limit') ?? '30', 10); + + const currentUrl = new URL(`discover${id ? `/${id}` : ''}`, rootUrl).href; + + const currentHtml = await ofetch(currentUrl); + + const $ = load(currentHtml); + + const { apiRecommListUrl, apiRecommProcUrl, apiTagProcUrl } = await buildApiUrl($); + + let ptag, stag; + let isTag = !!(pid && sid); + + if (isTag) { + const apiRecommList = await ofetch(apiRecommListUrl); + + const recommList = apiRecommList?.data?.results ?? []; + + const parentTag = recommList.find((t) => String(t.Id) === pid); + const subTag = parentTag ? parentTag.sublist.find((t) => String(t.Id) === sid) : undefined; + + ptag = parentTag?.tag ?? parentTag?.alias ?? undefined; + stag = subTag?.tag ?? subTag?.alias ?? undefined; + + isTag = !!(ptag && stag); + } + + const query = { + page: 1, + pagesize: limit, + ticket: '', + }; + + const { + data: { results: apiProcs }, + } = await (isTag + ? ofetch(apiRecommProcUrl, { + query: { + ...query, + ptag, + stag, + }, + }) + : ofetch(apiTagProcUrl, { + query: { + ...query, + f: 'id', + o: 'desc', + }, + })); + + const items = processItems(apiProcs?.slice(0, limit) ?? []); + + const image = new URL($('img.logo').prop('src'), rootUrl).href; + + const author = $('title').text().split(/_/).pop(); + + return { + title: `${author}${isTag ? ` | ${ptag} - ${stag}` : ''}`, + description: $('meta[property="og:description"]').prop('content'), + link: currentUrl, + item: items, + allowEmpty: true, + image, + author, + }; +}; + +export const route: Route = { + path: '/discover/:id?', + name: '发现', + url: 'top.aibase.com', + maintainers: ['nczitzk'], + handler, + example: '/aibase/discover', + parameters: { id: '发现分类,默认为空,即全部产品,可在对应发现分类页 URL 中找到' }, + description: `:::tip + 若订阅 [图片背景移除](https://top.aibase.com/discover/37-49),网址为 \`https://top.aibase.com/discover/37-49\`。截取 \`https://top.aibase.com/discover/\` 到末尾的部分 \`37-49\` 作为参数填入,此时路由为 [\`/aibase/discover/37-49\`](https://rsshub.app/aibase/discover/37-49)。 + ::: + +
+ 更多分类 + + #### 图像处理 + + | 分类 | ID | + | ----------------------------------------------------- | ------------------------------------------------- | + | [图片背景移除](https://top.aibase.com/discover/37-49) | [37-49](https://rsshub.app/aibase/discover/37-49) | + | [图片无损放大](https://top.aibase.com/discover/37-50) | [37-50](https://rsshub.app/aibase/discover/37-50) | + | [图片AI修复](https://top.aibase.com/discover/37-51) | [37-51](https://rsshub.app/aibase/discover/37-51) | + | [图像生成](https://top.aibase.com/discover/37-52) | [37-52](https://rsshub.app/aibase/discover/37-52) | + | [Ai图片拓展](https://top.aibase.com/discover/37-53) | [37-53](https://rsshub.app/aibase/discover/37-53) | + | [Ai漫画生成](https://top.aibase.com/discover/37-54) | [37-54](https://rsshub.app/aibase/discover/37-54) | + | [Ai生成写真](https://top.aibase.com/discover/37-55) | [37-55](https://rsshub.app/aibase/discover/37-55) | + | [电商图片制作](https://top.aibase.com/discover/37-83) | [37-83](https://rsshub.app/aibase/discover/37-83) | + | [Ai图像转视频](https://top.aibase.com/discover/37-86) | [37-86](https://rsshub.app/aibase/discover/37-86) | + + #### 视频创作 + + | 分类 | ID | + | --------------------------------------------------- | ------------------------------------------------- | + | [视频剪辑](https://top.aibase.com/discover/38-56) | [38-56](https://rsshub.app/aibase/discover/38-56) | + | [生成视频](https://top.aibase.com/discover/38-57) | [38-57](https://rsshub.app/aibase/discover/38-57) | + | [Ai动画制作](https://top.aibase.com/discover/38-58) | [38-58](https://rsshub.app/aibase/discover/38-58) | + | [字幕生成](https://top.aibase.com/discover/38-84) | [38-84](https://rsshub.app/aibase/discover/38-84) | + + #### 效率助手 + + | 分类 | ID | + | --------------------------------------------------- | ------------------------------------------------- | + | [AI文档工具](https://top.aibase.com/discover/39-59) | [39-59](https://rsshub.app/aibase/discover/39-59) | + | [PPT](https://top.aibase.com/discover/39-60) | [39-60](https://rsshub.app/aibase/discover/39-60) | + | [思维导图](https://top.aibase.com/discover/39-61) | [39-61](https://rsshub.app/aibase/discover/39-61) | + | [表格处理](https://top.aibase.com/discover/39-62) | [39-62](https://rsshub.app/aibase/discover/39-62) | + | [Ai办公助手](https://top.aibase.com/discover/39-63) | [39-63](https://rsshub.app/aibase/discover/39-63) | + + #### 写作灵感 + + | 分类 | ID | + | ------------------------------------------------- | ------------------------------------------------- | + | [文案写作](https://top.aibase.com/discover/40-64) | [40-64](https://rsshub.app/aibase/discover/40-64) | + | [论文写作](https://top.aibase.com/discover/40-88) | [40-88](https://rsshub.app/aibase/discover/40-88) | + + #### 艺术灵感 + + | 分类 | ID | + | --------------------------------------------------- | ------------------------------------------------- | + | [音乐创作](https://top.aibase.com/discover/41-65) | [41-65](https://rsshub.app/aibase/discover/41-65) | + | [设计创作](https://top.aibase.com/discover/41-66) | [41-66](https://rsshub.app/aibase/discover/41-66) | + | [Ai图标生成](https://top.aibase.com/discover/41-67) | [41-67](https://rsshub.app/aibase/discover/41-67) | + + #### 趣味 + + | 分类 | ID | + | ----------------------------------------------------- | ------------------------------------------------- | + | [Ai名字生成器](https://top.aibase.com/discover/42-68) | [42-68](https://rsshub.app/aibase/discover/42-68) | + | [游戏娱乐](https://top.aibase.com/discover/42-71) | [42-71](https://rsshub.app/aibase/discover/42-71) | + | [其他](https://top.aibase.com/discover/42-72) | [42-72](https://rsshub.app/aibase/discover/42-72) | + + #### 开发编程 + + | 分类 | ID | + | --------------------------------------------------- | ------------------------------------------------- | + | [开发编程](https://top.aibase.com/discover/43-73) | [43-73](https://rsshub.app/aibase/discover/43-73) | + | [Ai开放平台](https://top.aibase.com/discover/43-74) | [43-74](https://rsshub.app/aibase/discover/43-74) | + | [Ai算力平台](https://top.aibase.com/discover/43-75) | [43-75](https://rsshub.app/aibase/discover/43-75) | + + #### 聊天机器人 + + | 分类 | ID | + | ------------------------------------------------- | ------------------------------------------------- | + | [智能聊天](https://top.aibase.com/discover/44-76) | [44-76](https://rsshub.app/aibase/discover/44-76) | + | [智能客服](https://top.aibase.com/discover/44-77) | [44-77](https://rsshub.app/aibase/discover/44-77) | + + #### 翻译 + + | 分类 | ID | + | --------------------------------------------- | ------------------------------------------------- | + | [翻译](https://top.aibase.com/discover/46-79) | [46-79](https://rsshub.app/aibase/discover/46-79) | + + #### 教育学习 + + | 分类 | ID | + | ------------------------------------------------- | ------------------------------------------------- | + | [教育学习](https://top.aibase.com/discover/47-80) | [47-80](https://rsshub.app/aibase/discover/47-80) | + + #### 智能营销 + + | 分类 | ID | + | ------------------------------------------------- | ------------------------------------------------- | + | [智能营销](https://top.aibase.com/discover/48-81) | [48-81](https://rsshub.app/aibase/discover/48-81) | + + #### 法律 + + | 分类 | ID | + | ----------------------------------------------- | ----------------------------------------------------- | + | [法律](https://top.aibase.com/discover/138-139) | [138-139](https://rsshub.app/aibase/discover/138-139) | +
+ `, + categories: ['new-media'], + + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['top.aibase.com/discover/:id'], + target: (params) => { + const id = params.id; + + return `/discover${id ? `/${id}` : ''}`; + }, + }, + { + title: '图像处理 - 图片背景移除', + source: ['top.aibase.com/discover/37-49'], + target: '/discover/37-49', + }, + { + title: '图像处理 - 图片无损放大', + source: ['top.aibase.com/discover/37-50'], + target: '/discover/37-50', + }, + { + title: '图像处理 - 图片AI修复', + source: ['top.aibase.com/discover/37-51'], + target: '/discover/37-51', + }, + { + title: '图像处理 - 图像生成', + source: ['top.aibase.com/discover/37-52'], + target: '/discover/37-52', + }, + { + title: '图像处理 - Ai图片拓展', + source: ['top.aibase.com/discover/37-53'], + target: '/discover/37-53', + }, + { + title: '图像处理 - Ai漫画生成', + source: ['top.aibase.com/discover/37-54'], + target: '/discover/37-54', + }, + { + title: '图像处理 - Ai生成写真', + source: ['top.aibase.com/discover/37-55'], + target: '/discover/37-55', + }, + { + title: '图像处理 - 电商图片制作', + source: ['top.aibase.com/discover/37-83'], + target: '/discover/37-83', + }, + { + title: '图像处理 - Ai图像转视频', + source: ['top.aibase.com/discover/37-86'], + target: '/discover/37-86', + }, + { + title: '视频创作 - 视频剪辑', + source: ['top.aibase.com/discover/38-56'], + target: '/discover/38-56', + }, + { + title: '视频创作 - 生成视频', + source: ['top.aibase.com/discover/38-57'], + target: '/discover/38-57', + }, + { + title: '视频创作 - Ai动画制作', + source: ['top.aibase.com/discover/38-58'], + target: '/discover/38-58', + }, + { + title: '视频创作 - 字幕生成', + source: ['top.aibase.com/discover/38-84'], + target: '/discover/38-84', + }, + { + title: '效率助手 - AI文档工具', + source: ['top.aibase.com/discover/39-59'], + target: '/discover/39-59', + }, + { + title: '效率助手 - PPT', + source: ['top.aibase.com/discover/39-60'], + target: '/discover/39-60', + }, + { + title: '效率助手 - 思维导图', + source: ['top.aibase.com/discover/39-61'], + target: '/discover/39-61', + }, + { + title: '效率助手 - 表格处理', + source: ['top.aibase.com/discover/39-62'], + target: '/discover/39-62', + }, + { + title: '效率助手 - Ai办公助手', + source: ['top.aibase.com/discover/39-63'], + target: '/discover/39-63', + }, + { + title: '写作灵感 - 文案写作', + source: ['top.aibase.com/discover/40-64'], + target: '/discover/40-64', + }, + { + title: '写作灵感 - 论文写作', + source: ['top.aibase.com/discover/40-88'], + target: '/discover/40-88', + }, + { + title: '艺术灵感 - 音乐创作', + source: ['top.aibase.com/discover/41-65'], + target: '/discover/41-65', + }, + { + title: '艺术灵感 - 设计创作', + source: ['top.aibase.com/discover/41-66'], + target: '/discover/41-66', + }, + { + title: '艺术灵感 - Ai图标生成', + source: ['top.aibase.com/discover/41-67'], + target: '/discover/41-67', + }, + { + title: '趣味 - Ai名字生成器', + source: ['top.aibase.com/discover/42-68'], + target: '/discover/42-68', + }, + { + title: '趣味 - 游戏娱乐', + source: ['top.aibase.com/discover/42-71'], + target: '/discover/42-71', + }, + { + title: '趣味 - 其他', + source: ['top.aibase.com/discover/42-72'], + target: '/discover/42-72', + }, + { + title: '开发编程 - 开发编程', + source: ['top.aibase.com/discover/43-73'], + target: '/discover/43-73', + }, + { + title: '开发编程 - Ai开放平台', + source: ['top.aibase.com/discover/43-74'], + target: '/discover/43-74', + }, + { + title: '开发编程 - Ai算力平台', + source: ['top.aibase.com/discover/43-75'], + target: '/discover/43-75', + }, + { + title: '聊天机器人 - 智能聊天', + source: ['top.aibase.com/discover/44-76'], + target: '/discover/44-76', + }, + { + title: '聊天机器人 - 智能客服', + source: ['top.aibase.com/discover/44-77'], + target: '/discover/44-77', + }, + { + title: '翻译 - 翻译', + source: ['top.aibase.com/discover/46-79'], + target: '/discover/46-79', + }, + { + title: '教育学习 - 教育学习', + source: ['top.aibase.com/discover/47-80'], + target: '/discover/47-80', + }, + { + title: '智能营销 - 智能营销', + source: ['top.aibase.com/discover/48-81'], + target: '/discover/48-81', + }, + { + title: '法律 - 法律', + source: ['top.aibase.com/discover/138-139'], + target: '/discover/138-139', + }, + ], +}; diff --git a/lib/routes/aibase/namespace.ts b/lib/routes/aibase/namespace.ts new file mode 100644 index 00000000000000..0ecc00c0d4666e --- /dev/null +++ b/lib/routes/aibase/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'AIBase', + url: 'aibase.com', + categories: ['new-media'], + description: '', +}; diff --git a/lib/routes/aibase/templates/description.art b/lib/routes/aibase/templates/description.art new file mode 100644 index 00000000000000..fae2782a3c7dfa --- /dev/null +++ b/lib/routes/aibase/templates/description.art @@ -0,0 +1,100 @@ +{{ if images }} + {{ each images image }} + {{ if image?.src }} +
+ {{ image.alt }} +
+ {{ /if }} + {{ /each }} +{{ /if }} + +{{ if item }} + + + + + + + + + + + + + + + + {{ if item.desc }} + {{ item.desc }} + {{ else }} + 无 + {{ /if }} + + + + + + + + + + + + + + + + + + +
名称{{ item.name }}
标签 + {{ each strToArray(item.tags) t }} + {{ t }}  + {{ /each }} +
类型 + {{ if item.proctypename }} + {{ item.proctypename }} + {{ else }} + 无 + {{ /if }} +
描述
需求人群 + {{ set list = strToArray(item.use) }} + {{ if list.length === 1 }} + {{ list[0] }} + {{ else }} + {{ each list l }} +
  • {{ l }}
  • + {{ /each }} + {{ /if }} +
    使用场景示例 + {{ set list = strToArray(item.example) }} + {{ if list.length === 1 }} + {{ list[0] }} + {{ else }} + {{ each list l }} +
  • {{ l }}
  • + {{ /each }} + {{ /if }} +
    产品特色 + {{ set list = strToArray(item.functions) }} + {{ if list.length === 1 }} + {{ list[0] }} + {{ else }} + {{ each list l }} +
  • {{ l }}
  • + {{ /each }} + {{ /if }} +
    站点 + {{ if item.url }} + + {{ item.url }} + + {{ else }} + 无 + {{ /if }} +
    +{{ /if }} \ No newline at end of file diff --git a/lib/routes/aibase/topic.ts b/lib/routes/aibase/topic.ts new file mode 100644 index 00000000000000..3bedc44f9db441 --- /dev/null +++ b/lib/routes/aibase/topic.ts @@ -0,0 +1,614 @@ +import { Route } from '@/types'; + +import { ofetch } from 'ofetch'; +import { load } from 'cheerio'; + +import { rootUrl, buildApiUrl, processItems } from './util'; + +export const handler = async (ctx) => { + const { id, filter = 'id' } = ctx.req.param(); + + const limit = Number.parseInt(ctx.req.query('limit') ?? '30', 10); + + const currentUrl = new URL(id ? `topic/${id}` : 'discover', rootUrl).href; + + const currentHtml = await ofetch(currentUrl); + + const $ = load(currentHtml); + + const { apiTagProcUrl } = await buildApiUrl($); + + const { + data: { results: apiTagProcs }, + } = await ofetch(apiTagProcUrl, { + query: { + ...(id ? { tag: id } : {}), + page: 1, + pagesize: 20, + f: filter, + o: 'desc', + ticket: '', + }, + }); + + const items = processItems(apiTagProcs?.slice(0, limit) ?? []); + + const image = new URL($('img.logo').prop('src'), rootUrl).href; + + const author = $('title').text().split(/_/).pop(); + + return { + title: `${author}${id ? ` | ${id}` : ''}`, + description: $('meta[property="og:description"]').prop('content'), + link: currentUrl, + item: items, + allowEmpty: true, + image, + author, + }; +}; + +export const route: Route = { + path: '/topic/:id?/:filter?', + name: '标签', + url: 'top.aibase.com', + maintainers: ['nczitzk'], + handler, + example: '/aibase/topic', + parameters: { id: '标签,默认为空,即全部产品,可在对应标签页 URL 中找到', filter: '过滤器,默认为 `id` 即最新,可选 `pv` 即热门' }, + description: `:::tip + 若订阅 [AI](https://top.aibase.com/topic/AI),网址为 \`https://top.aibase.com/topic/AI\`。截取 \`https://top.aibase.com/topic\` 到末尾的部分 \`AI\` 作为参数填入,此时路由为 [\`/aibase/topic/AI\`](https://rsshub.app/aibase/topic/AI)。 + ::: + + :::tip + 此处查看 [全部标签](https://top.aibase.com/topic) + ::: + +
    + 更多标签 + + | [AI](https://top.aibase.com/topic/AI) | [人工智能](https://top.aibase.com/topic/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD) | [图像生成](https://top.aibase.com/topic/%E5%9B%BE%E5%83%8F%E7%94%9F%E6%88%90) | [自动化](https://top.aibase.com/topic/%E8%87%AA%E5%8A%A8%E5%8C%96) | [AI 助手](https://top.aibase.com/topic/AI%E5%8A%A9%E6%89%8B) | + | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | + | [聊天机器人](https://top.aibase.com/topic/%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA) | [个性化](https://top.aibase.com/topic/%E4%B8%AA%E6%80%A7%E5%8C%96) | [社交媒体](https://top.aibase.com/topic/%E7%A4%BE%E4%BA%A4%E5%AA%92%E4%BD%93) | [图像处理](https://top.aibase.com/topic/%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86) | [数据分析](https://top.aibase.com/topic/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90) | + | [自然语言处理](https://top.aibase.com/topic/%E8%87%AA%E7%84%B6%E8%AF%AD%E8%A8%80%E5%A4%84%E7%90%86) | [聊天](https://top.aibase.com/topic/%E8%81%8A%E5%A4%A9) | [机器学习](https://top.aibase.com/topic/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0) | [教育](https://top.aibase.com/topic/%E6%95%99%E8%82%B2) | [内容创作](https://top.aibase.com/topic/%E5%86%85%E5%AE%B9%E5%88%9B%E4%BD%9C) | + | [生产力](https://top.aibase.com/topic/%E7%94%9F%E4%BA%A7%E5%8A%9B) | [设计](https://top.aibase.com/topic/%E8%AE%BE%E8%AE%A1) | [ChatGPT](https://top.aibase.com/topic/ChatGPT) | [创意](https://top.aibase.com/topic/%E5%88%9B%E6%84%8F) | [开源](https://top.aibase.com/topic/%E5%BC%80%E6%BA%90) | + | [写作](https://top.aibase.com/topic/%E5%86%99%E4%BD%9C) | [效率助手](https://top.aibase.com/topic/%E6%95%88%E7%8E%87%E5%8A%A9%E6%89%8B) | [学习](https://top.aibase.com/topic/%E5%AD%A6%E4%B9%A0) | [插件](https://top.aibase.com/topic/%E6%8F%92%E4%BB%B6) | [翻译](https://top.aibase.com/topic/%E7%BF%BB%E8%AF%91) | + | [团队协作](https://top.aibase.com/topic/%E5%9B%A2%E9%98%9F%E5%8D%8F%E4%BD%9C) | [SEO](https://top.aibase.com/topic/SEO) | [营销](https://top.aibase.com/topic/%E8%90%A5%E9%94%80) | [内容生成](https://top.aibase.com/topic/%E5%86%85%E5%AE%B9%E7%94%9F%E6%88%90) | [AI 技术](https://top.aibase.com/topic/AI%E6%8A%80%E6%9C%AF) | + | [AI 工具](https://top.aibase.com/topic/AI%E5%B7%A5%E5%85%B7) | [智能助手](https://top.aibase.com/topic/%E6%99%BA%E8%83%BD%E5%8A%A9%E6%89%8B) | [深度学习](https://top.aibase.com/topic/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0) | [多语言支持](https://top.aibase.com/topic/%E5%A4%9A%E8%AF%AD%E8%A8%80%E6%94%AF%E6%8C%81) | [视频](https://top.aibase.com/topic/%E8%A7%86%E9%A2%91) | + | [艺术](https://top.aibase.com/topic/%E8%89%BA%E6%9C%AF) | [文本生成](https://top.aibase.com/topic/%E6%96%87%E6%9C%AC%E7%94%9F%E6%88%90) | [开发编程](https://top.aibase.com/topic/%E5%BC%80%E5%8F%91%E7%BC%96%E7%A8%8B) | [协作](https://top.aibase.com/topic/%E5%8D%8F%E4%BD%9C) | [语言模型](https://top.aibase.com/topic/%E8%AF%AD%E8%A8%80%E6%A8%A1%E5%9E%8B) | + | [工具](https://top.aibase.com/topic/%E5%B7%A5%E5%85%B7) | [销售](https://top.aibase.com/topic/%E9%94%80%E5%94%AE) | [生产力工具](https://top.aibase.com/topic/%E7%94%9F%E4%BA%A7%E5%8A%9B%E5%B7%A5%E5%85%B7) | [AI 写作](https://top.aibase.com/topic/AI%E5%86%99%E4%BD%9C) | [创作](https://top.aibase.com/topic/%E5%88%9B%E4%BD%9C) | + | [工作效率](https://top.aibase.com/topic/%E5%B7%A5%E4%BD%9C%E6%95%88%E7%8E%87) | [无代码](https://top.aibase.com/topic/%E6%97%A0%E4%BB%A3%E7%A0%81) | [隐私保护](https://top.aibase.com/topic/%E9%9A%90%E7%A7%81%E4%BF%9D%E6%8A%A4) | [视频编辑](https://top.aibase.com/topic/%E8%A7%86%E9%A2%91%E7%BC%96%E8%BE%91) | [摘要](https://top.aibase.com/topic/%E6%91%98%E8%A6%81) | + | [多语言](https://top.aibase.com/topic/%E5%A4%9A%E8%AF%AD%E8%A8%80) | [求职](https://top.aibase.com/topic/%E6%B1%82%E8%81%8C) | [GPT](https://top.aibase.com/topic/GPT) | [音乐](https://top.aibase.com/topic/%E9%9F%B3%E4%B9%90) | [视频创作](https://top.aibase.com/topic/%E8%A7%86%E9%A2%91%E5%88%9B%E4%BD%9C) | + | [设计工具](https://top.aibase.com/topic/%E8%AE%BE%E8%AE%A1%E5%B7%A5%E5%85%B7) | [搜索](https://top.aibase.com/topic/%E6%90%9C%E7%B4%A2) | [写作工具](https://top.aibase.com/topic/%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7) | [视频生成](https://top.aibase.com/topic/%E8%A7%86%E9%A2%91%E7%94%9F%E6%88%90) | [招聘](https://top.aibase.com/topic/%E6%8B%9B%E8%81%98) | + | [代码生成](https://top.aibase.com/topic/%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90) | [大型语言模型](https://top.aibase.com/topic/%E5%A4%A7%E5%9E%8B%E8%AF%AD%E8%A8%80%E6%A8%A1%E5%9E%8B) | [语音识别](https://top.aibase.com/topic/%E8%AF%AD%E9%9F%B3%E8%AF%86%E5%88%AB) | [编程](https://top.aibase.com/topic/%E7%BC%96%E7%A8%8B) | [在线工具](https://top.aibase.com/topic/%E5%9C%A8%E7%BA%BF%E5%B7%A5%E5%85%B7) | + | [API](https://top.aibase.com/topic/API) | [趣味](https://top.aibase.com/topic/%E8%B6%A3%E5%91%B3) | [客户支持](https://top.aibase.com/topic/%E5%AE%A2%E6%88%B7%E6%94%AF%E6%8C%81) | [语音合成](https://top.aibase.com/topic/%E8%AF%AD%E9%9F%B3%E5%90%88%E6%88%90) | [图像](https://top.aibase.com/topic/%E5%9B%BE%E5%83%8F) | + | [电子商务](https://top.aibase.com/topic/%E7%94%B5%E5%AD%90%E5%95%86%E5%8A%A1) | [SEO 优化](https://top.aibase.com/topic/SEO%E4%BC%98%E5%8C%96) | [AI 辅助](https://top.aibase.com/topic/AI%E8%BE%85%E5%8A%A9) | [AI 生成](https://top.aibase.com/topic/AI%E7%94%9F%E6%88%90) | [创作工具](https://top.aibase.com/topic/%E5%88%9B%E4%BD%9C%E5%B7%A5%E5%85%B7) | + | [免费](https://top.aibase.com/topic/%E5%85%8D%E8%B4%B9) | [LinkedIn](https://top.aibase.com/topic/LinkedIn) | [博客](https://top.aibase.com/topic/%E5%8D%9A%E5%AE%A2) | [写作助手](https://top.aibase.com/topic/%E5%86%99%E4%BD%9C%E5%8A%A9%E6%89%8B) | [助手](https://top.aibase.com/topic/%E5%8A%A9%E6%89%8B) | + | [智能](https://top.aibase.com/topic/%E6%99%BA%E8%83%BD) | [健康](https://top.aibase.com/topic/%E5%81%A5%E5%BA%B7) | [多模态](https://top.aibase.com/topic/%E5%A4%9A%E6%A8%A1%E6%80%81) | [任务管理](https://top.aibase.com/topic/%E4%BB%BB%E5%8A%A1%E7%AE%A1%E7%90%86) | [电子邮件](https://top.aibase.com/topic/%E7%94%B5%E5%AD%90%E9%82%AE%E4%BB%B6) | + | [笔记](https://top.aibase.com/topic/%E7%AC%94%E8%AE%B0) | [搜索引擎](https://top.aibase.com/topic/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E) | [计算机视觉](https://top.aibase.com/topic/%E8%AE%A1%E7%AE%97%E6%9C%BA%E8%A7%86%E8%A7%89) | [社区](https://top.aibase.com/topic/%E7%A4%BE%E5%8C%BA) | [效率](https://top.aibase.com/topic/%E6%95%88%E7%8E%87) | + | [知识管理](https://top.aibase.com/topic/%E7%9F%A5%E8%AF%86%E7%AE%A1%E7%90%86) | [LLM](https://top.aibase.com/topic/LLM) | [智能聊天](https://top.aibase.com/topic/%E6%99%BA%E8%83%BD%E8%81%8A%E5%A4%A9) | [社交](https://top.aibase.com/topic/%E7%A4%BE%E4%BA%A4) | [语言学习](https://top.aibase.com/topic/%E8%AF%AD%E8%A8%80%E5%AD%A6%E4%B9%A0) | + | [娱乐](https://top.aibase.com/topic/%E5%A8%B1%E4%B9%90) | [简历](https://top.aibase.com/topic/%E7%AE%80%E5%8E%86) | [OpenAI](https://top.aibase.com/topic/OpenAI) | [客户服务](https://top.aibase.com/topic/%E5%AE%A2%E6%88%B7%E6%9C%8D%E5%8A%A1) | [室内设计](https://top.aibase.com/topic/%E5%AE%A4%E5%86%85%E8%AE%BE%E8%AE%A1) | +
    + `, + categories: ['new-media'], + + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['top.aibase.com/topic/:id'], + target: (params) => { + const id = params.id; + + return `/topic${id ? `/${id}` : ''}`; + }, + }, + { + title: 'AI', + source: ['top.aibase.com/topic/AI'], + target: '/topic/AI', + }, + { + title: '人工智能', + source: ['top.aibase.com/topic/%E4%BA%BA%E5%B7%A5%E6%99%BA%E8%83%BD'], + target: '/topic/人工智能', + }, + { + title: '图像生成', + source: ['top.aibase.com/topic/%E5%9B%BE%E5%83%8F%E7%94%9F%E6%88%90'], + target: '/topic/图像生成', + }, + { + title: '自动化', + source: ['top.aibase.com/topic/%E8%87%AA%E5%8A%A8%E5%8C%96'], + target: '/topic/自动化', + }, + { + title: 'AI助手', + source: ['top.aibase.com/topic/AI%E5%8A%A9%E6%89%8B'], + target: '/topic/AI助手', + }, + { + title: '聊天机器人', + source: ['top.aibase.com/topic/%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA'], + target: '/topic/聊天机器人', + }, + { + title: '个性化', + source: ['top.aibase.com/topic/%E4%B8%AA%E6%80%A7%E5%8C%96'], + target: '/topic/个性化', + }, + { + title: '社交媒体', + source: ['top.aibase.com/topic/%E7%A4%BE%E4%BA%A4%E5%AA%92%E4%BD%93'], + target: '/topic/社交媒体', + }, + { + title: '图像处理', + source: ['top.aibase.com/topic/%E5%9B%BE%E5%83%8F%E5%A4%84%E7%90%86'], + target: '/topic/图像处理', + }, + { + title: '数据分析', + source: ['top.aibase.com/topic/%E6%95%B0%E6%8D%AE%E5%88%86%E6%9E%90'], + target: '/topic/数据分析', + }, + { + title: '自然语言处理', + source: ['top.aibase.com/topic/%E8%87%AA%E7%84%B6%E8%AF%AD%E8%A8%80%E5%A4%84%E7%90%86'], + target: '/topic/自然语言处理', + }, + { + title: '聊天', + source: ['top.aibase.com/topic/%E8%81%8A%E5%A4%A9'], + target: '/topic/聊天', + }, + { + title: '机器学习', + source: ['top.aibase.com/topic/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0'], + target: '/topic/机器学习', + }, + { + title: '教育', + source: ['top.aibase.com/topic/%E6%95%99%E8%82%B2'], + target: '/topic/教育', + }, + { + title: '内容创作', + source: ['top.aibase.com/topic/%E5%86%85%E5%AE%B9%E5%88%9B%E4%BD%9C'], + target: '/topic/内容创作', + }, + { + title: '生产力', + source: ['top.aibase.com/topic/%E7%94%9F%E4%BA%A7%E5%8A%9B'], + target: '/topic/生产力', + }, + { + title: '设计', + source: ['top.aibase.com/topic/%E8%AE%BE%E8%AE%A1'], + target: '/topic/设计', + }, + { + title: 'ChatGPT', + source: ['top.aibase.com/topic/ChatGPT'], + target: '/topic/ChatGPT', + }, + { + title: '创意', + source: ['top.aibase.com/topic/%E5%88%9B%E6%84%8F'], + target: '/topic/创意', + }, + { + title: '开源', + source: ['top.aibase.com/topic/%E5%BC%80%E6%BA%90'], + target: '/topic/开源', + }, + { + title: '写作', + source: ['top.aibase.com/topic/%E5%86%99%E4%BD%9C'], + target: '/topic/写作', + }, + { + title: '效率助手', + source: ['top.aibase.com/topic/%E6%95%88%E7%8E%87%E5%8A%A9%E6%89%8B'], + target: '/topic/效率助手', + }, + { + title: '学习', + source: ['top.aibase.com/topic/%E5%AD%A6%E4%B9%A0'], + target: '/topic/学习', + }, + { + title: '插件', + source: ['top.aibase.com/topic/%E6%8F%92%E4%BB%B6'], + target: '/topic/插件', + }, + { + title: '翻译', + source: ['top.aibase.com/topic/%E7%BF%BB%E8%AF%91'], + target: '/topic/翻译', + }, + { + title: '团队协作', + source: ['top.aibase.com/topic/%E5%9B%A2%E9%98%9F%E5%8D%8F%E4%BD%9C'], + target: '/topic/团队协作', + }, + { + title: 'SEO', + source: ['top.aibase.com/topic/SEO'], + target: '/topic/SEO', + }, + { + title: '营销', + source: ['top.aibase.com/topic/%E8%90%A5%E9%94%80'], + target: '/topic/营销', + }, + { + title: '内容生成', + source: ['top.aibase.com/topic/%E5%86%85%E5%AE%B9%E7%94%9F%E6%88%90'], + target: '/topic/内容生成', + }, + { + title: 'AI技术', + source: ['top.aibase.com/topic/AI%E6%8A%80%E6%9C%AF'], + target: '/topic/AI技术', + }, + { + title: 'AI工具', + source: ['top.aibase.com/topic/AI%E5%B7%A5%E5%85%B7'], + target: '/topic/AI工具', + }, + { + title: '智能助手', + source: ['top.aibase.com/topic/%E6%99%BA%E8%83%BD%E5%8A%A9%E6%89%8B'], + target: '/topic/智能助手', + }, + { + title: '深度学习', + source: ['top.aibase.com/topic/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0'], + target: '/topic/深度学习', + }, + { + title: '多语言支持', + source: ['top.aibase.com/topic/%E5%A4%9A%E8%AF%AD%E8%A8%80%E6%94%AF%E6%8C%81'], + target: '/topic/多语言支持', + }, + { + title: '视频', + source: ['top.aibase.com/topic/%E8%A7%86%E9%A2%91'], + target: '/topic/视频', + }, + { + title: '艺术', + source: ['top.aibase.com/topic/%E8%89%BA%E6%9C%AF'], + target: '/topic/艺术', + }, + { + title: '文本生成', + source: ['top.aibase.com/topic/%E6%96%87%E6%9C%AC%E7%94%9F%E6%88%90'], + target: '/topic/文本生成', + }, + { + title: '开发编程', + source: ['top.aibase.com/topic/%E5%BC%80%E5%8F%91%E7%BC%96%E7%A8%8B'], + target: '/topic/开发编程', + }, + { + title: '协作', + source: ['top.aibase.com/topic/%E5%8D%8F%E4%BD%9C'], + target: '/topic/协作', + }, + { + title: '语言模型', + source: ['top.aibase.com/topic/%E8%AF%AD%E8%A8%80%E6%A8%A1%E5%9E%8B'], + target: '/topic/语言模型', + }, + { + title: '工具', + source: ['top.aibase.com/topic/%E5%B7%A5%E5%85%B7'], + target: '/topic/工具', + }, + { + title: '销售', + source: ['top.aibase.com/topic/%E9%94%80%E5%94%AE'], + target: '/topic/销售', + }, + { + title: '生产力工具', + source: ['top.aibase.com/topic/%E7%94%9F%E4%BA%A7%E5%8A%9B%E5%B7%A5%E5%85%B7'], + target: '/topic/生产力工具', + }, + { + title: 'AI写作', + source: ['top.aibase.com/topic/AI%E5%86%99%E4%BD%9C'], + target: '/topic/AI写作', + }, + { + title: '创作', + source: ['top.aibase.com/topic/%E5%88%9B%E4%BD%9C'], + target: '/topic/创作', + }, + { + title: '工作效率', + source: ['top.aibase.com/topic/%E5%B7%A5%E4%BD%9C%E6%95%88%E7%8E%87'], + target: '/topic/工作效率', + }, + { + title: '无代码', + source: ['top.aibase.com/topic/%E6%97%A0%E4%BB%A3%E7%A0%81'], + target: '/topic/无代码', + }, + { + title: '隐私保护', + source: ['top.aibase.com/topic/%E9%9A%90%E7%A7%81%E4%BF%9D%E6%8A%A4'], + target: '/topic/隐私保护', + }, + { + title: '视频编辑', + source: ['top.aibase.com/topic/%E8%A7%86%E9%A2%91%E7%BC%96%E8%BE%91'], + target: '/topic/视频编辑', + }, + { + title: '摘要', + source: ['top.aibase.com/topic/%E6%91%98%E8%A6%81'], + target: '/topic/摘要', + }, + { + title: '多语言', + source: ['top.aibase.com/topic/%E5%A4%9A%E8%AF%AD%E8%A8%80'], + target: '/topic/多语言', + }, + { + title: '求职', + source: ['top.aibase.com/topic/%E6%B1%82%E8%81%8C'], + target: '/topic/求职', + }, + { + title: 'GPT', + source: ['top.aibase.com/topic/GPT'], + target: '/topic/GPT', + }, + { + title: '音乐', + source: ['top.aibase.com/topic/%E9%9F%B3%E4%B9%90'], + target: '/topic/音乐', + }, + { + title: '视频创作', + source: ['top.aibase.com/topic/%E8%A7%86%E9%A2%91%E5%88%9B%E4%BD%9C'], + target: '/topic/视频创作', + }, + { + title: '设计工具', + source: ['top.aibase.com/topic/%E8%AE%BE%E8%AE%A1%E5%B7%A5%E5%85%B7'], + target: '/topic/设计工具', + }, + { + title: '搜索', + source: ['top.aibase.com/topic/%E6%90%9C%E7%B4%A2'], + target: '/topic/搜索', + }, + { + title: '写作工具', + source: ['top.aibase.com/topic/%E5%86%99%E4%BD%9C%E5%B7%A5%E5%85%B7'], + target: '/topic/写作工具', + }, + { + title: '视频生成', + source: ['top.aibase.com/topic/%E8%A7%86%E9%A2%91%E7%94%9F%E6%88%90'], + target: '/topic/视频生成', + }, + { + title: '招聘', + source: ['top.aibase.com/topic/%E6%8B%9B%E8%81%98'], + target: '/topic/招聘', + }, + { + title: '代码生成', + source: ['top.aibase.com/topic/%E4%BB%A3%E7%A0%81%E7%94%9F%E6%88%90'], + target: '/topic/代码生成', + }, + { + title: '大型语言模型', + source: ['top.aibase.com/topic/%E5%A4%A7%E5%9E%8B%E8%AF%AD%E8%A8%80%E6%A8%A1%E5%9E%8B'], + target: '/topic/大型语言模型', + }, + { + title: '语音识别', + source: ['top.aibase.com/topic/%E8%AF%AD%E9%9F%B3%E8%AF%86%E5%88%AB'], + target: '/topic/语音识别', + }, + { + title: '编程', + source: ['top.aibase.com/topic/%E7%BC%96%E7%A8%8B'], + target: '/topic/编程', + }, + { + title: '在线工具', + source: ['top.aibase.com/topic/%E5%9C%A8%E7%BA%BF%E5%B7%A5%E5%85%B7'], + target: '/topic/在线工具', + }, + { + title: 'API', + source: ['top.aibase.com/topic/API'], + target: '/topic/API', + }, + { + title: '趣味', + source: ['top.aibase.com/topic/%E8%B6%A3%E5%91%B3'], + target: '/topic/趣味', + }, + { + title: '客户支持', + source: ['top.aibase.com/topic/%E5%AE%A2%E6%88%B7%E6%94%AF%E6%8C%81'], + target: '/topic/客户支持', + }, + { + title: '语音合成', + source: ['top.aibase.com/topic/%E8%AF%AD%E9%9F%B3%E5%90%88%E6%88%90'], + target: '/topic/语音合成', + }, + { + title: '图像', + source: ['top.aibase.com/topic/%E5%9B%BE%E5%83%8F'], + target: '/topic/图像', + }, + { + title: '电子商务', + source: ['top.aibase.com/topic/%E7%94%B5%E5%AD%90%E5%95%86%E5%8A%A1'], + target: '/topic/电子商务', + }, + { + title: 'SEO优化', + source: ['top.aibase.com/topic/SEO%E4%BC%98%E5%8C%96'], + target: '/topic/SEO优化', + }, + { + title: 'AI辅助', + source: ['top.aibase.com/topic/AI%E8%BE%85%E5%8A%A9'], + target: '/topic/AI辅助', + }, + { + title: 'AI生成', + source: ['top.aibase.com/topic/AI%E7%94%9F%E6%88%90'], + target: '/topic/AI生成', + }, + { + title: '创作工具', + source: ['top.aibase.com/topic/%E5%88%9B%E4%BD%9C%E5%B7%A5%E5%85%B7'], + target: '/topic/创作工具', + }, + { + title: '免费', + source: ['top.aibase.com/topic/%E5%85%8D%E8%B4%B9'], + target: '/topic/免费', + }, + { + title: 'LinkedIn', + source: ['top.aibase.com/topic/LinkedIn'], + target: '/topic/LinkedIn', + }, + { + title: '博客', + source: ['top.aibase.com/topic/%E5%8D%9A%E5%AE%A2'], + target: '/topic/博客', + }, + { + title: '写作助手', + source: ['top.aibase.com/topic/%E5%86%99%E4%BD%9C%E5%8A%A9%E6%89%8B'], + target: '/topic/写作助手', + }, + { + title: '助手', + source: ['top.aibase.com/topic/%E5%8A%A9%E6%89%8B'], + target: '/topic/助手', + }, + { + title: '智能', + source: ['top.aibase.com/topic/%E6%99%BA%E8%83%BD'], + target: '/topic/智能', + }, + { + title: '健康', + source: ['top.aibase.com/topic/%E5%81%A5%E5%BA%B7'], + target: '/topic/健康', + }, + { + title: '多模态', + source: ['top.aibase.com/topic/%E5%A4%9A%E6%A8%A1%E6%80%81'], + target: '/topic/多模态', + }, + { + title: '任务管理', + source: ['top.aibase.com/topic/%E4%BB%BB%E5%8A%A1%E7%AE%A1%E7%90%86'], + target: '/topic/任务管理', + }, + { + title: '电子邮件', + source: ['top.aibase.com/topic/%E7%94%B5%E5%AD%90%E9%82%AE%E4%BB%B6'], + target: '/topic/电子邮件', + }, + { + title: '笔记', + source: ['top.aibase.com/topic/%E7%AC%94%E8%AE%B0'], + target: '/topic/笔记', + }, + { + title: '搜索引擎', + source: ['top.aibase.com/topic/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E'], + target: '/topic/搜索引擎', + }, + { + title: '计算机视觉', + source: ['top.aibase.com/topic/%E8%AE%A1%E7%AE%97%E6%9C%BA%E8%A7%86%E8%A7%89'], + target: '/topic/计算机视觉', + }, + { + title: '社区', + source: ['top.aibase.com/topic/%E7%A4%BE%E5%8C%BA'], + target: '/topic/社区', + }, + { + title: '效率', + source: ['top.aibase.com/topic/%E6%95%88%E7%8E%87'], + target: '/topic/效率', + }, + { + title: '知识管理', + source: ['top.aibase.com/topic/%E7%9F%A5%E8%AF%86%E7%AE%A1%E7%90%86'], + target: '/topic/知识管理', + }, + { + title: 'LLM', + source: ['top.aibase.com/topic/LLM'], + target: '/topic/LLM', + }, + { + title: '智能聊天', + source: ['top.aibase.com/topic/%E6%99%BA%E8%83%BD%E8%81%8A%E5%A4%A9'], + target: '/topic/智能聊天', + }, + { + title: '社交', + source: ['top.aibase.com/topic/%E7%A4%BE%E4%BA%A4'], + target: '/topic/社交', + }, + { + title: '语言学习', + source: ['top.aibase.com/topic/%E8%AF%AD%E8%A8%80%E5%AD%A6%E4%B9%A0'], + target: '/topic/语言学习', + }, + { + title: '娱乐', + source: ['top.aibase.com/topic/%E5%A8%B1%E4%B9%90'], + target: '/topic/娱乐', + }, + { + title: '简历', + source: ['top.aibase.com/topic/%E7%AE%80%E5%8E%86'], + target: '/topic/简历', + }, + { + title: 'OpenAI', + source: ['top.aibase.com/topic/OpenAI'], + target: '/topic/OpenAI', + }, + { + title: '客户服务', + source: ['top.aibase.com/topic/%E5%AE%A2%E6%88%B7%E6%9C%8D%E5%8A%A1'], + target: '/topic/客户服务', + }, + { + title: '室内设计', + source: ['top.aibase.com/topic/%E5%AE%A4%E5%86%85%E8%AE%BE%E8%AE%A1'], + target: '/topic/室内设计', + }, + ], +}; diff --git a/lib/routes/aibase/util.ts b/lib/routes/aibase/util.ts new file mode 100644 index 00000000000000..ef9168e92aae0c --- /dev/null +++ b/lib/routes/aibase/util.ts @@ -0,0 +1,106 @@ +import { ofetch } from 'ofetch'; +import { CheerioAPI } from 'cheerio'; +import timezone from '@/utils/timezone'; +import { parseDate } from '@/utils/parse-date'; +import { art } from '@/utils/render'; +import path from 'node:path'; + +const defaultSrc = '_static/ee6af7e.js'; +const defaultToken = 'djflkdsoisknfoklsyhownfrlewfknoiaewf'; + +const rootUrl = 'https://top.aibase.com'; +const apiRootUrl = 'https://app.chinaz.com'; + +/** + * Convert a string to an array by parsing it as JSON. If parsing fails, return the string in an array. + * @param str - The string to be converted to an array. + * @returns An array containing the parsed JSON or the original string. + */ +const strToArray = (str: string) => { + try { + return str ? JSON.parse(str) : []; + } catch { + 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 ($: CheerioAPI): Promise => { + const scriptUrl = new URL($('script[src]').last()?.prop('src') ?? defaultSrc, rootUrl).href; + + const script = await ofetch(scriptUrl, { + responseType: 'text', + }); + + return script.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 ($: CheerioAPI) => { + const token = await getToken($); + + const apiRecommListUrl = new URL(`${token}/ai/GetAIProcRecommList.aspx`, apiRootUrl).href; + const apiRecommProcUrl = new URL(`${token}/ai/GetAIProcListByRecomm.aspx`, apiRootUrl).href; + const apiTagProcUrl = new URL(`${token}/ai/GetAiProductOfTag.aspx`, apiRootUrl).href; + + return { + apiRecommListUrl, + apiRecommProcUrl, + apiTagProcUrl, + }; +}; + +/** + * 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: any[]): any[] => + items.map((item) => { + const title = item.name; + const image = item.imgurl; + const description = art(path.join(__dirname, 'templates/description.art'), { + images: image + ? [ + { + src: image, + alt: title, + }, + ] + : undefined, + 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()}` : undefined, + enclosure_title: title, + }; + }); + +export { rootUrl, processItems, buildApiUrl }; From 82366b2a17a6f9602a256167da6be9f9398eee23 Mon Sep 17 00:00:00 2001 From: nczitzk <42264778+nczitzk@users.noreply.github.com> Date: Sat, 28 Sep 2024 22:30:12 +0800 Subject: [PATCH 2/3] fix: template for description --- lib/routes/aibase/discover.ts | 2 +- lib/routes/aibase/namespace.ts | 2 +- lib/routes/aibase/topic.ts | 2 +- lib/routes/aibase/util.ts | 18 ++++++++++-------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/routes/aibase/discover.ts b/lib/routes/aibase/discover.ts index f7b919f8daf8a7..2728f54374ed48 100644 --- a/lib/routes/aibase/discover.ts +++ b/lib/routes/aibase/discover.ts @@ -1,6 +1,6 @@ import { Route } from '@/types'; -import { ofetch } from 'ofetch'; +import ofetch from '@/utils/ofetch'; import { load } from 'cheerio'; import { rootUrl, buildApiUrl, processItems } from './util'; diff --git a/lib/routes/aibase/namespace.ts b/lib/routes/aibase/namespace.ts index 0ecc00c0d4666e..6c160a097a288a 100644 --- a/lib/routes/aibase/namespace.ts +++ b/lib/routes/aibase/namespace.ts @@ -1,7 +1,7 @@ import type { Namespace } from '@/types'; export const namespace: Namespace = { - name: 'AIBase', + name: 'AIbase', url: 'aibase.com', categories: ['new-media'], description: '', diff --git a/lib/routes/aibase/topic.ts b/lib/routes/aibase/topic.ts index 3bedc44f9db441..78e0fe11ddfb11 100644 --- a/lib/routes/aibase/topic.ts +++ b/lib/routes/aibase/topic.ts @@ -1,6 +1,6 @@ import { Route } from '@/types'; -import { ofetch } from 'ofetch'; +import ofetch from '@/utils/ofetch'; import { load } from 'cheerio'; import { rootUrl, buildApiUrl, processItems } from './util'; diff --git a/lib/routes/aibase/util.ts b/lib/routes/aibase/util.ts index ef9168e92aae0c..221b2763287e3e 100644 --- a/lib/routes/aibase/util.ts +++ b/lib/routes/aibase/util.ts @@ -1,4 +1,4 @@ -import { ofetch } from 'ofetch'; +import ofetch from '@/utils/ofetch'; import { CheerioAPI } from 'cheerio'; import timezone from '@/utils/timezone'; import { parseDate } from '@/utils/parse-date'; @@ -12,16 +12,18 @@ const rootUrl = 'https://top.aibase.com'; const apiRootUrl = 'https://app.chinaz.com'; /** - * Convert a string to an array by parsing it as JSON. If parsing fails, return the string in an array. - * @param str - The string to be converted to an array. - * @returns An array containing the parsed JSON or the original string. + * 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: string) => { - try { - return str ? JSON.parse(str) : []; - } catch { - return [str]; + if (str.startsWith('[')) { + return JSON.parse(str); } + return [str]; }; art.defaults.imports.strToArray = strToArray; From 1d4e9cb45f04b5fbc9d94aa8445cd13cd47f3279 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Sun, 13 Oct 2024 23:56:29 +0800 Subject: [PATCH 3/3] update util.ts --- lib/routes/aibase/util.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/routes/aibase/util.ts b/lib/routes/aibase/util.ts index 221b2763287e3e..c2f9289cc6ba13 100644 --- a/lib/routes/aibase/util.ts +++ b/lib/routes/aibase/util.ts @@ -1,3 +1,6 @@ +import { getCurrentPath } from '@/utils/helpers'; +const __dirname = getCurrentPath(import.meta.url); + import ofetch from '@/utils/ofetch'; import { CheerioAPI } from 'cheerio'; import timezone from '@/utils/timezone';