From ba2c3419b66cbb3a10a900ec3046a9b10d2ecd40 Mon Sep 17 00:00:00 2001 From: SunBK201 Date: Wed, 9 Nov 2022 21:25:11 +0800 Subject: [PATCH] feat(route): Add ymgal.games RSS (#11241) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): Add 月幕 Galgame RSS * fix(route): improve cache and fix radar path * feat(route): add all type * docs: fix param * fix: sort publishTime --- docs/anime.md | 12 ++++++++ lib/v2/ymgal/article.js | 61 ++++++++++++++++++++++++++++++++++++++ lib/v2/ymgal/maintainer.js | 3 ++ lib/v2/ymgal/radar.js | 25 ++++++++++++++++ lib/v2/ymgal/router.js | 3 ++ 5 files changed, 104 insertions(+) create mode 100644 lib/v2/ymgal/article.js create mode 100644 lib/v2/ymgal/maintainer.js create mode 100644 lib/v2/ymgal/radar.js create mode 100644 lib/v2/ymgal/router.js diff --git a/docs/anime.md b/docs/anime.md index 751f7ea2e..d19dc9675 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -711,6 +711,18 @@ Sources +## 月幕 Galgame + +### 文章 + + + +| All | 资讯 | 专栏 | +| --- | ---- | ------ | +| all | news | column | + + + ## 终点分享 ### 最新汉化 diff --git a/lib/v2/ymgal/article.js b/lib/v2/ymgal/article.js new file mode 100644 index 000000000..49097fd94 --- /dev/null +++ b/lib/v2/ymgal/article.js @@ -0,0 +1,61 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +const host = 'https://www.ymgal.games'; + +const types = { + news: '?type=NEWS&page=1', + column: '?type=COLUMN&page=1', +}; + +module.exports = async (ctx) => { + const type = ctx.params.type || 'all'; + + const link = `${host}/co/topic/list` + types[type]; + let data = []; + if (type === 'all') { + await Promise.all( + Object.values(types).map(async (type) => { + const response = await got(`${host}/co/topic/list${type}`); + data.push.apply(data, response.data.data); + }) + ); + data = data.sort((a, b) => b.publishTime - a.publishTime).slice(0, 10); + } else { + const response = await got(link); + data = response.data.data; + } + + const items = await Promise.all( + data.map((item) => { + const itemUrl = host + '/co/article/' + item.topicId; + return ctx.cache.tryGet(itemUrl, async () => { + const result = await got(itemUrl); + const $ = cheerio.load(result.data); + const description = $('article').html().trim(); + return { + title: item.title, + link: itemUrl, + pubDate: timezone(parseDate(item.publishTime), 8), + description, + }; + }); + }) + ); + + let info = '全部文章'; + if (type === 'news') { + info = '资讯'; + } else if (type === 'column') { + info = '专栏'; + } + + ctx.state.data = { + title: `月幕 Galgame - ${info}`, + link: 'https://www.ymgal.games/co/article', + description: `月幕 Galgame - ${info}`, + item: items, + }; +}; diff --git a/lib/v2/ymgal/maintainer.js b/lib/v2/ymgal/maintainer.js new file mode 100644 index 000000000..5090f3217 --- /dev/null +++ b/lib/v2/ymgal/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/article/:type?': ['SunBK201'], +}; diff --git a/lib/v2/ymgal/radar.js b/lib/v2/ymgal/radar.js new file mode 100644 index 000000000..6e2302912 --- /dev/null +++ b/lib/v2/ymgal/radar.js @@ -0,0 +1,25 @@ +module.exports = { + 'ymgal.games': { + _name: '月幕 Galgame', + '.': [ + { + title: '全部文章', + docs: 'https://docs.rsshub.app/anime.html#yue-mu-galgame', + source: ['/co/article'], + target: '/ymgal/article/all', + }, + { + title: '资讯', + docs: 'https://docs.rsshub.app/anime.html#yue-mu-galgame', + source: ['/co/article'], + target: '/ymgal/article/news', + }, + { + title: '专栏', + docs: 'https://docs.rsshub.app/anime.html#yue-mu-galgame', + source: ['/co/article'], + target: '/ymgal/article/column', + }, + ], + }, +}; diff --git a/lib/v2/ymgal/router.js b/lib/v2/ymgal/router.js new file mode 100644 index 000000000..8fcc9ea22 --- /dev/null +++ b/lib/v2/ymgal/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/article/:type?', require('./article')); +};