feat: add soul 热门瞬间 (#5412)

Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
BugWriter2 2020-08-19 04:22:44 +08:00 committed by GitHub
parent 8d933537c8
commit 2e0d38e4dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 0 deletions

View File

@ -415,6 +415,10 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
<Route author="ImSingee" example="/soul/Y2w2aTNWQVBLOU09" path="/soul/:id" :paramsDesc="['用户 id, 分享用户主页时的 URL 的 userIdEcpt 参数']" radar="1"></Route>
### 热门瞬间
<Route author="BugWriter2" example="/soul/posts/hot" path="/soul/posts/hot" radar="1"></Route>
## Telegram
### 频道

View File

@ -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'));

63
lib/routes/soul/hot.js Normal file
View File

@ -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/, '<br />');
if (item.attachments) {
for (const attachment of item.attachments) {
if (attachment.type === 'IMAGE') {
content += '<br />';
content += `<img src="${attachment.fileUrl}" />`;
} else if (attachment.type === 'VIDEO') {
content += '<br />';
content += `<video controls="controls" src="${attachment.fileUrl}" width="640" height="360"></video>`;
} else if (attachment.type === 'AUDIO') {
content += '<br />';
content += `<audio controls="controls" src="${attachment.fileUrl}" width="360" height="120"></audio>`;
}
}
}
return {
pId: item.postIdEcpt,
pureContent,
content,
createTime: item.createTime,
uId: item.authorIdEcpt,
uName: item.signature,
};
});
allItems.push(...items);
});
ctx.state.data = await generateResponse(allItems);
};