-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): 新增鸣潮游戏公告、新闻与活动 (#16316)
* feat(route): 新增鸣潮游戏公告、新闻与活动 * refactor: refactor cache logic feat: improved date parse with timezone * fix: route example Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix: namespace url Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix: import ofetch from utils Co-authored-by: Tony <TonyRL@users.noreply.github.com> * fix: unnecessary quotation * fix: cache the whole object ---------
- Loading branch information
1 parent
beba6c1
commit adb0f64
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; | ||
}, | ||
}; |