From 228313fc3e4279fd530769891cf2cbe9dbb51017 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 15 Aug 2019 19:34:19 +0800 Subject: [PATCH] feat: remove jike, rip --- docs/social-media.md | 28 ------- lib/router.js | 7 -- lib/routes/jike/common.js | 134 --------------------------------- lib/routes/jike/daily.js | 19 ----- lib/routes/jike/topic.js | 69 ----------------- lib/routes/jike/topicSquare.js | 37 --------- lib/routes/jike/topicText.js | 45 ----------- lib/routes/jike/user.js | 114 ---------------------------- 8 files changed, 453 deletions(-) delete mode 100644 lib/routes/jike/common.js delete mode 100644 lib/routes/jike/daily.js delete mode 100644 lib/routes/jike/topic.js delete mode 100644 lib/routes/jike/topicSquare.js delete mode 100644 lib/routes/jike/topicText.js delete mode 100644 lib/routes/jike/user.js diff --git a/docs/social-media.md b/docs/social-media.md index d7c89fcf52..b270b785ed 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -560,34 +560,6 @@ pageClass: routes -## 即刻 - -### 圈子-精选 - - - -::: tip 提示 - -部分圈子如 `一觉醒来发生了什么: 553870e8e4b0cafb0a1bef68` 提供纯文字内容, 圈子-纯文字 /jike/topic/text/:id 可能会提供更好的体验. - -::: - -### 圈子-广场 - - - -### 圈子-纯文字 - - - -### 用户动态 - - - -### 即刻小报 - - - ## 简书 ### 首页 diff --git a/lib/router.js b/lib/router.js index c96f9d893c..306b3cd2fd 100644 --- a/lib/router.js +++ b/lib/router.js @@ -175,13 +175,6 @@ router.get('/youtube/user/:username/:embed?', require('./routes/youtube/user')); router.get('/youtube/channel/:id/:embed?', require('./routes/youtube/channel')); router.get('/youtube/playlist/:id/:embed?', require('./routes/youtube/playlist')); -// 即刻 -router.get('/jike/topic/:id', require('./routes/jike/topic')); -router.get('/jike/topic/text/:id', require('./routes/jike/topicText')); -router.get('/jike/topic/square/:id', require('./routes/jike/topicSquare')); -router.get('/jike/user/:id', require('./routes/jike/user')); -router.get('/jike/daily', require('./routes/jike/daily')); - // 极客时间 router.get('/geektime/column/:cid', require('./routes/geektime/column')); router.get('/geektime/news', require('./routes/geektime/news')); diff --git a/lib/routes/jike/common.js b/lib/routes/jike/common.js deleted file mode 100644 index 21af18739e..0000000000 --- a/lib/routes/jike/common.js +++ /dev/null @@ -1,134 +0,0 @@ -const url = require('url'); - -module.exports = { - emptyResponseCheck: (ctx, data) => { - if (data.length === 0) { - ctx.state.data = { - title: '主题 ID 不存在,或该主题暂无内容', - }; - return true; - } - }, - topicDataHanding: (data) => - data.map((item) => { - let audioName, videoName, linkName; - - // 获取纯文字内容 和 即刻原文链接 - let content, link; - switch (item.type) { - case 'OFFICIAL_MESSAGE': - content = item.content; - link = `https://web.okjike.com/message-detail/${item.id}/officialMessage`; - break; - case 'ORIGINAL_POST': - content = item.content; - link = `https://web.okjike.com/post-detail/${item.id}/originalPost`; - break; - case 'QUESTION': - content = item.title; - link = `https://m.okjike.com/questions/${item.id}`; - break; - default: - content = '未知类型,请前往GitHub提交issue'; - link = 'https://github.com/DIYgod/RSSHub/issues'; - } - - // rss内容 - let description = ''; - - if (item.linkInfo) { - const linkUrl = item.linkInfo.originalLinkUrl || item.linkInfo.linkUrl; - - // 对于即刻抓取的微信公众号文章 特殊处理 - // 此时 Rss原文链接 变为 微信公众号链接 - if (url.parse(linkUrl).host === 'mp.weixin.qq.com') { - link = linkUrl; - } - - // 1. 音频 - const audioObject = item.linkInfo.audio || item.audio; - if (audioObject) { - const audioImage = audioObject.image.picUrl || audioObject.image.thumbnailUrl; - const audioLink = linkUrl; - const audioTitle = audioObject.title; - const audioAuthor = audioObject.author; - audioName = `${audioTitle} - ${audioAuthor}`; - description += ` - - ${audioName} - `; - } - - // 2. 视频 - const videoObject = item.linkInfo.video || item.video; - if (videoObject) { - const videoImage = videoObject.image.picUrl || videoObject.image.thumbnailUrl; - const videoLink = linkUrl; - const videoDuration = Math.floor(videoObject.duration / 60000); - videoName = item.linkInfo.title; - description += ` - - ${videoName || '观看视频'} - 约${videoDuration}分钟 - `; - } - - // 3. 链接 - if (!audioObject && !videoObject && linkUrl) { - // 部分链接有标题 - linkName = item.linkInfo.title; - const linkTitle = linkName || '访问原文'; - // 部分链接有缩略图 - const linkImage = item.linkInfo.pictureUrl; - const imageTag = ``; - description += ` - ${linkImage ? imageTag : ''} - ${linkTitle} - `; - } - } - - // 4. 文字内容 - description += `
${content}`; - - // 5. 图片 - if (item.pictures) { - item.pictures.forEach((pic) => { - if (pic.format === 'gif') { - description += ``; - } else { - // jpeg, bmp, png, gif, webp - // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types - let type = 'jpeg'; - switch (pic.format) { - case 'bmp': - type = 'bmp'; - break; - case 'png': - type = 'png'; - break; - default: - break; - } - const imgUrl = pic.picUrl.match(/\.[a-z0-9]+?\?imageMogr2/) ? pic.picUrl.split('?imageMogr2/')[0] : pic.picUrl.replace(/thumbnail\/.+/, ''); - description += `
`; - } - }); - } - - // rss标题 - // 优先将音频和视频名作为标题 - // 其次将正文内容作为标题 - // 若都没有 则是推送型消息,将连接标题作为主题 - // “无题” fallback - const title = audioName || videoName || content || linkName || '无题'; - - return { - title, - description: description.replace(new RegExp('\n', 'g'), '
'), - pubDate: new Date(item.createdAt).toUTCString(), - link: link, - }; - }), -}; diff --git a/lib/routes/jike/daily.js b/lib/routes/jike/daily.js deleted file mode 100644 index 98f97b91d6..0000000000 --- a/lib/routes/jike/daily.js +++ /dev/null @@ -1,19 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const { - data: { data }, - } = await got.get('https://app.jike.ruguoapp.com/1.0/dailies/list'); - - ctx.state.data = { - title: '即刻小报', - link: 'https://jike.app/', - description: '不定期呈现的即刻内容精选', - item: data.map((item) => ({ - title: item.title, - description: ``, - pubDate: new Date(item.date).toUTCString(), - link: `https://m.okjike.com/dailies/${item.id}`, - })), - }; -}; diff --git a/lib/routes/jike/topic.js b/lib/routes/jike/topic.js deleted file mode 100644 index 3fd8ef0560..0000000000 --- a/lib/routes/jike/topic.js +++ /dev/null @@ -1,69 +0,0 @@ -const got = require('@/utils/got'); -const common = require('./common'); -const cheerio = require('cheerio'); -const dayjs = require('dayjs'); - -module.exports = async (ctx) => { - const id = ctx.params.id; - - const response = await got({ - method: 'post', - url: 'https://app.jike.ruguoapp.com/1.0/messages/history', - headers: { - Referer: `https://m.okjike.com/topics/${id}`, - 'App-Version': '4.12.0', - }, - json: true, - data: { - loadMoreKey: null, - topic: id, - limit: 10, - }, - }); - - const data = response.data.data; - - if (common.emptyResponseCheck(ctx, data)) { - return; - } - - const topic = data[0].topic; - ctx.state.data = { - title: `${topic.content} - 即刻主题精选`, - link: `https://web.okjike.com/topic/${id}/official`, - description: topic.content, - image: topic.squarePicture.picUrl || topic.squarePicture.middlePicUrl || topic.squarePicture.thumbnailUrl, - item: common.topicDataHanding(data), - }; - if (id === '553870e8e4b0cafb0a1bef68' || id === '55963702e4b0d84d2c30ce6f') { - const promises = ctx.state.data.item.map(async (one) => { - const item = { ...one }; - const regResult = /https:\/\/www.okjike.com\/medium\/[a-zA-Z0-9]*/.exec(item.description); - if (regResult) { - const newsUrl = regResult[0]; - const cache = await ctx.cache.get(newsUrl); - if (cache) { - item.description = cache; - } else { - const { data } = await got.get(newsUrl); - const $ = cheerio.load(data); - const upper = $('ul.main > li.item'); - const links = upper.find('a').map((_, ele) => $(ele).attr('href')); - const texts = upper.find('span.text').map((_, ele) => $(ele).text()); - let description = ''; - for (let i = 0; i < links.length; i++) { - description += `${i + 1}、${texts[i]}
`; - } - if (description) { - item.description = description; - await ctx.cache.set(newsUrl, description); - } - } - } - item.title = `${topic.content} ${dayjs(new Date(one.pubDate)).format('MM月DD日')}`; - return item; - }); - - ctx.state.data.item = await Promise.all(promises); - } -}; diff --git a/lib/routes/jike/topicSquare.js b/lib/routes/jike/topicSquare.js deleted file mode 100644 index b4c8c16e2f..0000000000 --- a/lib/routes/jike/topicSquare.js +++ /dev/null @@ -1,37 +0,0 @@ -const got = require('@/utils/got'); -const common = require('./common'); - -module.exports = async (ctx) => { - const id = ctx.params.id; - - const response = await got({ - method: 'post', - url: 'https://app.jike.ruguoapp.com/1.0/squarePosts/list', - headers: { - Referer: `https://m.okjike.com/topics/${id}`, - 'App-Version': '4.12.0', - }, - json: true, - data: { - loadMoreKey: null, - topicId: id, - limit: 20, - }, - }); - - const data = response.data.data; - - if (common.emptyResponseCheck(ctx, data)) { - return; - } - - const topic = data[0].topic; - - ctx.state.data = { - title: `${topic.content} - 即刻主题广场`, - link: `https://web.okjike.com/topic/${id}/user`, - description: topic.content, - image: topic.squarePicture.picUrl || topic.squarePicture.middlePicUrl || topic.squarePicture.thumbnailUrl, - item: common.topicDataHanding(data), - }; -}; diff --git a/lib/routes/jike/topicText.js b/lib/routes/jike/topicText.js deleted file mode 100644 index df03db1332..0000000000 --- a/lib/routes/jike/topicText.js +++ /dev/null @@ -1,45 +0,0 @@ -const got = require('@/utils/got'); -const dayjs = require('dayjs'); -const common = require('./common'); - -module.exports = async (ctx) => { - const id = ctx.params.id; - - const response = await got({ - method: 'post', - url: 'https://app.jike.ruguoapp.com/1.0/messages/history', - headers: { - Referer: `https://m.okjike.com/topics/${id}`, - 'App-Version': '4.12.0', - }, - json: true, - data: { - loadMoreKey: null, - topic: id, - limit: 5, - }, - }); - - const data = response.data.data; - - if (common.emptyResponseCheck(ctx, data)) { - return; - } - - const title = data[0].topic.content; - - ctx.state.data = { - title: `${title} - 即刻`, - link: `https://web.okjike.com/topic/${id}/official`, - description: `${title} - 即刻`, - item: data.map((item) => { - const date = new Date(item.createdAt); - return { - title: `${title} ${dayjs(date).format('MM月DD日')}`, - description: item.content.replace(new RegExp('\n', 'g'), '
'), - pubDate: date.toUTCString(), - link: `https://web.okjike.com/message-detail/${item.id}/officialMessage`, - }; - }), - }; -}; diff --git a/lib/routes/jike/user.js b/lib/routes/jike/user.js deleted file mode 100644 index 5d3724715e..0000000000 --- a/lib/routes/jike/user.js +++ /dev/null @@ -1,114 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const id = ctx.params.id; - - const response = await got({ - method: 'post', - url: 'https://app.jike.ruguoapp.com/1.0/personalUpdate/single', - headers: { - Referer: `https://web.okjike.com/user/${id}/post`, - 'App-Version': '4.12.0', - platform: 'web', - }, - json: true, - data: { - limit: 20, - loadMoreKey: null, - username: id, - }, - }); - - const data = response.data.data; - - ctx.state.data = { - title: `${data[0].user.screenName}的即刻动态`, - link: `https://web.okjike.com/user/${id}`, - image: data[0].user.avatarImage.picUrl, - item: data.map((item) => { - const typeMap = { - ORIGINAL_POST: '发布', - REPOST: '转发', - ANSWER: '回答', - QUESTION: '提问', - PERSONAL_UPDATE: '创建新主题', - }; - - const linkMap = { - OFFICIAL_MESSAGE: `https://web.okjike.com/message-detail/${item.id}/officialMessage`, - ORIGINAL_POST: `https://web.okjike.com/post-detail/${item.id}/originalPost`, - REPOST: `https://web.okjike.com/post-detail/${item.id}/repost`, - ANSWER: `https://m.okjike.com/answers/${item.id}`, - QUESTION: `https://m.okjike.com/questions/${item.id}`, - PERSONAL_UPDATE: `https://web.okjike.com/topic/${item.topic && item.topic.id}/official`, - }; - - let linkTemplate = ''; - if (item.linkInfo && item.linkInfo.linkUrl) { - linkTemplate = `${item.linkInfo.title}
`; - } - - let imgTemplate = ''; - item.pictures && - item.pictures.forEach((item) => { - imgTemplate += `
`; - }); - - let content = item.content || (item.linkInfo && item.linkInfo.title) || (item.question && item.question.title) || item.title || ''; - - let shortenTitle = '一条动态'; - if (content) { - shortenTitle = content.length > 75 ? `${content.substr(0, 75)}...` : content; - content = `${content}

`; - } - - if (item.type === 'REPOST') { - const screenNameTemplate = item.target.user ? `@${item.target.user.screenName}` : ''; - - let repostImgTemplate = ''; - item.target.pictures && - item.target.pictures.forEach((item) => { - repostImgTemplate += `
`; - }); - - const repostContent = `转发 ${screenNameTemplate}: ${item.target.content}${repostImgTemplate}`; - content = `${content}${repostContent}`.replace(/\n|\r/g, '
'); - } 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; - } - }); - - 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 { - title: `${typeMap[item.type]}了: ${shortenTitle}`, - description: `${content}${linkTemplate}${imgTemplate}`, - pubDate: new Date(item.createdAt).toUTCString(), - link: `${linkMap[item.type]}`, - }; - }), - }; -};