From b8c7278dc6512e677c634be22ba373f55ace88d0 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Fri, 1 Nov 2024 03:44:41 +0800 Subject: [PATCH] feat(route): add Counter Strike News (#17394) --- lib/routes/counter-strike/namespace.ts | 8 ++ lib/routes/counter-strike/news.ts | 144 +++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 lib/routes/counter-strike/namespace.ts create mode 100644 lib/routes/counter-strike/news.ts diff --git a/lib/routes/counter-strike/namespace.ts b/lib/routes/counter-strike/namespace.ts new file mode 100644 index 000000000..98157da3c --- /dev/null +++ b/lib/routes/counter-strike/namespace.ts @@ -0,0 +1,8 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: 'Counter Strike', + url: 'counter-strike.net', + categories: ['game'], + description: '', +}; diff --git a/lib/routes/counter-strike/news.ts b/lib/routes/counter-strike/news.ts new file mode 100644 index 000000000..d7d5abc5c --- /dev/null +++ b/lib/routes/counter-strike/news.ts @@ -0,0 +1,144 @@ +import { Route } from '@/types'; + +import got from '@/utils/got'; +import { load } from 'cheerio'; +import bbcode from 'bbcodejs'; +import { parseDate } from '@/utils/parse-date'; + +export const handler = async (ctx) => { + const { category = 'all', language = 'english' } = ctx.req.param(); + const limit = ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 100; + + const rootUrl = 'https://www.counter-strike.net'; + const apiRootUrl = 'https://store.steampowered.com'; + const cdnRootUrl = 'https://media.st.dl.eccdnx.com'; + const currentUrl = new URL(`news${category && category !== 'all' ? `/${category}` : ''}${language ? `?l=${language}` : ''}`, rootUrl).href; + const apiUrl = new URL('events/ajaxgetpartnereventspageable/', apiRootUrl).href; + + const { data: response } = await got(apiUrl, { + searchParams: { + clan_accountid: 0, + appid: 730, + offset: 0, + count: limit, + l: language, + }, + }); + + const bbcodeParser = new bbcode.Parser(); + + const items = response.events + .filter((item) => (category === 'updates' ? item.event_type === 12 : item.event_type !== 12)) + .slice(0, limit) + .map((item) => { + const title = item.event_name; + const description = bbcodeParser.toHTML(item.announcement_body.body); + const guid = `counter-strike-news-${item.gid}`; + + return { + title, + description, + pubDate: parseDate(item.announcement_body.posttime, 'X'), + link: new URL(`newsentry/${item.gid}`, rootUrl).href, + category: item.announcement_body.tags, + guid, + id: guid, + content: { + html: description, + text: item.announcement_body.body, + }, + updated: parseDate(item.announcement_body.updatetime, 'X'), + }; + }); + + const { data: currentResponse } = await got(currentUrl); + + const $ = load(currentResponse); + + const author = 'Counter Strike'; + const image = new URL('apps/csgo/images/dota_react//blog/default_cover.jpg', cdnRootUrl).href; + + return { + title: `${author} - ${category === 'updates' ? 'Updates' : 'News'}`, + description: $('title').text(), + link: currentUrl, + item: items, + allowEmpty: true, + image, + author, + language, + }; +}; + +export const route: Route = { + path: '/news/:category?/:language?', + name: 'News', + url: 'www.counter-strike.net', + maintainers: ['nczitzk'], + handler, + example: '/counter-strike/news', + parameters: { category: 'Category, `updates` or `all`, `all` by default', language: 'Language, english by default, see below for more languages' }, + description: `:::tip + If you subscribe to [Updates in English](https://www.counter-strike.net/news/updates?l=english),where the URL is \`https://www.counter-strike.net/news/updates?l=english\`, extract the \`l\`, which is \`english\`, and use it as the parameter to fill in. Therefore, the route will be [\`/counter-strike/news/updates/english\`](https://rsshub.app/counter-strike/news/updates/english). + ::: + +
+ More languages + +| 语言代码 | 语言名称 | +| ------------------------------------------------- | ---------- | +| English | english | +| Español - España (Spanish - Spain) | spanish | +| Français (French) | french | +| Italiano (Italian) | italian | +| Deutsch (German) | german | +| Ελληνικά (Greek) | greek | +| 한국어 (Korean) | koreana | +| 简体中文 (Simplified Chinese) | schinese | +| 繁體中文 (Traditional Chinese) | tchinese | +| Русский (Russian) | russian | +| ไทย (Thai) | thai | +| 日本語 (Japanese) | japanese | +| Português (Portuguese) | portuguese | +| Português - Brasil (Portuguese - Brazil) | brazilian | +| Polski (Polish) | polish | +| Dansk (Danish) | danish | +| Nederlands (Dutch) | dutch | +| Suomi (Finnish) | finnish | +| Norsk (Norwegian) | norwegian | +| Svenska (Swedish) | swedish | +| Čeština (Czech) | czech | +| Magyar (Hungarian) | hungarian | +| Română (Romanian) | romanian | +| Български (Bulgarian) | bulgarian | +| Türkçe (Turkish) | turkish | +| Українська (Ukrainian) | ukrainian | +| Tiếng Việt (Vietnamese) | vietnamese | +| Español - Latinoamérica (Spanish - Latin America) | latam | + +
+ `, + categories: ['game'], + + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportRadar: true, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['www.counter-strike.net/news/:category'], + target: (params, url) => { + url = new URL(url); + const category = params.category; + const language = url.searchParams.get('l'); + + return `/news${category ? `/${category}${language ? `/${language}` : ''}` : ''}`; + }, + }, + ], +};