fix: steam news center (#6481)
This commit is contained in:
parent
2812499a9d
commit
2fcf82a89c
|
|
@ -315,7 +315,13 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
|
|||
|
||||
### Steam news
|
||||
|
||||
<Route author="maple3142" example="/steam/news/282800" path="/steam/news/:appids" :paramsDesc="['游戏 id']" radar="1" rssbud="1"/>
|
||||
<Route author="maple3142" example="/steam/news/1091500/schinese" path="/steam/news/:appid/:language?" :paramsDesc="['游戏 id', '语言,默认简体中文']" radar="1" rssbud="1">
|
||||
|
||||
| 语言 (Language) | 简体中文 (Simplified Chinese) | 繁體中文 (Traditional Chinese) | 日本語 (Japanese) | 한국어 (Korean) | Български (Bulgarian) | Čeština (Czech) | Dansk (Danish) | Deutsch (German) | Español - España (Spanish - Spain) | Español - Latinoamérica (Spanish - Latin America), | Ελληνικά (Greek) | Français (French) | Italiano (Italian) | Magyar (Hungarian) | Nederlands (Dutch) | Norsk (Norwegian) | Polski (Polish) | Português (Portuguese) | Português - Brasil (Portuguese - Brazil) | Română (Romanian) | Русский (Russian) | Suomi (Finnish) | Svenska (Swedish) | Türkçe (Turkish) | Tiếng Việt (Vietnamese) | Українська (Ukrainian) |
|
||||
| --------------- | ----------------------------- | ------------------------------ | ----------------- | --------------- | --------------------- | --------------- | -------------- | ---------------- | ---------------------------------- | -------------------------------------------------- | ---------------- | ----------------- | ------------------ | ------------------ | ------------------ | ----------------- | --------------- | ---------------------- | ---------------------------------------- | ----------------- | ----------------- | --------------- | ----------------- | ---------------- | ----------------------- | ---------------------- |
|
||||
| | schinese | tchinese | japanese | koreana | bulgarian | czech | danish | german | spanish | latam | greek | french | italian | hungarian | dutch | norwegian | polish | portuguese | brazilian | romanian | russian | finnish | swedish | turkish | vietnamese | ukrainian |
|
||||
|
||||
</Route>
|
||||
|
||||
## SteamGifts
|
||||
|
||||
|
|
|
|||
|
|
@ -1216,7 +1216,7 @@ router.get('/huxiu/collection/:id', require('./routes/huxiu/collection'));
|
|||
|
||||
// Steam
|
||||
router.get('/steam/search/:params', require('./routes/steam/search'));
|
||||
router.get('/steam/news/:appids', require('./routes/steam/news'));
|
||||
router.get('/steam/news/:appid/:language?', require('./routes/steam/news'));
|
||||
|
||||
// Steamgifts
|
||||
router.get('/steamgifts/discussions/:category?', require('./routes/steam/steamgifts/discussions'));
|
||||
|
|
|
|||
|
|
@ -1,28 +1,45 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const queryString = require('query-string');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { appids } = ctx.params;
|
||||
const { data: html } = await got.get(`https://store.steampowered.com/news/`, {
|
||||
searchParams: queryString.stringify({ appids }),
|
||||
const { appid, language = 'schinese' } = ctx.params;
|
||||
const response = await got.get(`https://store.steampowered.com/news/app/${appid}`, {
|
||||
headers: {
|
||||
cookie: `Steam_Language=${language}`,
|
||||
},
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
const { events } = JSON.parse($('#application_config').attr('data-initialevents'));
|
||||
|
||||
const item = events.map((event) => {
|
||||
event.announcement_body.body = event.announcement_body.body
|
||||
.replace(/\[img]\{STEAM_CLAN_IMAGE}/g, '<img noopener noreferer style="max-width:100%;" src="https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/clans')
|
||||
.replace(/\[\/img]/g, '"/>')
|
||||
.replace(/\[h1]/g, '<h1>')
|
||||
.replace(/\[\/h1]/g, '</h1>')
|
||||
.replace(/\[h2]/g, '<h2>')
|
||||
.replace(/\[\/h2]/g, '</h2>')
|
||||
.replace(/\[b]/g, '<b>')
|
||||
.replace(/\[\/b]/g, '</b>')
|
||||
.replace(/\[i]/g, '<i>')
|
||||
.replace(/\[\/i]/g, '</i>')
|
||||
.replace(/\[url=\s?(http.*?)]/g, '<a href="$1">')
|
||||
.replace(/\[\/url]/g, '</a>')
|
||||
.replace(/\[list]/g, '<ul>')
|
||||
.replace(/\[\/list]/g, '</ul>')
|
||||
.replace(/\[\*]/g, '<li>');
|
||||
|
||||
return {
|
||||
title: event.event_name,
|
||||
link: `https://store.steampowered.com/news/app/${appid}/view/${event.gid}`,
|
||||
pubDate: new Date(event.announcement_body.posttime * 1000),
|
||||
description: event.announcement_body.body,
|
||||
};
|
||||
});
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('.pageheader').text(),
|
||||
link: `https://store.steampowered.com/news/?appids=${appids}`,
|
||||
item: $('#news div[id]')
|
||||
.toArray()
|
||||
.map((a) => {
|
||||
const $el = $(a);
|
||||
return {
|
||||
title: $el.find('.posttitle').text(),
|
||||
link: $el.find('.posttitle a').attr('href'),
|
||||
author: $el.find('.feed').text(),
|
||||
description: $el.find('.body').html(),
|
||||
};
|
||||
})
|
||||
.filter((it) => it.title),
|
||||
title: $('head title').text(),
|
||||
link: `https://store.steampowered.com/news/app/${appid}`,
|
||||
item,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue