fix(route): 修复 soul 请求链接 (#7955)

This commit is contained in:
BugWriter2
2021-08-12 01:17:51 -07:00
committed by GitHub
parent 37877a93fe
commit 47d1305f95
3 changed files with 23 additions and 8 deletions
+7 -1
View File
@@ -564,7 +564,13 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
### 热门瞬间
<Route author="BugWriter2" example="/soul/posts/hot" path="/soul/posts/hot" radar="1" rssbud="1"></Route>
<Route author="BugWriter2" example="/soul/posts/hot/NXJiSlM5V21kamJWVlgvZUh1NEExdz09" path="/soul/posts/hot/:pid*" :paramsDesc="['瞬间 id, 分享用户瞬间时的 URL 的 postIdEcpt 参数']"/>
::: tip 提示
提供不同内容的 `pid`, 可以得到不同的热门瞬间推荐,如果想看多个种类的热门可以用 `/` 把不同的 `pid` 连起来,例如: `NXJiSlM5V21kamJWVlgvZUh1NEExdz09/MkM0amxSTUNiTEpLcHhzSlRzTEI1dz09`
:::
## Tape 小纸条
+1 -1
View File
@@ -2107,7 +2107,7 @@ router.get('/hanime/video', require('./routes/hanime/video'));
// Soul
router.get('/soul/:id', require('./routes/soul'));
router.get('/soul/posts/hot', require('./routes/soul/hot'));
router.get('/soul/posts/hot/:pid*', require('./routes/soul/hot'));
// 单向空间
router.get('/owspace/read/:type?', require('./routes/owspace/read'));
+15 -6
View File
@@ -1,26 +1,33 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const generateResponse = async (items) => ({
// 源标题
title: '热门瞬间',
title: 'Soul 热门瞬间',
// 源链接
link: 'https://api-h5.soulapp.cn/html/v2/post/hot?pageIndex=2',
link: 'https://api-h5.soulapp.cn/html/v2/post/hot?postIdEcpt',
item: items.map((item) => ({
title: `「${item.uName}」的瞬间:${item.pureContent}`,
author: item.uName,
description: item.content,
pubDate: new Date(item.createTime).toUTCString(),
pubDate: parseDate(item.createTime),
guid: item.pId,
link: `https://w3.soulsmile.cn/activity/#/web/topic/detail?postIdEcpt=${item.pId}`,
})),
});
module.exports = async (ctx) => {
// 根据不同用户瞬间会得到不同的结果,这里提供一些例子
const defaultPid = 'NXJiSlM5V21kamJWVlgvZUh1NEExdz09';
const userPid = ctx.params.pid || defaultPid;
const examplePids = userPid.split('/');
const rsps = await Promise.all(
[1, 2].map((pageId) =>
examplePids.map((pId) =>
got({
method: 'get',
url: `https://api-h5.soulapp.cn/html/v2/post/hot?pageIndex=${pageId}`,
url: `https://api-h5.soulapp.cn/html/v2/post/hot?postIdEcpt=${pId}`,
})
)
);
@@ -62,5 +69,7 @@ module.exports = async (ctx) => {
allItems.push(...items);
});
ctx.state.data = await generateResponse(allItems);
const uniqAllItems = allItems.filter((value, idx, arr) => arr.findIndex((item) => (item.pId === value.pId)) === idx);
ctx.state.data = await generateResponse(uniqAllItems);
};