rsshub 1.0.0-master.b76ffa1 → 1.0.0-master.b77ea8a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.ts +3 -0
- package/lib/middleware/access-control.ts +1 -1
- package/lib/routes/afdian/dynamic.ts +1 -1
- package/lib/routes/afdian/explore.ts +1 -1
- package/lib/routes/bilibili/bangumi.ts +45 -43
- package/lib/routes/bilibili/bilibili-recommend.ts +4 -4
- package/lib/routes/bilibili/coin.ts +4 -4
- package/lib/routes/bilibili/dynamic.ts +14 -14
- package/lib/routes/bilibili/fav.ts +4 -4
- package/lib/routes/bilibili/followings-dynamic.ts +25 -3
- package/lib/routes/bilibili/followings-video.ts +4 -4
- package/lib/routes/bilibili/like.ts +4 -4
- package/lib/routes/bilibili/page.ts +5 -4
- package/lib/routes/bilibili/partion-ranking.ts +4 -4
- package/lib/routes/bilibili/partion.ts +4 -4
- package/lib/routes/bilibili/popular.ts +6 -4
- package/lib/routes/bilibili/ranking.ts +4 -6
- package/lib/routes/bilibili/templates/description.art +12 -0
- package/lib/routes/bilibili/types.ts +52 -0
- package/lib/routes/bilibili/user-channel.ts +10 -17
- package/lib/routes/bilibili/user-collection.ts +10 -18
- package/lib/routes/bilibili/user-fav.ts +4 -4
- package/lib/routes/bilibili/utils.ts +111 -7
- package/lib/routes/bilibili/video-all.ts +8 -3
- package/lib/routes/bilibili/video.ts +5 -4
- package/lib/routes/bilibili/vsearch.ts +21 -5
- package/lib/routes/bilibili/watchlater.ts +4 -4
- package/lib/routes/bilibili/weekly-recommend.ts +4 -9
- package/lib/routes/bsky/posts.ts +2 -2
- package/lib/routes/bsky/templates/post.art +4 -2
- package/lib/routes/chinania/index.ts +240 -0
- package/lib/routes/chinania/namespace.ts +8 -0
- package/lib/routes/dedao/articles.ts +149 -0
- package/lib/routes/eshukan/academic.ts +134 -0
- package/lib/routes/eshukan/namespace.ts +8 -0
- package/lib/routes/eshukan/templates/description.art +7 -0
- package/lib/routes/follow/profile.ts +37 -3
- package/lib/routes/lovelive-anime/schedules.ts +4 -5
- package/lib/routes/lovelive-anime/topics.ts +88 -37
- package/lib/routes/mingpao/index.ts +7 -1
- package/lib/routes/nature/cover.ts +5 -3
- package/lib/routes/nature/research.ts +1 -1
- package/lib/routes/nature/siteindex.ts +25 -11
- package/lib/routes/nature/utils.ts +5 -7
- package/lib/routes/qq/pd/guild.ts +146 -0
- package/lib/routes/qq/pd/types.ts +82 -0
- package/lib/routes/qq/pd/utils.ts +119 -0
- package/lib/routes/reuters/common.ts +160 -159
- package/lib/routes/reuters/investigates.ts +3 -2
- package/lib/routes/rsshub/transform/html.ts +2 -2
- package/lib/routes/telegram/channel.ts +14 -5
- package/lib/routes/telegram/scripts/get-telegram-session.mjs +41 -0
- package/lib/routes/telegram/tglib/channel.ts +8 -4
- package/lib/routes/theinitium/app.ts +49 -27
- package/lib/routes/theinitium/templates/description.art +2 -2
- package/lib/routes/threads/index.ts +1 -1
- package/lib/routes/threads/utils.ts +19 -1
- package/lib/routes/twitter/api/mobile-api/login.ts +125 -127
- package/lib/routes/twitter/api/mobile-api/token.ts +2 -0
- package/lib/routes/twitter/home-latest.ts +4 -1
- package/lib/routes/twitter/home.ts +4 -1
- package/lib/routes/twitter/likes.ts +4 -1
- package/lib/routes/twitter/list.ts +4 -1
- package/lib/routes/twitter/namespace.ts +1 -0
- package/lib/routes/twitter/utils.ts +9 -3
- package/lib/routes/warthunder/news.ts +8 -8
- package/lib/routes/washingtonpost/app.ts +118 -0
- package/lib/routes/washingtonpost/namespace.ts +6 -0
- package/lib/routes/washingtonpost/templates/description.art +59 -0
- package/lib/routes/zhihu/daily.ts +30 -64
- package/package.json +12 -12
|
@@ -3,11 +3,12 @@ import { getCurrentPath } from '@/utils/helpers';
|
|
|
3
3
|
const __dirname = getCurrentPath(import.meta.url);
|
|
4
4
|
|
|
5
5
|
import cache from '@/utils/cache';
|
|
6
|
-
import
|
|
6
|
+
import ofetch from '@/utils/ofetch';
|
|
7
7
|
import { load } from 'cheerio';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import { art } from '@/utils/render';
|
|
10
10
|
import { parseDate } from '@/utils/parse-date';
|
|
11
|
+
import timezone from '@/utils/timezone';
|
|
11
12
|
const renderDescription = (desc) => art(path.join(__dirname, 'templates/description.art'), desc);
|
|
12
13
|
|
|
13
14
|
export const route: Route = {
|
|
@@ -40,10 +41,25 @@ export const route: Route = {
|
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
async function handler(ctx) {
|
|
43
|
-
const abbr = ctx.req.param(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
const { abbr, category = '', option } = ctx.req.param();
|
|
45
|
+
let rootUrl: string;
|
|
46
|
+
switch (abbr) {
|
|
47
|
+
case 'musical':
|
|
48
|
+
rootUrl = 'https://www.lovelive-anime.jp/special/musical';
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
rootUrl = `https://www.lovelive-anime.jp/${abbr}`;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
const topicsTable = {
|
|
55
|
+
otonokizaka: 'topics.php',
|
|
56
|
+
uranohoshi: 'topics.php',
|
|
57
|
+
nijigasaki: 'topics.php',
|
|
58
|
+
yuigaoka: 'topics/',
|
|
59
|
+
hasunosora: 'news/',
|
|
60
|
+
musical: 'topics.php',
|
|
61
|
+
};
|
|
62
|
+
const baseUrl = `${rootUrl}/${topicsTable[abbr]}`;
|
|
47
63
|
const abbrDetail = {
|
|
48
64
|
otonokizaka: 'ラブライブ!',
|
|
49
65
|
uranohoshi: 'サンシャイン!!',
|
|
@@ -51,50 +67,85 @@ async function handler(ctx) {
|
|
|
51
67
|
yuigaoka: 'スーパースター!!',
|
|
52
68
|
};
|
|
53
69
|
|
|
54
|
-
const url =
|
|
70
|
+
const url = category !== '' && category !== 'detail' ? `${baseUrl}?cat=${category}` : baseUrl;
|
|
55
71
|
|
|
56
|
-
const response = await
|
|
72
|
+
const response = await ofetch(url);
|
|
57
73
|
|
|
58
|
-
const $ = load(response
|
|
74
|
+
const $ = load(response);
|
|
59
75
|
|
|
60
76
|
const categoryName = 'uranohoshi' === abbr ? $('div.llbox > p').text() : $('div.category_title > h2').text();
|
|
61
77
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
item = $(item);
|
|
78
|
+
const newsList = 'hasunosora' === abbr ? $('.list__content > ul > li').toArray() : $('ul.listbox > li').toArray();
|
|
79
|
+
let items;
|
|
65
80
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
item
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
.match(/background-image:url\((.*)\)/)[1]
|
|
75
|
-
}`;
|
|
81
|
+
switch (abbr) {
|
|
82
|
+
case 'hasunosora':
|
|
83
|
+
items = newsList.map((item) => {
|
|
84
|
+
item = $(item);
|
|
85
|
+
const link = `${rootUrl}/news/${item.find('a').attr('href')}`;
|
|
86
|
+
const pubDate = timezone(parseDate(item.find('.list--date').text(), 'YYYY.MM.DD'), +9);
|
|
87
|
+
const title = item.find('.list--text').text();
|
|
88
|
+
const category = item.find('.list--category').text();
|
|
76
89
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
title,
|
|
81
|
-
category,
|
|
82
|
-
description: renderDescription({
|
|
90
|
+
return {
|
|
91
|
+
link,
|
|
92
|
+
pubDate,
|
|
83
93
|
title,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
94
|
+
category,
|
|
95
|
+
description: title,
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
break;
|
|
99
|
+
default:
|
|
100
|
+
items = newsList.map((item) => {
|
|
101
|
+
item = $(item);
|
|
102
|
+
let link: string;
|
|
103
|
+
switch (abbr) {
|
|
104
|
+
case 'yuigaoka':
|
|
105
|
+
link = `${baseUrl}${item.find('div > a').attr('href')}`;
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
link = `${rootUrl}/${item.find('div > a').attr('href')}`;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
const pubDate = timezone(parseDate(item.find('a > p.date').text(), 'YYYY/MM/DD'), +9);
|
|
112
|
+
const title = item.find('a > p.title').text();
|
|
113
|
+
const category = item.find('a > p.category').text();
|
|
114
|
+
const imglink = `${rootUrl}/${
|
|
115
|
+
item
|
|
116
|
+
.find('a > img')
|
|
117
|
+
.attr('style')
|
|
118
|
+
.match(/background-image:url\((.*)\)/)[1]
|
|
119
|
+
}`;
|
|
89
120
|
|
|
90
|
-
|
|
121
|
+
return {
|
|
122
|
+
link,
|
|
123
|
+
pubDate,
|
|
124
|
+
title,
|
|
125
|
+
category,
|
|
126
|
+
description: renderDescription({
|
|
127
|
+
imglink,
|
|
128
|
+
}),
|
|
129
|
+
};
|
|
130
|
+
});
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (option === 'detail' || category === 'detail') {
|
|
91
135
|
items = await Promise.all(
|
|
92
136
|
items.map((item) =>
|
|
93
137
|
cache.tryGet(item.link, async () => {
|
|
94
|
-
const detailResp = await
|
|
95
|
-
const $ = load(detailResp
|
|
96
|
-
|
|
97
|
-
|
|
138
|
+
const detailResp = await ofetch(item.link);
|
|
139
|
+
const $ = load(detailResp);
|
|
140
|
+
let content;
|
|
141
|
+
switch (abbr) {
|
|
142
|
+
case 'hasunosora':
|
|
143
|
+
content = $('div.detail__content');
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
content = $('div.p-page__detail.p-article');
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
98
149
|
for (const v of content.find('img')) {
|
|
99
150
|
v.attribs.src = `${baseUrl}${v.attribs.src}`;
|
|
100
151
|
}
|
|
@@ -112,6 +112,12 @@ async function handler(ctx) {
|
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
const $ = cheerio.load(response);
|
|
115
|
+
const topVideo = $('#topvideo').length
|
|
116
|
+
? $('#topvideo iframe')
|
|
117
|
+
.toArray()
|
|
118
|
+
.map((e) => $(e).attr('href', $(e).attr('src')))
|
|
119
|
+
.map((e) => fixFancybox(e, $))
|
|
120
|
+
: [];
|
|
115
121
|
const fancyboxImg = $('a.fancybox').length ? $('a.fancybox') : $('a.fancybox-buttons');
|
|
116
122
|
|
|
117
123
|
// remove unwanted elements
|
|
@@ -125,7 +131,7 @@ async function handler(ctx) {
|
|
|
125
131
|
item.category = item.categories;
|
|
126
132
|
|
|
127
133
|
// fix fancybox image
|
|
128
|
-
let fancybox = fancyboxImg.toArray().map((e) => fixFancybox(e, $));
|
|
134
|
+
let fancybox = [...topVideo, ...fancyboxImg.toArray().map((e) => fixFancybox(e, $))];
|
|
129
135
|
const script = $('script')
|
|
130
136
|
.toArray()
|
|
131
137
|
.find((e) => $(e).text()?.includes("$('#lower').prepend('"));
|
|
@@ -41,7 +41,7 @@ export const route: Route = {
|
|
|
41
41
|
},
|
|
42
42
|
],
|
|
43
43
|
name: 'Cover Story',
|
|
44
|
-
maintainers: ['y9c'],
|
|
44
|
+
maintainers: ['y9c', 'pseudoyu'],
|
|
45
45
|
handler,
|
|
46
46
|
url: 'nature.com/',
|
|
47
47
|
description: `Subscribe to the cover images of the Nature journals, and get the latest publication updates in time.`,
|
|
@@ -65,13 +65,15 @@ async function handler() {
|
|
|
65
65
|
const { id, name, link } = journal;
|
|
66
66
|
|
|
67
67
|
const response = await got(link, { cookieJar });
|
|
68
|
+
const $ = load(response.data);
|
|
68
69
|
|
|
70
|
+
const ogUrl = $('meta[property="og:url"]').attr('content');
|
|
69
71
|
const capturingRegex = /volumes\/(?<volume>\d+)\/issues\/(?<issue>\d+)/;
|
|
70
|
-
const { volume, issue } =
|
|
72
|
+
const { volume, issue } = ogUrl?.match(capturingRegex)?.groups ?? {};
|
|
73
|
+
|
|
71
74
|
const imageUrl = `https://media.springernature.com/full/springer-static/cover-hires/journal/${id}/${volume}/${issue}?as=webp`;
|
|
72
75
|
const contents = `<div align="center"><img src="${imageUrl}" alt="Volume ${volume} Issue ${issue}"></div>`;
|
|
73
76
|
|
|
74
|
-
const $ = load(response.data);
|
|
75
77
|
const date = $('title').text().split(',')[1].trim();
|
|
76
78
|
const issueDescription = $('div[data-test=issue-description]').html() ?? '';
|
|
77
79
|
|
|
@@ -38,7 +38,7 @@ export const route: Route = {
|
|
|
38
38
|
},
|
|
39
39
|
],
|
|
40
40
|
name: 'Latest Research',
|
|
41
|
-
maintainers: ['y9c', 'TonyRL'],
|
|
41
|
+
maintainers: ['y9c', 'TonyRL', 'pseudoyu'],
|
|
42
42
|
handler,
|
|
43
43
|
description: `| \`:journal\` | Full Name of the Journal | Route |
|
|
44
44
|
| :-----------: | :-------------------------: | ---------------------------------------------------------------------------------- |
|
|
@@ -18,7 +18,7 @@ export const route: Route = {
|
|
|
18
18
|
supportScihub: false,
|
|
19
19
|
},
|
|
20
20
|
name: 'Journal List',
|
|
21
|
-
maintainers: ['TonyRL'],
|
|
21
|
+
maintainers: ['TonyRL', 'pseudoyu'],
|
|
22
22
|
handler,
|
|
23
23
|
};
|
|
24
24
|
|
|
@@ -40,19 +40,33 @@ async function handler(ctx) {
|
|
|
40
40
|
items = await Promise.all(
|
|
41
41
|
items.map((item) =>
|
|
42
42
|
cache.tryGet(`nature:siteindex:${item.title}`, async () => {
|
|
43
|
-
const response = await got(item.link, { cookieJar });
|
|
44
|
-
const $ = load(response.data);
|
|
45
|
-
|
|
46
|
-
delete item.link;
|
|
47
43
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
const response = await got(item.link, { cookieJar });
|
|
45
|
+
const $ = load(response.data);
|
|
46
|
+
|
|
47
|
+
const imgSrc = $('.app-latest-issue-row__image img').attr('src');
|
|
48
|
+
if (imgSrc) {
|
|
49
|
+
const match = imgSrc.match(/.*\/journal\/(\d{5})/);
|
|
50
|
+
if (match) {
|
|
51
|
+
const id = match[1];
|
|
52
|
+
return {
|
|
53
|
+
title: item.title,
|
|
54
|
+
name: item.name,
|
|
55
|
+
id,
|
|
56
|
+
description: id,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
title: item.title,
|
|
62
|
+
name: item.name,
|
|
63
|
+
};
|
|
52
64
|
} catch {
|
|
53
|
-
|
|
65
|
+
return {
|
|
66
|
+
title: item.title,
|
|
67
|
+
name: item.name,
|
|
68
|
+
};
|
|
54
69
|
}
|
|
55
|
-
return item;
|
|
56
70
|
})
|
|
57
71
|
)
|
|
58
72
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import cache from '@/utils/cache';
|
|
2
|
-
import
|
|
2
|
+
import ofetch from '@/utils/ofetch';
|
|
3
3
|
import { load } from 'cheerio';
|
|
4
4
|
import { parseDate } from '@/utils/parse-date';
|
|
5
5
|
import { CookieJar } from 'tough-cookie';
|
|
@@ -52,13 +52,11 @@ const getArticleList = (html) =>
|
|
|
52
52
|
|
|
53
53
|
const getArticle = (item) =>
|
|
54
54
|
cache.tryGet(item.link, async () => {
|
|
55
|
-
const response = await
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const $ = load(response.data);
|
|
59
|
-
const responseUrl = new URL(response.url);
|
|
55
|
+
const response = await ofetch(item.link);
|
|
56
|
+
|
|
57
|
+
const $ = load(response);
|
|
60
58
|
|
|
61
|
-
if (
|
|
59
|
+
if (new URL(item.link).pathname.startsWith('/immersive/')) {
|
|
62
60
|
const meta = getDataLayer($);
|
|
63
61
|
item.doi = meta.content.article?.doi;
|
|
64
62
|
item.author = meta.content.contentInfo.authors.join(', ');
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { Data, DataItem, Route } from '@/types';
|
|
2
|
+
import ofetch from '@/utils/ofetch';
|
|
3
|
+
import InvalidParameterError from '@/errors/types/invalid-parameter';
|
|
4
|
+
import type { Context } from 'hono';
|
|
5
|
+
|
|
6
|
+
import { Feed } from './types';
|
|
7
|
+
import { parseFeed } from './utils';
|
|
8
|
+
import cache from '@/utils/cache';
|
|
9
|
+
|
|
10
|
+
const baseUrl = 'https://pd.qq.com/g/';
|
|
11
|
+
const baseApiUrl = 'https://pd.qq.com/qunng/guild/gotrpc/noauth/trpc.qchannel.commreader.ComReader/';
|
|
12
|
+
const getGuildFeedsUrl = baseApiUrl + 'GetGuildFeeds';
|
|
13
|
+
const getChannelTimelineFeedsUrl = baseApiUrl + 'GetChannelTimelineFeeds';
|
|
14
|
+
const getFeedDetailUrl = baseApiUrl + 'GetFeedDetail';
|
|
15
|
+
|
|
16
|
+
const sortMap = {
|
|
17
|
+
hot: 0,
|
|
18
|
+
created: 1,
|
|
19
|
+
replied: 2,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const route: Route = {
|
|
23
|
+
path: ['/pd/guild/:id/:sub?/:sort?'],
|
|
24
|
+
categories: ['bbs'],
|
|
25
|
+
example: '/qq/pd/guild/qrp4pkq01d/650967831/created',
|
|
26
|
+
parameters: {
|
|
27
|
+
id: '频道号',
|
|
28
|
+
sub: '子频道 ID,网页端 URL `subc` 参数的值,默认为 `hot`(全部)',
|
|
29
|
+
sort: '排序方式,`hot`(热门),`created`(最新发布),`replied`(最新回复),默认为 `created`',
|
|
30
|
+
},
|
|
31
|
+
features: {
|
|
32
|
+
requireConfig: false,
|
|
33
|
+
requirePuppeteer: false,
|
|
34
|
+
antiCrawler: false,
|
|
35
|
+
supportBT: false,
|
|
36
|
+
supportPodcast: false,
|
|
37
|
+
supportScihub: false,
|
|
38
|
+
},
|
|
39
|
+
radar: [
|
|
40
|
+
{
|
|
41
|
+
source: ['pd.qq.com/'],
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
name: '腾讯频道',
|
|
45
|
+
maintainers: ['mobyw'],
|
|
46
|
+
handler,
|
|
47
|
+
url: 'pd.qq.com/',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
async function handler(ctx: Context): Promise<Data> {
|
|
51
|
+
const { id, sub = 'hot', sort = 'created' } = ctx.req.param();
|
|
52
|
+
|
|
53
|
+
if (sort in sortMap === false) {
|
|
54
|
+
throw new InvalidParameterError('invalid sort parameter, should be `hot`, `created`, or `replied`');
|
|
55
|
+
}
|
|
56
|
+
const sortType = sortMap[sort];
|
|
57
|
+
|
|
58
|
+
let url = '';
|
|
59
|
+
let body = {};
|
|
60
|
+
let headers = {};
|
|
61
|
+
|
|
62
|
+
if (sub === 'hot') {
|
|
63
|
+
url = getGuildFeedsUrl;
|
|
64
|
+
// notice: do not change the order of the keys in the body
|
|
65
|
+
body = { count: 20, from: 7, guild_number: id, get_type: 1, feedAttchInfo: '', sortOption: sortType, need_channel_list: false, need_top_info: false };
|
|
66
|
+
headers = {
|
|
67
|
+
cookie: 'p_uin=o09000002',
|
|
68
|
+
'x-oidb': '{"uint32_service_type":12}',
|
|
69
|
+
'x-qq-client-appid': '537246381',
|
|
70
|
+
};
|
|
71
|
+
} else {
|
|
72
|
+
url = getChannelTimelineFeedsUrl;
|
|
73
|
+
// notice: do not change the order of the keys in the body
|
|
74
|
+
body = { count: 20, from: 7, guild_number: id, channelSign: { channel_id: sub }, feedAttchInfo: '', sortOption: sortType, need_top_info: false };
|
|
75
|
+
headers = {
|
|
76
|
+
cookie: 'p_uin=o09000002',
|
|
77
|
+
'x-oidb': '{"uint32_service_type":11}',
|
|
78
|
+
'x-qq-client-appid': '537246381',
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const data = await ofetch(url, { method: 'POST', body, headers });
|
|
83
|
+
const feeds = data.data?.vecFeed || [];
|
|
84
|
+
|
|
85
|
+
const items = feeds.map(async (feed: Feed) => {
|
|
86
|
+
let subId = sub;
|
|
87
|
+
if (sub === 'hot') {
|
|
88
|
+
// get real subId for hot feeds
|
|
89
|
+
subId = feed.channelInfo?.sign?.channel_id || '';
|
|
90
|
+
}
|
|
91
|
+
const feedLink = baseUrl + id + '/post/' + feed.id;
|
|
92
|
+
const feedDetail = await cache.tryGet(feedLink, async () => {
|
|
93
|
+
// notice: do not change the order of the keys in the body
|
|
94
|
+
body = {
|
|
95
|
+
feedId: feed.id,
|
|
96
|
+
userId: feed.poster?.id,
|
|
97
|
+
createTime: feed.createTime,
|
|
98
|
+
from: 2,
|
|
99
|
+
detail_type: 1,
|
|
100
|
+
channelSign: { guild_number: id, channel_id: subId },
|
|
101
|
+
extInfo: {
|
|
102
|
+
mapInfo: [
|
|
103
|
+
{ key: 'qc-tabid', value: 'ark' },
|
|
104
|
+
{ key: 'qc-pageid', value: 'pc' },
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
headers = {
|
|
109
|
+
cookie: 'p_uin=o09000002',
|
|
110
|
+
referer: feedLink,
|
|
111
|
+
'x-oidb': '{"uint32_service_type":5}',
|
|
112
|
+
'x-qq-client-appid': '537246381',
|
|
113
|
+
};
|
|
114
|
+
const feedResponse = await ofetch(getFeedDetailUrl, { method: 'POST', body, headers });
|
|
115
|
+
const feedContent: Feed = feedResponse.data?.feed || {};
|
|
116
|
+
return {
|
|
117
|
+
title: feed.title?.contents[0]?.text_content?.text || feed.channelInfo?.guild_name || '',
|
|
118
|
+
link: feedLink,
|
|
119
|
+
description: parseFeed(feedContent),
|
|
120
|
+
pubDate: new Date(Number(feed.createTime) * 1000),
|
|
121
|
+
author: feed.poster?.nick,
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return feedDetail;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const feedItems = await Promise.all(items);
|
|
129
|
+
|
|
130
|
+
let guildName = '';
|
|
131
|
+
|
|
132
|
+
if (feeds.length > 0 && feeds[0].channelInfo?.guild_name) {
|
|
133
|
+
guildName = feeds[0].channelInfo?.guild_name;
|
|
134
|
+
if (sub !== 'hot' && feeds[0].channelInfo?.name) {
|
|
135
|
+
guildName += ' (' + feeds[0].channelInfo?.name + ')';
|
|
136
|
+
}
|
|
137
|
+
guildName += ' - 腾讯频道';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
title: guildName,
|
|
142
|
+
link: baseUrl + id,
|
|
143
|
+
description: guildName,
|
|
144
|
+
item: feedItems as DataItem[],
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Description: Types for QQ PD API.
|
|
2
|
+
|
|
3
|
+
export type Feed = {
|
|
4
|
+
id: string;
|
|
5
|
+
feed_type: number; // 1-post, 2-article
|
|
6
|
+
patternInfo: string; // JSON string
|
|
7
|
+
channelInfo: ChannelInfo;
|
|
8
|
+
title: {
|
|
9
|
+
contents: FeedContent[];
|
|
10
|
+
};
|
|
11
|
+
contents: {
|
|
12
|
+
contents: FeedContent[];
|
|
13
|
+
};
|
|
14
|
+
images: FeedImage[];
|
|
15
|
+
poster: {
|
|
16
|
+
id: string;
|
|
17
|
+
nick: string;
|
|
18
|
+
};
|
|
19
|
+
createTime: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ChannelInfo = {
|
|
23
|
+
name: string;
|
|
24
|
+
guild_number: string;
|
|
25
|
+
guild_name: string;
|
|
26
|
+
sign: {
|
|
27
|
+
guild_id: string;
|
|
28
|
+
channel_id: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type FeedContent = {
|
|
33
|
+
type: number;
|
|
34
|
+
pattern_id: string;
|
|
35
|
+
text_content?: {
|
|
36
|
+
text: string;
|
|
37
|
+
};
|
|
38
|
+
emoji_content?: {
|
|
39
|
+
id: string;
|
|
40
|
+
type: string;
|
|
41
|
+
};
|
|
42
|
+
url_content?: {
|
|
43
|
+
url: string;
|
|
44
|
+
displayText: string;
|
|
45
|
+
type: number;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type FeedImage = {
|
|
50
|
+
picId: string;
|
|
51
|
+
picUrl: string;
|
|
52
|
+
width: number;
|
|
53
|
+
height: number;
|
|
54
|
+
pattern_id?: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type FeedPattern = {
|
|
58
|
+
id: string;
|
|
59
|
+
props?: {
|
|
60
|
+
textAlignment: number; // 0-left, 1-center, 2-right
|
|
61
|
+
};
|
|
62
|
+
data: FeedPatternData[];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type FeedPatternData = {
|
|
66
|
+
type: number; // 1-text, 2-emoji, 5-link, 6-image, 9-newline
|
|
67
|
+
text?: string;
|
|
68
|
+
props?: FeedFontProps;
|
|
69
|
+
fileId?: string;
|
|
70
|
+
taskId?: string;
|
|
71
|
+
url?: string;
|
|
72
|
+
width?: number;
|
|
73
|
+
height?: number;
|
|
74
|
+
desc?: string;
|
|
75
|
+
href?: string;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type FeedFontProps = {
|
|
79
|
+
fontWeight: number; // 400-normal, 700-bold
|
|
80
|
+
italic: boolean;
|
|
81
|
+
underline: boolean;
|
|
82
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Description: QQ PD utils
|
|
2
|
+
|
|
3
|
+
import { Feed, FeedImage, FeedPattern, FeedFontProps, FeedPatternData } from './types';
|
|
4
|
+
|
|
5
|
+
const patternTypeMap = {
|
|
6
|
+
1: 'text',
|
|
7
|
+
2: 'emoji',
|
|
8
|
+
5: 'link',
|
|
9
|
+
6: 'image',
|
|
10
|
+
9: 'newline',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const textAlignmentMap = {
|
|
14
|
+
0: 'left',
|
|
15
|
+
1: 'center',
|
|
16
|
+
2: 'right',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function parseText(text: string, props: FeedFontProps | undefined): string {
|
|
20
|
+
if (props === undefined) {
|
|
21
|
+
return text;
|
|
22
|
+
}
|
|
23
|
+
let style = '';
|
|
24
|
+
if (props.fontWeight === 700) {
|
|
25
|
+
style += 'font-weight: bold;';
|
|
26
|
+
}
|
|
27
|
+
if (props.italic) {
|
|
28
|
+
style += 'font-style: italic;';
|
|
29
|
+
}
|
|
30
|
+
if (props.underline) {
|
|
31
|
+
style += 'text-decoration: underline;';
|
|
32
|
+
}
|
|
33
|
+
if (style === '') {
|
|
34
|
+
return text;
|
|
35
|
+
}
|
|
36
|
+
return `<span style="${style}">${text}</span>`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function parseDataItem(item: FeedPatternData, texts: string[], images: { [id: string]: FeedImage }): string {
|
|
40
|
+
let imageId = '';
|
|
41
|
+
switch (patternTypeMap[item.type] || undefined) {
|
|
42
|
+
case 'text':
|
|
43
|
+
return parseText(texts.shift() ?? '', item.props);
|
|
44
|
+
case 'newline':
|
|
45
|
+
texts.shift();
|
|
46
|
+
return '<br />';
|
|
47
|
+
case 'link':
|
|
48
|
+
return `<a href="${item.href ?? '#'}" target="_blank">${item.desc ?? ''}</a>`;
|
|
49
|
+
case 'image':
|
|
50
|
+
imageId = item.fileId || item.taskId || '';
|
|
51
|
+
return `<img src="${images[imageId].picUrl}" style="max-width: 100%; width: ${images[imageId].width}px;"><br />`;
|
|
52
|
+
default:
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function parseArticle(feed: Feed, texts: string[], images: { [id: string]: FeedImage }): string {
|
|
58
|
+
let result = '';
|
|
59
|
+
if (feed.patternInfo === undefined || feed.patternInfo === null || feed.patternInfo === '') {
|
|
60
|
+
feed.patternInfo = '[]';
|
|
61
|
+
}
|
|
62
|
+
const patterns: FeedPattern[] = JSON.parse(feed.patternInfo);
|
|
63
|
+
for (const pattern of patterns) {
|
|
64
|
+
if (pattern.props === undefined) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const textAlign = pattern.props.textAlignment || 0;
|
|
68
|
+
result += '<p style="text-align: ' + textAlignmentMap[textAlign] + ';">';
|
|
69
|
+
for (const item of pattern.data) {
|
|
70
|
+
result += parseDataItem(item, texts, images);
|
|
71
|
+
}
|
|
72
|
+
result += '</p>';
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function parsePost(feed: Feed, texts: string[], images: { [id: string]: FeedImage }): string {
|
|
78
|
+
for (const content of feed.contents.contents) {
|
|
79
|
+
if (content.text_content) {
|
|
80
|
+
texts.push(content.text_content.text);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
let result = '';
|
|
84
|
+
for (const text of texts) {
|
|
85
|
+
result += text;
|
|
86
|
+
}
|
|
87
|
+
for (const image of Object.values(images)) {
|
|
88
|
+
result += '<p style="text-align: center">';
|
|
89
|
+
result += `<img src="${image.picUrl}" style="max-width: 100%; width: ${image.width}px;">`;
|
|
90
|
+
result += '</p>';
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function parseFeed(feed: Feed): string {
|
|
96
|
+
const texts: string[] = [];
|
|
97
|
+
const images: { [id: string]: FeedImage } = {};
|
|
98
|
+
for (const content of feed.contents.contents) {
|
|
99
|
+
if (content.text_content) {
|
|
100
|
+
texts.push(content.text_content.text);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const image of feed.images) {
|
|
104
|
+
images[image.picId] = {
|
|
105
|
+
picId: image.picId,
|
|
106
|
+
picUrl: image.picUrl,
|
|
107
|
+
width: image.width,
|
|
108
|
+
height: image.height,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (feed.feed_type === 1) {
|
|
112
|
+
// post: text and attachments
|
|
113
|
+
return parsePost(feed, texts, images);
|
|
114
|
+
} else if (feed.feed_type === 2) {
|
|
115
|
+
// article: pattern info
|
|
116
|
+
return parseArticle(feed, texts, images);
|
|
117
|
+
}
|
|
118
|
+
return '';
|
|
119
|
+
}
|