diff --git a/lib/routes/jike/user.js b/lib/routes/jike/user.js index 3028f3626..6590a7d36 100644 --- a/lib/routes/jike/user.js +++ b/lib/routes/jike/user.js @@ -17,11 +17,8 @@ module.exports = async (ctx) => { const raw = $('[type = "application/json"]').html(); const data = JSON.parse(raw).props.pageProps; - ctx.state.data = { - title: `${data.user.screenName}的即刻动态`, - link: `https://m.okjike.com/users/${id}`, - image: data.user.avatarImage.picUrl, - item: data.posts.map((item) => { + const items = await Promise.all( + data.posts.map(async (item) => { const typeMap = { ORIGINAL_POST: '发布', REPOST: '转发', @@ -33,6 +30,7 @@ module.exports = async (ctx) => { const linkMap = { ORIGINAL_POST: `https://m.okjike.com/originalPosts/${item.id}`, REPOST: `https://m.okjike.com/reposts/${item.id}`, + MEDIUM: `https://www.okjike.com/medium/${item.id}`, // OFFICIAL_MESSAGE: `https://m.okjike.com/originalPosts/${item.id}`, // ANSWER: `https://m.okjike.com/answer/${item.id}`, // QUESTION: `https://m.okjike.com/originalPosts/${item.id}`, @@ -72,41 +70,76 @@ module.exports = async (ctx) => { } // 部分功能未知 /* else if (item.type === 'ANSWER') { - let answerTextTemplate = ''; - let answerImgTemplate = ''; - let answerImgKeys = []; - item.richtextContent.blocks && - item.richtextContent.blocks.forEach((item) => { - if (item.entityRanges.length && item.text === '[图片]') { - answerImgKeys = [...answerImgKeys, ...Object.keys(item.entityRanges)]; - } else { - answerTextTemplate += item.text; - } - }); + let answerTextTemplate = ''; + let answerImgTemplate = ''; + let answerImgKeys = []; + item.richtextContent.blocks && + item.richtextContent.blocks.forEach((item) => { + if (item.entityRanges.length && item.text === '[图片]') { + answerImgKeys = [...answerImgKeys, ...Object.keys(item.entityRanges)]; + } else { + answerTextTemplate += item.text; + } + }); - if (answerImgKeys.length) { - answerImgKeys.forEach((key) => { - const entity = item.richtextContent.entityMap[key]; - if (entity.type.toUpperCase() === 'IMAGE') { - answerImgTemplate += `
`; - } - }); - } - const answerContent = `回答: ${answerTextTemplate}${answerImgTemplate}`; - content = `${content}${answerContent}`.replace(/\n|\r/g, '
'); - } else if (item.type === 'QUESTION') { - content = `在主题 ${item.topic.content} 提出了一个问题:

${content}`; - } else if (item.type === 'PERSONAL_UPDATE') { - shortenTitle = item.topic.content; - content = ` 主题简介:
${item.topic.briefIntro.replace(/(?:\r\n|\r|\n)/g, '
')}`; - }*/ + if (answerImgKeys.length) { + answerImgKeys.forEach((key) => { + const entity = item.richtextContent.entityMap[key]; + if (entity.type.toUpperCase() === 'IMAGE') { + answerImgTemplate += `
`; + } + }); + } + const answerContent = `回答: ${answerTextTemplate}${answerImgTemplate}`; + content = `${content}${answerContent}`.replace(/\n|\r/g, '
'); + } else if (item.type === 'QUESTION') { + content = `在主题 ${item.topic.content} 提出了一个问题:

${content}`; + } else if (item.type === 'PERSONAL_UPDATE') { + shortenTitle = item.topic.content; + content = ` 主题简介:
${item.topic.briefIntro.replace(/(?:\r\n|\r|\n)/g, '
')}`; + }*/ - return { + const single = { title: `${typeMap[item.type]}了: ${shortenTitle}`, description: `${content}${linkTemplate}${imgTemplate}`, pubDate: new Date(item.createdAt).toUTCString(), link: `${linkMap[item.type]}`, }; - }), + + if (id === 'wenhao1996' && item.topic.id === '553870e8e4b0cafb0a1bef68') { + single.link = item.urlsInText[0].url; + + const data = ( + await got({ + method: 'get', + url: single.link, + headers: { + Referer: `https://m.okjike.com/users/${id}`, + }, + }) + ).data; + const $$ = cheerio.load(data); + $$('span.num,span.arrow').remove(); + + single.title = `一觉醒来世界发生了什么 ${$$('title').text()}`; + + single.description = ''; + $$('div.container') + .find('li.item') + // eslint-disable-next-line array-callback-return + .map((i, j) => { + single.description += `${$$(j).find('a').text()}
`; + }); + } + + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${data.user.screenName}的即刻动态`, + link: `https://m.okjike.com/users/${id}`, + image: data.user.avatarImage.picUrl, + item: items, }; };