From ff3ea5ade31e719f046228d0cd3aaed0bf5da6d8 Mon Sep 17 00:00:00 2001 From: mukelongji <54195094+Coxwtwo@users.noreply.github.com> Date: Fri, 15 Aug 2025 22:41:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E7=BB=9D=E5=8C=BA?= =?UTF-8?q?=E9=9B=B6=E6=96=B0=E9=97=BB=E8=B5=84=E8=AE=AF=20(#19840)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/mihoyo/zzz/news.ts | 106 ++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 lib/routes/mihoyo/zzz/news.ts diff --git a/lib/routes/mihoyo/zzz/news.ts b/lib/routes/mihoyo/zzz/news.ts new file mode 100644 index 0000000000..7a941be1d0 --- /dev/null +++ b/lib/routes/mihoyo/zzz/news.ts @@ -0,0 +1,106 @@ +import { Route } from '@/types'; +import got from '@/utils/got'; +import { parseDate } from '@/utils/parse-date'; + +const categories = { + 'zh-cn': { + 'news-all': { + id: '273', + title: '最新', + }, + news: { + id: '278', + title: '新闻', + }, + notice: { + id: '279', + title: '公告', + }, + activity: { + id: '280', + title: '活动', + }, + title: '绝区零', + link: 'https://zzz.mihoyo.com/news', + apiRootUrl: 'https://api-takumi-static.mihoyo.com/content_v2_user/app/706fd13a87294881/getContentList', + }, + 'zh-tw': { + 'news-all': { + id: '288', + title: '最新', + }, + news: { + id: '295', + title: '新聞', + }, + notice: { + id: '296', + title: '公告', + }, + activity: { + id: '297', + title: '活動', + }, + title: '絕區零', + link: 'https://zenless.hoyoverse.com/zh-tw/news', + apiRootUrl: 'https://api-os-takumi-static.hoyoverse.com/content_v2_user/app/3e9196a4b9274bd7/getContentList', + }, +}; + +export const route: Route = { + path: '/zzz/:location?/:category?', + categories: ['game'], + example: '/mihoyo/zzz', + parameters: { location: '区域,可选 `zh-cn`(国服,简中)或 `zh-tw`(国际服,繁中)', category: '分类,见下表,默认为最新' }, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['zzz.mihoyo.com/news'], + target: '/zzz', + }, + ], + name: '绝区零', + maintainers: ['Yeye-0426'], + handler, + url: 'zzz.mihoyo.com/news', + description: `#### 新闻 {#mi-ha-you-jue-qu-ling-xin-wen} + +| 最新 | 新闻 | 公告 | 活动 | +| -------- | ---- | ------ | -------- | +| news-all | news | notice | activity |`, +}; + +async function handler(ctx) { + // location 地区 category 类型 + const { location = 'zh-cn', category = 'news-all' } = ctx.req.param(); + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 50; + + const params = { + 'zh-cn': `iPageSize=${limit}&iPage=1&sLangKey=zh-cn&isPreview=0&iChanId=${categories[location][category].id}`, + 'zh-tw': `iPageSize=${limit}&iPage=1&sLangKey=zh-tw&isPreview=0&iChanId=${categories[location][category].id}`, + }; + + const apiUrl = `${categories[location].apiRootUrl}?${params[location]}`; + const response = await got(apiUrl); + const list = response.data.data.list; + const items = list.map((item) => ({ + title: item.sTitle, + description: item.sContent, + link: `${categories[location].link}/${item.iInfoId}`, + pubDate: parseDate(item.dtStartTime), + category: item.sCategoryName, + })); + + return { + title: `${categories[location][category].title}-${categories[location].title}`, + link: `${categories[location].link}?category=${categories[location][category].id}`, + item: items, + }; +}