mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-17 05:11:57 +08:00
fix(route): minecraft forge mod 使用新 api (#7807)
This commit is contained in:
+1
-1
@@ -232,7 +232,7 @@ pageClass: routes
|
||||
|
||||
### CurseForge Mod 更新
|
||||
|
||||
<Route author="Indexyz" example="/curseforge/files/jei" path="/curseforge/files/:project" :paramsDesc="['项目的短名或者 `Project ID`. 项目的短名可以在地址栏获取到, 例如地址为 `https://minecraft.curseforge.com/projects/non-update`, 短名就为 `non-update`. `Project ID` 可在 `Overview` 中的 `About This Project` 中找到']"/>
|
||||
<Route author="Indexyz Discreater" example="/curseforge/files/jei" path="/curseforge/files/:project" :paramsDesc="['项目的 ID, 可在 mod 主页的 `About This Project` 中找到']"/>
|
||||
|
||||
### Feed The Beast (FTB) 模组包更新
|
||||
|
||||
|
||||
@@ -1,47 +1,31 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const BASE_URL = 'https://minecraft.curseforge.com/';
|
||||
const API_BASE_URL = 'https://addons-ecs.forgesvc.net/api/v2/addon';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { project } = ctx.params;
|
||||
const projectLink = `${BASE_URL}/projects/${project}/files`;
|
||||
const projectFilesReq = await got.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 cache = await ctx.cache.get(document.link);
|
||||
|
||||
if (cache) {
|
||||
return JSON.parse(cache);
|
||||
}
|
||||
const projectAPILink = `${API_BASE_URL}/${project}`;
|
||||
const projectFilesAPILink = `${projectAPILink}/files`;
|
||||
|
||||
const itemReq = await got.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}. ` + `</br> 支持的版本为: ${supportVersions}`;
|
||||
const [projectDesc, projectFiles] = (await Promise.all([got.get(projectAPILink), got.get(projectFilesAPILink)])).map((resp) => resp.data);
|
||||
|
||||
document.pubDate = new Date(Number($item('.standard-datetime').attr('data-epoch')) * 1000).toUTCString();
|
||||
document.guid = $item('.md5').text();
|
||||
const projectName = projectDesc.name;
|
||||
const projectLink = projectDesc.websiteUrl;
|
||||
const author = projectDesc.authors[0].name;
|
||||
|
||||
ctx.cache.set(document.link, JSON.stringify(document));
|
||||
const item = projectFiles.map((file) => {
|
||||
const doc = {};
|
||||
doc.link = projectLink;
|
||||
doc.author = author;
|
||||
doc.title = file.displayName;
|
||||
const supportVersions = file.gameVersion;
|
||||
|
||||
return document;
|
||||
});
|
||||
|
||||
const item = await Promise.all(reqs);
|
||||
doc.description = `${projectName} 发布了新的文件: ${file.displayName}. </br> 支持的版本为: ${supportVersions}`;
|
||||
doc.pubDate = new Date(file.fileDate).toUTCString();
|
||||
doc.guid = file.id;
|
||||
return doc;
|
||||
});
|
||||
|
||||
ctx.state.data = {
|
||||
title: `CurseForge 更新 - ${projectName}`,
|
||||
|
||||
Reference in New Issue
Block a user