mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat(route): zhihu get all collections (#8943)
This commit is contained in:
@@ -1220,7 +1220,7 @@ rule
|
||||
|
||||
### 收藏夹
|
||||
|
||||
<Route author="huruji Colin-XKL" example="/zhihu/collection/26444956" path="/zhihu/collection/:id" :paramsDesc="['收藏夹 id, 可在收藏夹页面 URL 中找到']" anticrawler="1" radar="1" rssbud="1"/>
|
||||
<Route author="huruji Colin-XKL Fatpandac" example="/zhihu/collection/26444956" path="/zhihu/collection/:id/:getAll?" :paramsDesc="['收藏夹 id, 可在收藏夹页面 URL 中找到', '获取全部收藏内容,任意值为打开']" anticrawler="1" radar="1" rssbud="1"/>
|
||||
|
||||
### 用户动态
|
||||
|
||||
|
||||
+1
-1
@@ -128,7 +128,7 @@ router.get('/jianshu/collection/:id', lazyloadRouteHandler('./routes/jianshu/col
|
||||
router.get('/jianshu/user/:id', lazyloadRouteHandler('./routes/jianshu/user'));
|
||||
|
||||
// 知乎
|
||||
router.get('/zhihu/collection/:id', lazyloadRouteHandler('./routes/zhihu/collection'));
|
||||
router.get('/zhihu/collection/:id/:getAll?', lazyloadRouteHandler('./routes/zhihu/collection'));
|
||||
router.get('/zhihu/people/activities/:id', lazyloadRouteHandler('./routes/zhihu/activities'));
|
||||
router.get('/zhihu/people/answers/:id', lazyloadRouteHandler('./routes/zhihu/answers'));
|
||||
router.get('/zhihu/posts/:usertype/:id', lazyloadRouteHandler('./routes/zhihu/posts'));
|
||||
|
||||
@@ -5,6 +5,7 @@ const { generateData } = require('./pin/utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const getAll = ctx.params.getAll;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
@@ -17,6 +18,29 @@ module.exports = async (ctx) => {
|
||||
|
||||
const list = response.data.data;
|
||||
|
||||
if (getAll) {
|
||||
const totals = response.data.paging.totals;
|
||||
|
||||
const offsetList = [...new Array(Math.round(totals / 20)).keys()].map((item) => item * 20).slice(1);
|
||||
const otherList = await Promise.all(
|
||||
offsetList.map((offset) =>
|
||||
ctx.cache.tryGet(`https://www.zhihu.com/api/v4/collections/${id}/items?offset=${offset}&limit=20`, async () => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://www.zhihu.com/api/v4/collections/${id}/items?offset=${offset}&limit=20`,
|
||||
headers: {
|
||||
...utils.header,
|
||||
Referer: `https://www.zhihu.com/collection/${id}`,
|
||||
},
|
||||
});
|
||||
|
||||
return response.data.data;
|
||||
})
|
||||
)
|
||||
).then((item) => item.flat());
|
||||
list.push(...otherList);
|
||||
}
|
||||
|
||||
const response2 = await got({
|
||||
method: 'get',
|
||||
url: `https://www.zhihu.com/collection/${id}`,
|
||||
@@ -42,9 +66,9 @@ module.exports = async (ctx) => {
|
||||
item.content.type === 'pin'
|
||||
? generateDataPin(item)
|
||||
: {
|
||||
title: item.content.type === 'article' ? item.content.title : item.content.question.title,
|
||||
title: item.content.type === 'article' || item.content.type === 'zvideo' ? item.content.title : item.content.question.title,
|
||||
link: item.content.url,
|
||||
description: item.content.content,
|
||||
description: item.content.type === 'zvideo' ? `<img src=${item.content.video.url}/>` : item.content.content,
|
||||
pubDate: new Date((item.content.type === 'article' ? item.content.updated : item.content.updated_time) * 1000).toUTCString(),
|
||||
}
|
||||
),
|
||||
|
||||
@@ -17,13 +17,23 @@ module.exports = {
|
||||
break;
|
||||
|
||||
case 'video':
|
||||
description += `<video
|
||||
controls="controls"
|
||||
width="${item.playlist.hd.width}"
|
||||
height="${item.playlist.hd.height}"
|
||||
poster="${item.cover_info.thumbnail}"
|
||||
src="${item.playlist.hd.play_url}"
|
||||
>`;
|
||||
try {
|
||||
description += `<video
|
||||
controls="controls"
|
||||
width="${item.playlist.hd.width}"
|
||||
height="${item.playlist.hd.height}"
|
||||
poster="${item.cover_info.thumbnail}"
|
||||
src="${item.playlist.hd.play_url}"
|
||||
>`;
|
||||
} catch (e) {
|
||||
description += `<video
|
||||
controls="controls"
|
||||
width="${item.playlist.pop().width}"
|
||||
height="${item.playlist.pop().height}"
|
||||
poster="${item.thumbnail}"
|
||||
src="${item.playlist.pop().play_url}"
|
||||
>`;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'link':
|
||||
|
||||
Reference in New Issue
Block a user