Skip to content

Commit

Permalink
fix(route): 修复 soul 请求链接 (#7955)
Browse files Browse the repository at this point in the history
  • Loading branch information
BugWriter2 authored Aug 12, 2021
1 parent 37877a9 commit 47d1305
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
8 changes: 7 additions & 1 deletion docs/social-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 小纸条

Expand Down
2 changes: 1 addition & 1 deletion lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
21 changes: 15 additions & 6 deletions lib/routes/soul/hot.js
Original file line number Diff line number Diff line change
@@ -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}`,
})
)
);
Expand Down Expand Up @@ -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);
};

1 comment on commit 47d1305

@vercel
Copy link

@vercel vercel bot commented on 47d1305 Aug 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.