From 8636c4556a9e6888a7959bfed344e727142a75b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=89=E5=87=89?= Date: Sat, 1 Aug 2020 21:46:48 +0800 Subject: [PATCH] fix: juejin pins (#5323) --- lib/routes/juejin/pins.js | 63 ++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/lib/routes/juejin/pins.js b/lib/routes/juejin/pins.js index 8d96de0fd6..108b429af6 100644 --- a/lib/routes/juejin/pins.js +++ b/lib/routes/juejin/pins.js @@ -3,53 +3,42 @@ const got = require('@/utils/got'); module.exports = async (ctx) => { const response = await got({ method: 'post', - url: 'https://web-api.juejin.im/graphql', - json: { operationName: '', query: '', variables: { size: 20, after: '', afterPosition: '' }, extensions: { query: { id: '964dab26a3f9997283d173b865509890' } } }, - headers: { - 'X-Agent': 'Juejin/Web', - }, + url: 'https://apinew.juejin.im/recommend_api/v1/short_msg/recommend', + json: true, + data: { id_type: 4, sort_type: 300, cursor: '0', limit: 20 }, }); - const items = response.data.data.recommendedActivityFeed.items.edges.map( - ({ - node: { - targets: [item], - }, - }) => { - const content = item.content; - const title = content; - const guid = item.id; - const link = `https://juejin.im/pin/${guid}`; - const pubDate = new Date(item.createdAt).toUTCString(); - const author = item.user.username; - const imgs = item.pictures.reduce((imgs, item) => { - imgs += ` + const items = response.data.data.map((item) => { + const content = item.msg_Info.content; + const title = content; + const guid = item.msg_id; + const link = `https://juejin.im/pin/${guid}`; + const pubDate = new Date(parseInt(item.msg_Info.ctime) * 1000).toUTCString(); + const author = item.author_user_info.user_name; + const imgs = item.msg_Info.pic_list.reduce((imgs, item) => { + imgs += `
`; - return imgs; - }, ''); - const url = item.url; - const urlTitle = item.urlTitle; - const description = ` + return imgs; + }, ''); + const description = ` ${content.replace(/\n/g, '
')}
${imgs}
- ${urlTitle}
`; - return { - title, - link, - description, - guid, - pubDate, - author, - }; - } - ); + return { + title, + link, + description, + guid, + pubDate, + author, + }; + }); ctx.state.data = { - title: '沸点 - 动态', - link: 'https://juejin.im/activities/recommended', + title: '沸点 - 推荐', + link: 'https://juejin.im/pins/recommended', item: items, }; };