feat(curseforge): add curseforge support

This commit is contained in:
Indexyz
2018-09-03 02:32:55 +08:00
parent 66e4133d19
commit 365f9fbca0
3 changed files with 57 additions and 0 deletions

View File

@@ -2588,3 +2588,15 @@ GitHub 官方也提供了一些 RSS:
### App Store/Mac App Store ### App Store/Mac App Store
见 <#app-store-mac-app-store> 见 <#app-store-mac-app-store>
## Minecraft CurseForge
### Mod 更新
举例: <https://rsshub.app/curseforge/files/jei>
路由: `/curseforge/files/:project`
参数:
- project: 项目的短名或者 `Project ID`. 项目的短名可以在地址栏获取到, 例如地址为 `https://minecraft.curseforge.com/projects/non-update`, 短名就为 `non-update`. `Project ID` 可在 `Overview` 中的 `About This Project` 中找到

View File

@@ -506,4 +506,7 @@ router.get('/zaobao/znews/:type?', require('./routes/zaobao/znews'));
// Apple // Apple
router.get('/apple/exchange_repair', require('./routes/apple/exchange_repair')); router.get('/apple/exchange_repair', require('./routes/apple/exchange_repair'));
// Minecraft CurseForge
router.get('/curseforge/files/:project', require('./routes/curseforge/files'));
module.exports = router; module.exports = router;

View File

@@ -0,0 +1,42 @@
const axios = require('../../utils/axios');
const cheerio = require('cheerio');
const BASE_URL = 'https://minecraft.curseforge.com/';
module.exports = async (ctx) => {
const { project } = ctx.params;
const projectLink = `${BASE_URL}/projects/${project}/files`;
const projectFilesReq = await axios.get(projectLink);
const { data } = projectFilesReq;
const $ = cheerio.load(data);
const projectName = $('.project-title span').text();
const reqs = $('.project-file-name-container > a').get()
.map(async (item) => {
const el = $(item);
const document = {};
const link = el.attr('href');
document.link = `${BASE_URL}${link}`;
const itemReq = await axios.get(document.link);
const $item = cheerio.load(itemReq.data);
const supportVersions = $item('.details-versions li')
.get()
.map((item) => $item(item).text())
.join(', ');
document.author = $item('.user-tag a').text();
document.title = $item('.details-header > h3').text();
document.description = `${projectName}${document.author} 发布了新的文件: ${document.title}. 支持的版本为: ${supportVersions}`;
document.pubDate = new Date(Number($item('.standard-datetime').attr('data-epoch')) * 1000).toUTCString();
document.guid = $item('.md5').text();
return document;
});
const item = await Promise.all(reqs);
ctx.state.data = {
title: `CurseForge 更新 - ${projectName}`,
link: projectLink,
description: 'CurseForge Mod 更新',
item,
};
};