From 740e5d1fe4524ed7b2b1b14861bf01cbc6e25844 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 17 May 2025 02:06:56 +0800 Subject: [PATCH] feat(route/cih-index): add report (#19114) --- lib/routes/cih-index/namespace.ts | 7 +++ lib/routes/cih-index/report.ts | 74 +++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 lib/routes/cih-index/namespace.ts create mode 100644 lib/routes/cih-index/report.ts diff --git a/lib/routes/cih-index/namespace.ts b/lib/routes/cih-index/namespace.ts new file mode 100644 index 000000000..7bf146a5c --- /dev/null +++ b/lib/routes/cih-index/namespace.ts @@ -0,0 +1,7 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '中指研究院', + url: 'www.cih-index.com', + lang: 'zh-CN', +}; diff --git a/lib/routes/cih-index/report.ts b/lib/routes/cih-index/report.ts new file mode 100644 index 000000000..f909df9bc --- /dev/null +++ b/lib/routes/cih-index/report.ts @@ -0,0 +1,74 @@ +import { Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; + +export const route: Route = { + path: '/report/list/:report?', + categories: ['finance'], + example: '/cih-index/report/list/p1-oaddtime-ddesc', + parameters: { report: '报告 id,可在 URL 中找到,留空为 `p1-oaddtime-ddesc`' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + name: '报告', + maintainers: ['TonyRL'], + handler, + url: 'www.cih-index.com/report/list/p1-oaddtime-ddesc', + radar: [ + { + source: ['www.cih-index.com/report/list/:report'], + }, + ], +}; + +async function handler(ctx) { + const { report = 'p1-oaddtime-ddesc' } = ctx.req.param(); + + const baseUrl = 'https://www.cih-index.com'; + const currentUrl = `${baseUrl}/report/list/${report}`; + const response = await ofetch(currentUrl); + + const $ = load(response); + const initialState = JSON.parse( + $('script:contains("window.__INITIAL_STATE__")') + .text() + .match(/window\.__INITIAL_STATE__\s*=\s*({.*?});/)?.[1] || '{}' + ); + const { dataResult, indNavLists, secondNameFilter, tagList, param } = initialState.data; + + const items = dataResult.reportInfoDtoList.map((info) => { + const pageCount = info.isCharging === 1 ? 3 : info.pageCount; + let images = ''; + for (let i = 1; i <= pageCount; i++) { + images += `
`; + } + return { + title: info.reportTitle, + link: `${baseUrl}/report/detail/${info.reportId}.html`, + pubDate: timezone(parseDate(info.addTime), +8), + category: [...new Set([...info.reportClassTagDtoList.map((t) => t.tag), ...(info.keywordList || [])])], + description: `${info.context}
${images}`, + image: `${info.coverFigureUrl}/200`, + }; + }); + + const category = param.firstId ? indNavLists.find((item) => item.classId === param.firstId)?.className + ' - ' : ''; + const subCategory = param.secondId ? secondNameFilter.find((item) => item.classId === param.secondId)?.className + ' - ' : ''; + const tag = param.tagId ? tagList.find((item) => item.tagId === Number.parseInt(param.tagId))?.tag + ' - ' : ''; + + return { + title: `${category}${subCategory}${tag}中指报告`, + description: $('meta[name="description"]').attr('content'), + image: `${baseUrl}/favicon.ico`, + lang: 'zh-CN', + link: currentUrl, + item: items, + }; +}