From adb0f64315c050b1020c9916a0c38106eb555db3 Mon Sep 17 00:00:00 2001 From: enpitsulin Date: Thu, 1 Aug 2024 06:26:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=B0=E5=A2=9E=E9=B8=A3?= =?UTF-8?q?=E6=BD=AE=E6=B8=B8=E6=88=8F=E5=85=AC=E5=91=8A=E3=80=81=E6=96=B0?= =?UTF-8?q?=E9=97=BB=E4=B8=8E=E6=B4=BB=E5=8A=A8=20(#16316)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 新增鸣潮游戏公告、新闻与活动 * refactor: refactor cache logic feat: improved date parse with timezone * fix: route example Co-authored-by: Tony * fix: namespace url Co-authored-by: Tony * fix: import ofetch from utils Co-authored-by: Tony * fix: unnecessary quotation * fix: cache the whole object --------- --- lib/routes/kurogames/namespace.ts | 7 +++ lib/routes/kurogames/wutheringwaves/news.ts | 59 +++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 lib/routes/kurogames/namespace.ts create mode 100644 lib/routes/kurogames/wutheringwaves/news.ts diff --git a/lib/routes/kurogames/namespace.ts b/lib/routes/kurogames/namespace.ts new file mode 100644 index 00000000000000..91dfa3b6eab2d6 --- /dev/null +++ b/lib/routes/kurogames/namespace.ts @@ -0,0 +1,7 @@ +import { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '库洛游戏', + url: 'www.kurogames.com', + categories: ['game'], +}; diff --git a/lib/routes/kurogames/wutheringwaves/news.ts b/lib/routes/kurogames/wutheringwaves/news.ts new file mode 100644 index 00000000000000..95e161378669b0 --- /dev/null +++ b/lib/routes/kurogames/wutheringwaves/news.ts @@ -0,0 +1,59 @@ +import { DataItem, Route } from '@/types'; +import cache from '@/utils/cache'; +import { parseDate } from '@/utils/parse-date'; +import timezone from '@/utils/timezone'; +import * as cheerio from 'cheerio'; +import ofetch from '@/utils/ofetch'; + +interface NewsItem { + articleContent: string; + articleDesc: string; + articleId: number; + articleTitle: string; + articleType: number; + createTime: string; + sortingMark: number; + startTime: string; + suggestCover: string; + top: number; +} + +export const route: Route = { + path: '/wutheringwaves/news', + categories: ['game'], + example: '/kurogames/wutheringwaves/news', + name: '鸣潮 — 游戏公告、新闻与活动', + radar: [ + { + source: ['mc.kurogames.com/m/main/news', 'mc.kurogames.com/main'], + }, + ], + maintainers: ['enpitsulin'], + description: '', + async handler() { + const res = await ofetch('https://media-cdn-mingchao.kurogame.com/akiwebsite/website2.0/json/G152/zh/ArticleMenu.json', { query: { t: Date.now() } }); + const item = await Promise.all( + res.map((i) => { + const contentUrl = `https://media-cdn-mingchao.kurogame.com/akiwebsite/website2.0/json/G152/zh/article/${i.articleId}.json`; + const item = { + title: i.articleTitle, + pubDate: timezone(parseDate(i.createTime), +8), + link: `https://mc.kurogames.com/main/news/detail/${i.articleId}`, + } as DataItem; + return cache.tryGet(contentUrl, async () => { + const data = await ofetch(contentUrl, { query: { t: Date.now() } }); + const $ = cheerio.load(data.articleContent); + + item.description = $.html() ?? i.articleDesc ?? ''; + return item; + }) as Promise; + }) + ); + return { + title: '《鸣潮》— 游戏公告、新闻和活动', + link: 'https://mc.kurogames.com/main#news', + item, + language: 'zh-cn', + }; + }, +};