/
pins.ts
89 lines (82 loc) · 3.03 KB
/
pins.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
import { Route } from '@/types';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/pins/:type?',
categories: ['programming'],
example: '/juejin/pins/6824710202487472141',
parameters: { type: '默认为 recommend,见下表' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: '沸点',
maintainers: ['xyqfer', 'laampui'],
handler,
description: `| 推荐 | 热门 | 上班摸鱼 | 内推招聘 | 一图胜千言 | 今天学到了 | 每天一道算法题 | 开发工具推荐 | 树洞一下 |
| --------- | ---- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
| recommend | hot | 6824710203301167112 | 6819970850532360206 | 6824710202487472141 | 6824710202562969614 | 6824710202378436621 | 6824710202000932877 | 6824710203112423437 |`,
};
async function handler(ctx) {
const type = ctx.req.param('type') ?? 'recommend';
const title = {
recommend: '推荐',
hot: '热门',
'6824710203301167112': '上班摸鱼',
'6819970850532360206': '内推招聘',
'6824710202487472141': '一图胜千言',
'6824710202562969614': '今天学到了',
'6824710202378436621': '每天一道算法题',
'6824710202000932877': '开发工具推荐',
'6824710203112423437': '树洞一下',
};
let url = '';
let json = null;
if (/^\d+$/.test(type)) {
url = `https://api.juejin.cn/recommend_api/v1/short_msg/topic`;
json = { id_type: 4, sort_type: 500, cursor: '0', limit: 20, topic_id: type };
} else {
url = `https://api.juejin.cn/recommend_api/v1/short_msg/${type}`;
json = { id_type: 4, sort_type: 200, cursor: '0', limit: 20 };
}
const response = await got({
method: 'post',
url,
json,
});
const items = response.data.data.map((item) => {
const content = item.msg_Info.content;
const title = content;
const guid = item.msg_id;
const link = `https://juejin.cn/pin/${guid}`;
const pubDate = parseDate(item.msg_Info.ctime * 1000);
const author = item.author_user_info.user_name;
const imgs = item.msg_Info.pic_list.reduce((imgs, item) => {
imgs += `
<img src="${item}"><br>
`;
return imgs;
}, '');
const description = `
${content.replaceAll('\n', '<br>')}<br>
${imgs}<br>
`;
return {
title,
link,
description,
guid,
pubDate,
author,
};
});
return {
title: `沸点 - ${title[type]}`,
link: 'https://juejin.cn/pins/recommended',
item: items,
};
}