From c954d142d61259933a8797568e48d8f23d63a401 Mon Sep 17 00:00:00 2001 From: Discreater Date: Tue, 5 Oct 2021 17:45:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20minecraft=20forge=20mod=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=96=B0=20api=20(#7807)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/game.md | 2 +- lib/routes/curseforge/files.js | 52 ++++++++++++---------------------- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/docs/game.md b/docs/game.md index 512c7159ae..767f7c093e 100644 --- a/docs/game.md +++ b/docs/game.md @@ -232,7 +232,7 @@ pageClass: routes ### CurseForge Mod 更新 - + ### Feed The Beast (FTB) 模组包更新 diff --git a/lib/routes/curseforge/files.js b/lib/routes/curseforge/files.js index 8d985a610b..ee1389e891 100644 --- a/lib/routes/curseforge/files.js +++ b/lib/routes/curseforge/files.js @@ -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}. ` + `
支持的版本为: ${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}.
支持的版本为: ${supportVersions}`; + doc.pubDate = new Date(file.fileDate).toUTCString(); + doc.guid = file.id; + return doc; + }); ctx.state.data = { title: `CurseForge 更新 - ${projectName}`,