From d84bb8473e358757d2346b4d68edd9509468a115 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 20 Jun 2021 11:49:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E5=B9=95=E5=B8=83=E7=B2=BE?= =?UTF-8?q?=E9=80=89=E7=A4=BE=E5=8C=BA=20(#7690)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/study.md | 2 +- lib/router.js | 2 +- lib/routes/mubu/explore.js | 54 ++++++++++++++++++-------------------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/docs/study.md b/docs/study.md index f62eb0ca4..8bef90a44 100644 --- a/docs/study.md +++ b/docs/study.md @@ -246,7 +246,7 @@ pageClass: routes ## 幕布精选 - + ## 扇贝 diff --git a/lib/router.js b/lib/router.js index d9a6de415..9768f9b81 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3686,7 +3686,7 @@ router.get('/mind42/search/:keyword', require('./routes/mind42/search')); router.get('/mind42/:caty?', require('./routes/mind42/index')); // 幕布网 -router.get('/mubu/explore/:tagId/:title?', require('./routes/mubu/explore')); +router.get('/mubu/explore/:category?/:title?', require('./routes/mubu/explore')); // Esquirehk router.get('/esquirehk/tag/:id', require('./routes/esquirehk/tag')); diff --git a/lib/routes/mubu/explore.js b/lib/routes/mubu/explore.js index d699d98c7..fe5ea6bc1 100644 --- a/lib/routes/mubu/explore.js +++ b/lib/routes/mubu/explore.js @@ -2,21 +2,22 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); module.exports = async (ctx) => { - const tagId = ctx.params.tagId; const title = ctx.params.title || ''; + const category = ctx.params.category || '0'; + + const rootUrl = 'https://mubu.com'; + const apiUrl = 'https://api2.mubu.com'; + const exploreUrl = `${apiUrl}/v3/api/explore/get_explore_doc_list`; + const documentUrl = `${apiUrl}/v3/api/explore/get`; const response = await got({ method: 'post', - url: `https:mubu.com/api/community/query_document`, - form: { - page: 1, - tagId, - title: '', - type: '', - docRecommend: '', - }, - headers: { - referer: 'https:mubu.com/explore', + url: exploreUrl, + json: { + categoryId: '3', + pageSize: '20', + start: '', + type: category === '0' ? 0 : 1, }, }); @@ -29,8 +30,8 @@ module.exports = async (ctx) => { } if (Array.isArray(node.images)) { ele += node.images - .map((pic) => `https://api2.mubu.com/v3/${pic.uri}`) - .map((uri) => `
`) + .map((pic) => `${apiUrl}/v3/${pic.url}`) + .map((url) => `
`) .join(''); } @@ -41,20 +42,17 @@ module.exports = async (ctx) => { return `
    ${list}
`; }; - const item = await Promise.all( + const items = await Promise.all( response.data.data.rows.slice(0, 20).map((item) => - ctx.cache.tryGet(`https://mubu.com/doc/explore/${item.id}`, async () => { - const res = await got({ + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ method: 'post', - url: `https://api2.mubu.com/v3/api/document/view/get`, + url: documentUrl, json: { - docId: item.documentId, - }, - headers: { - referer: 'https://mubu.com/', + exploreDocId: item.exploreDocId, }, }); - const content = JSON.parse(res.data.data.definition); + const content = JSON.parse(detailResponse.data.data.definition); const description = h(content.nodes); const $ = cheerio.load(description); @@ -63,18 +61,18 @@ module.exports = async (ctx) => { return { title: item.title, - link: `https://mubu.com/doc/explore/${item.id}`, - description: `

${item.title}

` + $('*').html(), - pubDate: new Date(item.publishTime), author: item.userName, + pubDate: new Date(item.submitTime), + link: `${rootUrl}/explore/${item.exploreDocId}`, + description: `

${item.title}

` + $('*').html(), }; }) ) ); ctx.state.data = { - title: title ? `幕布 - ${title}` : '幕布', - link: `https://mubu.com/explore#${tagId}`, - item, + title: `${title ? `${title} - ` : ''}幕布精选社区`, + link: `${rootUrl}/explore?categoryId=${category}`, + item: items, }; };