From 63529d60dbe233d535960ab4f54e53c4ce6f1a4b Mon Sep 17 00:00:00 2001 From: xyqfer Date: Wed, 26 Dec 2018 15:49:33 +0800 Subject: [PATCH 1/2] Hotfix: juejin pin --- routes/juejin/pins.js | 63 ++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/routes/juejin/pins.js b/routes/juejin/pins.js index 7c170110ce010c..6338536ef335fa 100644 --- a/routes/juejin/pins.js +++ b/routes/juejin/pins.js @@ -2,35 +2,48 @@ const axios = require('../../utils/axios'); module.exports = async (ctx) => { const response = await axios({ - method: 'get', - url: 'https://short-msg-ms.juejin.im/v1/pinList/recommend?uid=&device_id=&token=&src=web&before&limit=50', + method: 'post', + url: 'https://web-api.juejin.im/graphql', + data: { operationName: '', query: '', variables: { size: 20, after: '', afterPosition: '' }, extensions: { query: { id: '964dab26a3f9997283d173b865509890' } } }, + headers: { + 'X-Agent': 'Juejin/Web', + }, }); - const data = response.data.d.list; - - ctx.state.data = { - title: '沸点 - 掘金', - link: 'https://juejin.im/pins', - item: data.map(({ content, objectId, createdAt, user, pictures, url, urlTitle }) => { - const imgs = pictures.reduce((imgs, item) => { - imgs += ` + 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 += `
`; - return imgs; - }, ''); + return imgs; + }, ''); + const url = item.url; + const urlTitle = item.urlTitle; + const description = ` + ${content}
+ ${imgs}
+ ${urlTitle}
+ `; - return { - title: content, - link: `https://juejin.im/pin/${objectId}`, - description: ` - ${content}
- ${imgs}
- ${urlTitle}
- `, - pubDate: new Date(createdAt).toUTCString(), - author: user.username, - guid: objectId, - }; - }), + return { + title, + link, + description, + guid, + pubDate, + author, + }; + }); + + ctx.state.data = { + title: '沸点 - 动态', + link: 'https://juejin.im/activities/recommended', + item: items, }; }; From 3c7ccb0c243987f46d4d6681cbf463befc2bf0d7 Mon Sep 17 00:00:00 2001 From: xyqfer Date: Wed, 26 Dec 2018 15:52:45 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/juejin/pins.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/juejin/pins.js b/routes/juejin/pins.js index 6338536ef335fa..812ca04c5ba668 100644 --- a/routes/juejin/pins.js +++ b/routes/juejin/pins.js @@ -26,7 +26,7 @@ module.exports = async (ctx) => { const url = item.url; const urlTitle = item.urlTitle; const description = ` - ${content}
+ ${content.replace(/\n/g, '
')}
${imgs}
${urlTitle}
`;