/
activities.ts
162 lines (146 loc) · 6.25 KB
/
activities.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { Route } from '@/types';
import got from '@/utils/got';
import auth from './auth';
import { processImage } from '../utils';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/xhu/people/activities/:hexId',
categories: ['social-media'],
example: '/zhihu/xhu/people/activities/246e6cf44e94cefbf4b959cb5042bc91',
parameters: { hexId: '用户的 16 进制 id,获取方式见下方说明' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
radar: [
{
source: ['www.zhihu.com/people/:id'],
target: '/people/activities/:id',
},
],
name: 'xhu - 用户动态',
maintainers: ['JimenezLi'],
handler,
description: `[xhu](https://github.com/REToys/xhu)
:::tip
用户的 16 进制 id 获取方式:
1. 可以通过 RSSHub Radar 扩展获取;
2. 或者在用户主页打开 F12 控制台,执行以下代码:\`console.log(/"id":"([0-9a-f]*?)","urlToken"/.exec(document.getElementById('js-initialData').innerHTML)[1]);\` 即可获取用户的 16 进制 id。
:::`,
};
async function handler(ctx) {
const xhuCookie = await auth.getCookie();
const hexId = ctx.req.param('hexId');
const link = `https://www.zhihu.com/people/${hexId}`;
const url = `https://api.zhihuvvv.workers.dev/people/${hexId}/activities?before_id=0&limit=20`;
const response = await got({
method: 'get',
url,
headers: {
Referer: 'https://api.zhihuvvv.workers.dev',
Cookie: xhuCookie,
},
});
const data = response.data.data;
return {
title: `${data[0].actor.name}的知乎动态`,
link,
image: data[0].actor.avatar_url,
description: data[0].actor.headline || data[0].actor.description,
item: data.map((item) => {
const detail = item.target;
let title;
let description;
let url;
const images: string[] = [];
let text = '';
let link = '';
let author = '';
switch (item.target.type) {
case 'answer':
title = detail.question.title;
author = detail.author.name;
description = processImage(detail.content);
url = `https://www.zhihu.com/question/${detail.question.id}/answer/${detail.id}`;
break;
case 'article':
title = detail.title;
author = detail.author.name;
description = processImage(detail.content);
url = `https://zhuanlan.zhihu.com/p/${detail.id}`;
break;
case 'pin':
title = detail.excerpt_title;
author = detail.author.name;
for (const contentItem of detail.content) {
switch (contentItem.type) {
case 'text':
text = `<p>${contentItem.own_text}</p>`;
break;
case 'image':
images.push(`<p><img src="${contentItem.url.replace('xl', 'r')}"/></p>`);
break;
case 'link':
link = `<p><a href="${contentItem.url}" target="_blank">${contentItem.title}</a></p>`;
break;
case 'video':
link = `<p><video
controls="controls"
width="${contentItem.playlist[1].width}"
height="${contentItem.playlist[1].height}"
src="${contentItem.playlist[1].url}"></video></p>`;
break;
default:
throw new Error(`Unknown type: ${contentItem.type}`);
}
}
description = `${text}${link}${images.join('')}`;
url = `https://www.zhihu.com/pin/${detail.id}`;
break;
case 'question':
title = detail.title;
author = detail.author.name;
description = processImage(detail.detail);
url = `https://www.zhihu.com/question/${detail.id}`;
break;
case 'collection':
title = detail.title;
url = `https://www.zhihu.com/collection/${detail.id}`;
break;
case 'column':
title = detail.title;
description = `<p>${detail.intro}</p><p><img src="${detail.image_url}"/></p>`;
url = `https://zhuanlan.zhihu.com/${detail.id}`;
break;
case 'topic':
title = detail.name;
description = `<p>${detail.introduction}</p><p>话题关注者人数:${detail.followers_count}</p>`;
url = `https://www.zhihu.com/topic/${detail.id}`;
break;
case 'live':
title = detail.subject;
description = detail.description.replaceAll(/\n|\r/g, '<br>');
url = `https://www.zhihu.com/lives/${detail.id}`;
break;
case 'roundtable':
title = detail.name;
description = detail.description;
url = `https://www.zhihu.com/roundtable/${detail.id}`;
break;
default:
description = `未知类型 ${item.target.type},请点击<a href="https://github.com/DIYgod/RSSHub/issues">链接</a>提交issue`;
}
return {
title: `${data[0].actor.name}${item.action_text}: ${title}`,
author,
description,
pubDate: parseDate(item.created_time * 1000),
link: url,
};
}),
};
}