From 2e0d38e4dd6e2181a8ebaa92513264a2eb1af6cb Mon Sep 17 00:00:00 2001 From: BugWriter2 Date: Wed, 19 Aug 2020 04:22:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20soul=20=E7=83=AD=E9=97=A8?= =?UTF-8?q?=E7=9E=AC=E9=97=B4=20(#5412)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: codefactor-io --- docs/social-media.md | 4 +++ lib/router.js | 1 + lib/routes/soul/hot.js | 63 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lib/routes/soul/hot.js diff --git a/docs/social-media.md b/docs/social-media.md index 6a5822e38..1c0962b50 100644 --- a/docs/social-media.md +++ b/docs/social-media.md @@ -415,6 +415,10 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性 +### 热门瞬间 + + + ## Telegram ### 频道 diff --git a/lib/router.js b/lib/router.js index 8f11db6b8..f88659058 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1963,6 +1963,7 @@ router.get('/gouhuo/strategy', require('./routes/gouhuo/strategy')); // Soul router.get('/soul/:id', require('./routes/soul')); +router.get('/soul/posts/hot', require('./routes/soul/hot')); // 单向空间 router.get('/owspace/read/:type?', require('./routes/owspace/read')); diff --git a/lib/routes/soul/hot.js b/lib/routes/soul/hot.js new file mode 100644 index 000000000..555a2cf56 --- /dev/null +++ b/lib/routes/soul/hot.js @@ -0,0 +1,63 @@ +const got = require('@/utils/got'); + +const generateResponse = async (items) => ({ + // 源标题 + title: '热门瞬间', + // 源链接 + link: 'https://api-h5.soulapp.cn/html/v2/post/hot?pageIndex=2', + item: items.map((item) => ({ + title: `「${item.uName}」的瞬间:${item.pureContent}`, + author: item.uName, + description: item.content, + pubDate: new Date(item.createTime).toUTCString(), + guid: item.pId, + link: `https://w3.soulapp-inc.cn/activity/#/web/topic/detail?postIdEcpt=${item.pId}`, + })), +}); + +module.exports = async (ctx) => { + const rsps = await Promise.all([1, 2].map((pageId) => got({ + method: 'get', + url: `https://api-h5.soulapp.cn/html/v2/post/hot?pageIndex=${pageId}` + }))); + + const allItems = []; + rsps.forEach((response) => { + // 瞬间信息(数组) + let items = response.data.data.posts; + + items = items.map((item) => { + const pureContent = `${item.content}`; + let content = pureContent.replace(/\n/, '
'); + + if (item.attachments) { + for (const attachment of item.attachments) { + if (attachment.type === 'IMAGE') { + content += '
'; + content += ``; + } else if (attachment.type === 'VIDEO') { + content += '
'; + content += ``; + } else if (attachment.type === 'AUDIO') { + content += '
'; + content += ``; + } + } + } + + return { + pId: item.postIdEcpt, + pureContent, + content, + createTime: item.createTime, + uId: item.authorIdEcpt, + uName: item.signature, + }; + }); + + allItems.push(...items); + + }); + + ctx.state.data = await generateResponse(allItems); +};