Skip to content

Commit

Permalink
feat(route): 新增鸣潮游戏公告、新闻与活动 (#16316)
Browse files Browse the repository at this point in the history
* feat(route): 新增鸣潮游戏公告、新闻与活动

* refactor: refactor cache logic
feat: improved date parse with timezone

* fix: route example

Co-authored-by: Tony <[email protected]>

* fix: namespace url

Co-authored-by: Tony <[email protected]>

* fix: import ofetch from utils

Co-authored-by: Tony <[email protected]>

* fix: unnecessary quotation

* fix: cache the whole object

---------
  • Loading branch information
enpitsuLin authored Jul 31, 2024
1 parent beba6c1 commit adb0f64
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/routes/kurogames/namespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Namespace } from '@/types';

export const namespace: Namespace = {
name: '库洛游戏',
url: 'www.kurogames.com',
categories: ['game'],
};
59 changes: 59 additions & 0 deletions lib/routes/kurogames/wutheringwaves/news.ts
Original file line number Diff line number Diff line change
@@ -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<NewsItem[]>('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<NewsItem>(contentUrl, { query: { t: Date.now() } });
const $ = cheerio.load(data.articleContent);

item.description = $.html() ?? i.articleDesc ?? '';
return item;
}) as Promise<DataItem>;
})
);
return {
title: '《鸣潮》— 游戏公告、新闻和活动',
link: 'https://mc.kurogames.com/main#news',
item,
language: 'zh-cn',
};
},
};

0 comments on commit adb0f64

Please sign in to comment.