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
|
@@ -29,44 +29,7 @@ export const route: Route = {
|
|
|
29
29
|
],
|
|
30
30
|
default: 'world',
|
|
31
31
|
},
|
|
32
|
-
topic:
|
|
33
|
-
description: 'find it in the URL, or tables below, leave empty for `All`',
|
|
34
|
-
options: [
|
|
35
|
-
// World topics
|
|
36
|
-
{ value: 'africa', label: 'Africa' },
|
|
37
|
-
{ value: 'americas', label: 'Americas' },
|
|
38
|
-
{ value: 'asia-pacific', label: 'Asia Pacific' },
|
|
39
|
-
{ value: 'china', label: 'China' },
|
|
40
|
-
{ value: 'europe', label: 'Europe' },
|
|
41
|
-
{ value: 'india', label: 'India' },
|
|
42
|
-
{ value: 'middle-east', label: 'Middle East' },
|
|
43
|
-
{ value: 'uk', label: 'United Kingdom' },
|
|
44
|
-
{ value: 'us', label: 'United States' },
|
|
45
|
-
{ value: 'the-great-reboot', label: 'The Great Reboot' },
|
|
46
|
-
{ value: 'reuters-next', label: 'Reuters Next' },
|
|
47
|
-
// Business topics
|
|
48
|
-
{ value: 'aerospace-defense', label: 'Aerospace & Defense' },
|
|
49
|
-
{ value: 'autos-transportation', label: 'Autos & Transportation' },
|
|
50
|
-
{ value: 'energy', label: 'Energy' },
|
|
51
|
-
{ value: 'environment', label: 'Environment' },
|
|
52
|
-
{ value: 'finance', label: 'Finance' },
|
|
53
|
-
{ value: 'healthcare-pharmaceuticals', label: 'Healthcare & Pharmaceuticals' },
|
|
54
|
-
{ value: 'media-telecom', label: 'Media & Telecom' },
|
|
55
|
-
{ value: 'retail-consumer', label: 'Retail & Consumer' },
|
|
56
|
-
{ value: 'sustainable-business', label: 'Sustainable Business' },
|
|
57
|
-
{ value: 'charged', label: 'Charged' },
|
|
58
|
-
{ value: 'future-of-health', label: 'Future of Health' },
|
|
59
|
-
{ value: 'future-of-money', label: 'Future of Money' },
|
|
60
|
-
{ value: 'take-five', label: 'Take Five' },
|
|
61
|
-
{ value: 'reuters-impact', label: 'Reuters Impact' },
|
|
62
|
-
// Legal topics
|
|
63
|
-
{ value: 'government', label: 'Government' },
|
|
64
|
-
{ value: 'legalindustry', label: 'Legal Industry' },
|
|
65
|
-
{ value: 'litigation', label: 'Litigation' },
|
|
66
|
-
{ value: 'transactional', label: 'Transactional' },
|
|
67
|
-
],
|
|
68
|
-
default: 'us',
|
|
69
|
-
},
|
|
32
|
+
topic: 'find it in the URL, or tables below, leave empty for `All`',
|
|
70
33
|
},
|
|
71
34
|
features: {
|
|
72
35
|
requireConfig: false,
|
|
@@ -82,7 +45,7 @@ export const route: Route = {
|
|
|
82
45
|
},
|
|
83
46
|
],
|
|
84
47
|
name: 'Category/Topic/Author',
|
|
85
|
-
maintainers: ['LyleLee', 'HenryQW', 'proletarius101', 'black-desk', 'nczitzk'],
|
|
48
|
+
maintainers: ['LyleLee', 'HenryQW', 'proletarius101', 'black-desk', 'nczitzk', 'pseudoyu'],
|
|
86
49
|
handler,
|
|
87
50
|
description: `- \`:category\`:
|
|
88
51
|
|
|
@@ -127,128 +90,166 @@ async function handler(ctx) {
|
|
|
127
90
|
const useSophi = ctx.req.query('sophi') === 'true' && topic !== '' && CAN_USE_SOPHI.includes(category);
|
|
128
91
|
|
|
129
92
|
const section_id = `/${category}/${topic ? `${topic}/` : ''}`;
|
|
130
|
-
const { title, description, rootUrl, response } = await (async () => {
|
|
131
|
-
if (MUST_FETCH_BY_TOPICS.has(category)) {
|
|
132
|
-
const rootUrl = 'https://www.reuters.com/pf/api/v3/content/fetch/articles-by-topic-v1';
|
|
133
|
-
const response = await ofetch(rootUrl, {
|
|
134
|
-
query: {
|
|
135
|
-
query: JSON.stringify({
|
|
136
|
-
offset: 0,
|
|
137
|
-
size: limit,
|
|
138
|
-
topic_url: section_id,
|
|
139
|
-
website: 'reuters',
|
|
140
|
-
}),
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
93
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
rootUrl
|
|
148
|
-
response,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
94
|
+
try {
|
|
95
|
+
const { title, description, rootUrl, response } = await (async () => {
|
|
96
|
+
if (MUST_FETCH_BY_TOPICS.has(category)) {
|
|
97
|
+
const rootUrl = 'https://www.reuters.com/pf/api/v3/content/fetch/articles-by-topic-v1';
|
|
98
|
+
const response = await ofetch(rootUrl, {
|
|
99
|
+
query: {
|
|
100
|
+
query: JSON.stringify({
|
|
101
|
+
offset: 0,
|
|
102
|
+
size: limit,
|
|
103
|
+
topic_url: section_id,
|
|
104
|
+
website: 'reuters',
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
title: `${response.result.topics[0].name} | Reuters`,
|
|
111
|
+
description: response.result.topics[0].entity_id,
|
|
112
|
+
rootUrl,
|
|
113
|
+
response,
|
|
114
|
+
};
|
|
115
|
+
} else {
|
|
116
|
+
const rootUrl = 'https://www.reuters.com/pf/api/v3/content/fetch/articles-by-section-alias-or-id-v1';
|
|
117
|
+
const response = await ofetch(rootUrl, {
|
|
118
|
+
query: {
|
|
119
|
+
query: JSON.stringify({
|
|
120
|
+
offset: 0,
|
|
121
|
+
size: limit,
|
|
122
|
+
section_id,
|
|
123
|
+
website: 'reuters',
|
|
124
|
+
...(useSophi
|
|
125
|
+
? {
|
|
126
|
+
fetch_type: 'sophi',
|
|
127
|
+
sophi_page: '*',
|
|
128
|
+
sophi_widget: 'topic',
|
|
129
|
+
}
|
|
130
|
+
: {}),
|
|
131
|
+
}),
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
title: response.result.section.title,
|
|
136
|
+
description: response.result.section.section_about,
|
|
137
|
+
rootUrl,
|
|
138
|
+
response,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
})();
|
|
142
|
+
|
|
143
|
+
let items = response.result.articles.map((e) => ({
|
|
144
|
+
title: e.title,
|
|
145
|
+
link: new URL(e.canonical_url, rootUrl).href,
|
|
146
|
+
guid: e.id,
|
|
147
|
+
pubDate: parseDate(e.published_time),
|
|
148
|
+
updated: parseDate(e.updated_time),
|
|
149
|
+
author: e.authors.map((e) => e.name).join(', '),
|
|
150
|
+
category: e.kicker.names,
|
|
151
|
+
description: e.description,
|
|
152
|
+
}));
|
|
153
|
+
|
|
154
|
+
items = items.filter((e, i) => items.findIndex((f) => e.guid === f.guid) === i);
|
|
155
|
+
|
|
156
|
+
const results = await Promise.allSettled(
|
|
157
|
+
items.map((item) =>
|
|
158
|
+
ctx.req.query('fulltext') === 'true'
|
|
159
|
+
? cache.tryGet(item.link, async () => {
|
|
160
|
+
const detailResponse = await ofetch(item.link);
|
|
161
|
+
const content = load(detailResponse.data);
|
|
162
|
+
|
|
163
|
+
if (detailResponse.url.startsWith('https://www.reuters.com/investigates/')) {
|
|
164
|
+
const ldJson = JSON.parse(content('script[type="application/ld+json"]').text());
|
|
165
|
+
content('.special-report-article-container .container, #slide-dek, #slide-end, .share-in-article-container').remove();
|
|
166
|
+
|
|
167
|
+
item.title = ldJson.headline;
|
|
168
|
+
item.pubDate = parseDate(ldJson.dateCreated);
|
|
169
|
+
item.author = ldJson.creator;
|
|
170
|
+
item.category = ldJson.keywords;
|
|
171
|
+
item.description = content('.special-report-article-container').html();
|
|
172
|
+
|
|
173
|
+
return item;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const matches = content('script#fusion-metadata')
|
|
177
|
+
.text()
|
|
178
|
+
.match(/Fusion.globalContent=({[\S\s]*?});/);
|
|
179
|
+
|
|
180
|
+
if (matches) {
|
|
181
|
+
const data = JSON.parse(matches[1]);
|
|
182
|
+
|
|
183
|
+
item.title = data.result.title || item.title;
|
|
184
|
+
item.description = art(path.join(__dirname, 'templates/description.art'), {
|
|
185
|
+
result: data.result,
|
|
186
|
+
});
|
|
187
|
+
item.pubDate = parseDate(data.result.display_time);
|
|
188
|
+
item.author = data.result.authors.map((author) => author.name).join(', ');
|
|
189
|
+
item.category = data.result.taxonomy.keywords;
|
|
190
|
+
|
|
191
|
+
return item;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
content('.title').remove();
|
|
195
|
+
content('.article-metadata').remove();
|
|
196
|
+
|
|
197
|
+
item.title = content('meta[property="og:title"]').attr('content');
|
|
198
|
+
item.pubDate = parseDate(detailResponse.data.match(/"datePublished":"(.*?)","dateModified/)[1]);
|
|
199
|
+
item.author = detailResponse.data
|
|
200
|
+
.match(/{"@type":"Person","name":"(.*?)"}/g)
|
|
201
|
+
.map((p) => p.match(/"name":"(.*?)"/)[1])
|
|
202
|
+
.join(', ');
|
|
203
|
+
item.description = content('article').html();
|
|
207
204
|
|
|
208
205
|
return item;
|
|
209
|
-
}
|
|
206
|
+
})
|
|
207
|
+
: item
|
|
208
|
+
)
|
|
209
|
+
);
|
|
210
|
+
items = results.filter((r) => r.status === 'fulfilled').map((r) => r.value);
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
title,
|
|
214
|
+
description,
|
|
215
|
+
image: 'https://www.reuters.com/pf/resources/images/reuters/logo-vertical-default-512x512.png?d=116',
|
|
216
|
+
link: `https://www.reuters.com${section_id}`,
|
|
217
|
+
item: items,
|
|
218
|
+
};
|
|
219
|
+
} catch {
|
|
220
|
+
// Fallback to arc outboundfeeds if API fails
|
|
221
|
+
const arcUrl = topic ? `https://www.reuters.com/arc/outboundfeeds/v4/mobile/section${section_id}?outputType=json` : `https://www.reuters.com/arc/outboundfeeds/v4/mobile/section/${category}/?outputType=json`;
|
|
222
|
+
|
|
223
|
+
const arcResponse = await ofetch(arcUrl);
|
|
224
|
+
if (arcResponse.wireitems?.length) {
|
|
225
|
+
const items = arcResponse.wireitems
|
|
226
|
+
.map((item) => {
|
|
227
|
+
const story = item.templates.find((t) => t.template === 'story_with_image')?.story;
|
|
228
|
+
if (!story) {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
title: story.hed,
|
|
234
|
+
link: item.templates.find((t) => t.template === 'story_with_image')?.template_action?.url,
|
|
235
|
+
guid: story.usn,
|
|
236
|
+
pubDate: parseDate(story.updated_at),
|
|
237
|
+
updated: parseDate(story.updated_at),
|
|
238
|
+
description: story.lede,
|
|
239
|
+
author: story.authors?.map((author) => author.name).join(', '),
|
|
240
|
+
category: [arcResponse.analytics?.topic_channel, arcResponse.analytics?.topic_sub_channel].filter(Boolean),
|
|
241
|
+
};
|
|
242
|
+
})
|
|
243
|
+
.filter(Boolean);
|
|
210
244
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
item.pubDate = parseDate(data.result.display_time);
|
|
223
|
-
item.author = data.result.authors.map((author) => author.name).join(', ');
|
|
224
|
-
item.category = data.result.taxonomy.keywords;
|
|
225
|
-
|
|
226
|
-
return item;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
content('.title').remove();
|
|
230
|
-
content('.article-metadata').remove();
|
|
231
|
-
|
|
232
|
-
item.title = content('meta[property="og:title"]').attr('content');
|
|
233
|
-
item.pubDate = parseDate(detailResponse.data.match(/"datePublished":"(.*?)","dateModified/)[1]);
|
|
234
|
-
item.author = detailResponse.data
|
|
235
|
-
.match(/{"@type":"Person","name":"(.*?)"}/g)
|
|
236
|
-
.map((p) => p.match(/"name":"(.*?)"/)[1])
|
|
237
|
-
.join(', ');
|
|
238
|
-
item.description = content('article').html();
|
|
239
|
-
|
|
240
|
-
return item;
|
|
241
|
-
})
|
|
242
|
-
: item
|
|
243
|
-
)
|
|
244
|
-
);
|
|
245
|
-
items = results.filter((r) => r.status === 'fulfilled').map((r) => r.value);
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
title,
|
|
249
|
-
description,
|
|
250
|
-
image: 'https://www.reuters.com/pf/resources/images/reuters/logo-vertical-default-512x512.png?d=116',
|
|
251
|
-
link: `https://www.reuters.com${section_id}`,
|
|
252
|
-
item: items,
|
|
253
|
-
};
|
|
245
|
+
return {
|
|
246
|
+
title: arcResponse.analytics?.title || `${arcResponse.wire_name} | Reuters`,
|
|
247
|
+
description: arcResponse.analytics?.content_title,
|
|
248
|
+
image: 'https://www.reuters.com/pf/resources/images/reuters/logo-vertical-default-512x512.png?d=116',
|
|
249
|
+
link: arcResponse.canonical_action?.url || `https://www.reuters.com${section_id}`,
|
|
250
|
+
category: [arcResponse.analytics?.topic_channel, arcResponse.analytics?.topic_sub_channel].filter(Boolean),
|
|
251
|
+
item: items.slice(0, limit),
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
}
|
|
254
255
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Route } from '@/types';
|
|
1
|
+
import { Route, ViewType } from '@/types';
|
|
2
2
|
import cache from '@/utils/cache';
|
|
3
3
|
import got from '@/utils/got';
|
|
4
4
|
import { load } from 'cheerio';
|
|
@@ -6,7 +6,8 @@ import { parseDate } from '@/utils/parse-date';
|
|
|
6
6
|
|
|
7
7
|
export const route: Route = {
|
|
8
8
|
path: '/investigates',
|
|
9
|
-
categories: ['traditional-media'],
|
|
9
|
+
categories: ['traditional-media', 'popular'],
|
|
10
|
+
view: ViewType.Articles,
|
|
10
11
|
example: '/reuters/investigates',
|
|
11
12
|
parameters: {},
|
|
12
13
|
features: {
|
|
@@ -92,10 +92,10 @@ Specify options (in the format of query string) in parameter \`routeParams\` par
|
|
|
92
92
|
} else {
|
|
93
93
|
link = linkEle.is('a') ? linkEle.attr('href') : linkEle.find('a').attr('href');
|
|
94
94
|
}
|
|
95
|
-
//
|
|
95
|
+
// 补全绝对链接或相对链接
|
|
96
96
|
link = link.trim();
|
|
97
97
|
if (link && !link.startsWith('http')) {
|
|
98
|
-
link =
|
|
98
|
+
link = new URL(link, url).href;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
const descEle = routeParams.get('itemDesc') ? item.find(routeParams.get('itemDesc')) : item;
|
|
@@ -92,7 +92,13 @@ For backward compatibility reasons, invalid \`routeParams\` will be treated as \
|
|
|
92
92
|
`,
|
|
93
93
|
},
|
|
94
94
|
features: {
|
|
95
|
-
requireConfig:
|
|
95
|
+
requireConfig: [
|
|
96
|
+
{
|
|
97
|
+
name: 'TELEGRAM_SESSION',
|
|
98
|
+
optional: true,
|
|
99
|
+
description: 'Telegram API Authentication',
|
|
100
|
+
},
|
|
101
|
+
],
|
|
96
102
|
requirePuppeteer: false,
|
|
97
103
|
antiCrawler: false,
|
|
98
104
|
supportBT: false,
|
|
@@ -110,13 +116,12 @@ For backward compatibility reasons, invalid \`routeParams\` will be treated as \
|
|
|
110
116
|
handler,
|
|
111
117
|
description: `
|
|
112
118
|
:::tip
|
|
113
|
-
Due to Telegram restrictions, some channels involving pornography, copyright, and politics cannot be subscribed. You can confirm by visiting \`https://t.me/s/:username
|
|
119
|
+
Due to Telegram restrictions, some channels involving pornography, copyright, and politics cannot be subscribed. You can confirm by visiting \`https://t.me/s/:username\`, it's recommended to deploy your own instance with telegram api configs (create your telegram application via \`https://core.telegram.org/api/obtaining_api_id\`, run this command \`node ./lib/routes/telegram/scripts/get-telegram-session.mjs\` to get \`TELEGRAM_SESSION\` and set it as Environment Variable).
|
|
114
120
|
:::`,
|
|
115
121
|
};
|
|
116
122
|
|
|
117
123
|
async function handler(ctx) {
|
|
118
|
-
|
|
119
|
-
if (!useWeb) {
|
|
124
|
+
if (ctx.req.param('routeParams') && config.telegram.session) {
|
|
120
125
|
return tglibchannel(ctx);
|
|
121
126
|
}
|
|
122
127
|
|
|
@@ -154,7 +159,7 @@ async function handler(ctx) {
|
|
|
154
159
|
searchQuery = fallback(undefined, routeParams.searchQuery, null);
|
|
155
160
|
}
|
|
156
161
|
|
|
157
|
-
//
|
|
162
|
+
// some channels are not available in t.me/s/, fallback to use Telegram api
|
|
158
163
|
const resourceUrl = searchQuery ? `https://t.me/s/${username}?q=${encodeURIComponent(searchQuery)}` : `https://t.me/s/${username}`;
|
|
159
164
|
|
|
160
165
|
const data = await cache.tryGet(
|
|
@@ -191,6 +196,10 @@ async function handler(ctx) {
|
|
|
191
196
|
: $('.tgme_widget_message_wrap:not(.tgme_widget_message_wrap:has(.service_message,.tme_no_messages_found))'); // also exclude service messages
|
|
192
197
|
|
|
193
198
|
if (list.length === 0 && $('.tgme_channel_history').length === 0) {
|
|
199
|
+
if (config.telegram.session) {
|
|
200
|
+
return tglibchannel(ctx);
|
|
201
|
+
}
|
|
202
|
+
|
|
194
203
|
throw new Error(`Unable to fetch message feed from this channel. Please check this URL to see if you can view the message preview: ${resourceUrl}`);
|
|
195
204
|
}
|
|
196
205
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { TelegramClient } from 'telegram';
|
|
2
|
+
import { StringSession } from 'telegram/sessions/index.js';
|
|
3
|
+
import readline from 'readline';
|
|
4
|
+
|
|
5
|
+
function userInput(question) {
|
|
6
|
+
const rl = readline.createInterface({
|
|
7
|
+
input: process.stdin,
|
|
8
|
+
output: process.stdout
|
|
9
|
+
});
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
rl.question(question, (answer) => {
|
|
12
|
+
rl.close();
|
|
13
|
+
resolve(answer);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function getSessionString() {
|
|
19
|
+
const apiId = parseInt(await userInput('Please enter your API ID: '));
|
|
20
|
+
const apiHash = await userInput('Please enter your API Hash: ');
|
|
21
|
+
const stringSession = new StringSession('');
|
|
22
|
+
const client = new TelegramClient(stringSession, apiId, apiHash, {
|
|
23
|
+
connectionRetries: 5,
|
|
24
|
+
});
|
|
25
|
+
await client.start({
|
|
26
|
+
phoneNumber: async () => await userInput('Please enter your phone number: '),
|
|
27
|
+
password: async () => await userInput('Please enter your password: '),
|
|
28
|
+
phoneCode: async () => await userInput('Please enter the code you received: '),
|
|
29
|
+
onError: (err) => console.log(err),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log('You are now connected.');
|
|
33
|
+
const sessionString = client.session.save();
|
|
34
|
+
|
|
35
|
+
console.log('Your session string is:', sessionString);
|
|
36
|
+
await client.disconnect();
|
|
37
|
+
return sessionString;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Run the function
|
|
41
|
+
getSessionString().catch(console.error);
|
|
@@ -117,6 +117,10 @@ export default async function handler(ctx) {
|
|
|
117
117
|
const chat = await client.getInputEntity(ctx.req.param('username'));
|
|
118
118
|
const channelInfo = await client.getEntity(chat);
|
|
119
119
|
|
|
120
|
+
if (channelInfo.className !== 'Channel') {
|
|
121
|
+
throw new Error(`${ctx.req.param('username')} is not a channel`);
|
|
122
|
+
}
|
|
123
|
+
|
|
120
124
|
let attachments = [];
|
|
121
125
|
const messages = await client.getMessages(chat, { limit: 50 });
|
|
122
126
|
|
|
@@ -140,8 +144,8 @@ export default async function handler(ctx) {
|
|
|
140
144
|
title,
|
|
141
145
|
description,
|
|
142
146
|
pubDate: new Date(message.date * 1000).toUTCString(),
|
|
143
|
-
link: `https://t.me/s/${
|
|
144
|
-
author: `${channelInfo.title} (@${
|
|
147
|
+
link: `https://t.me/s/${ctx.req.param('username')}/${message.id}`,
|
|
148
|
+
author: `${channelInfo.title} (@${ctx.req.param('username')})`,
|
|
145
149
|
});
|
|
146
150
|
}
|
|
147
151
|
}
|
|
@@ -149,10 +153,10 @@ export default async function handler(ctx) {
|
|
|
149
153
|
return {
|
|
150
154
|
title: channelInfo.title,
|
|
151
155
|
language: null,
|
|
152
|
-
link: `https://t.me/${
|
|
156
|
+
link: `https://t.me/${ctx.req.param('username')}`,
|
|
153
157
|
item,
|
|
154
158
|
allowEmpty: ctx.req.param('id') === 'allow_empty',
|
|
155
|
-
description: `@${
|
|
159
|
+
description: `@${ctx.req.param('username')} on Telegram`,
|
|
156
160
|
};
|
|
157
161
|
}
|
|
158
162
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Route } from '@/types';
|
|
2
2
|
import cache from '@/utils/cache';
|
|
3
3
|
import got from '@/utils/got';
|
|
4
|
-
import { load } from 'cheerio';
|
|
4
|
+
import { load, type CheerioAPI, type Element } from 'cheerio';
|
|
5
5
|
import { art } from '@/utils/render';
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import { config } from '@/config';
|
|
@@ -52,38 +52,52 @@ Category 栏目:
|
|
|
52
52
|
| 播客 | article_audio_sc | article_audio_tc |`,
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
+
const resolveRelativeLink = ($: CheerioAPI, elem: Element, attr: string, baseUrl?: string) => {
|
|
56
|
+
// code from @/middleware/paratmeter.ts
|
|
57
|
+
const $elem = $(elem);
|
|
58
|
+
|
|
59
|
+
if (baseUrl) {
|
|
60
|
+
try {
|
|
61
|
+
const oldAttr = $elem.attr(attr);
|
|
62
|
+
if (oldAttr) {
|
|
63
|
+
// e.g. <video><source src="https://example.com"></video> should leave <video> unchanged
|
|
64
|
+
$elem.attr(attr, new URL(oldAttr, baseUrl).href);
|
|
65
|
+
}
|
|
66
|
+
} catch {
|
|
67
|
+
// no-empty
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
55
72
|
async function handler(ctx) {
|
|
56
73
|
const category = ctx.req.param('category') ?? 'latest_sc';
|
|
57
74
|
const __dirname = getCurrentPath(import.meta.url);
|
|
75
|
+
const baseUrl = 'https://app.theinitium.com/';
|
|
58
76
|
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const feedList = await cache.tryGet(
|
|
62
|
-
feedListLink,
|
|
77
|
+
const feeds = await cache.tryGet(
|
|
78
|
+
new URL('timelines.json', baseUrl).href,
|
|
63
79
|
async () =>
|
|
64
80
|
await got({
|
|
65
81
|
method: 'get',
|
|
66
|
-
url:
|
|
82
|
+
url: new URL('timelines.json', baseUrl).href,
|
|
67
83
|
}),
|
|
68
84
|
config.cache.routeExpire,
|
|
69
85
|
false
|
|
70
86
|
);
|
|
71
87
|
|
|
72
|
-
const
|
|
88
|
+
const metadata = feeds.data.timelines.find((timeline) => timeline.id === category);
|
|
73
89
|
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
const feedResponse = await got({
|
|
90
|
+
const response = await got({
|
|
77
91
|
method: 'get',
|
|
78
|
-
url:
|
|
92
|
+
url: new URL(metadata.feed, baseUrl).href,
|
|
79
93
|
});
|
|
80
94
|
|
|
81
|
-
const feed =
|
|
95
|
+
const feed = response.data.stories.filter((item) => item.type === 'article');
|
|
82
96
|
|
|
83
97
|
const items = await Promise.all(
|
|
84
98
|
feed.map((item) =>
|
|
85
|
-
cache.tryGet(
|
|
86
|
-
item.link =
|
|
99
|
+
cache.tryGet(new URL(item.url, baseUrl).href, async () => {
|
|
100
|
+
item.link = item.shareurl ?? new URL(item.url, baseUrl).href;
|
|
87
101
|
item.description = item.summary;
|
|
88
102
|
item.pubDate = item.published;
|
|
89
103
|
item.category = [];
|
|
@@ -99,12 +113,26 @@ async function handler(ctx) {
|
|
|
99
113
|
}
|
|
100
114
|
}
|
|
101
115
|
item.category = [...new Set(item.category)];
|
|
102
|
-
const response = await got(item.
|
|
116
|
+
const response = await got(new URL(item.url, baseUrl).href);
|
|
103
117
|
const $ = load(response.data);
|
|
118
|
+
// resolve relative links with app.theinitium.com
|
|
119
|
+
// code from @/middleware/paratmeter.ts
|
|
120
|
+
$('a, area').each((_, elem) => {
|
|
121
|
+
resolveRelativeLink($, elem, 'href', baseUrl);
|
|
122
|
+
// $(elem).attr('rel', 'noreferrer'); // currently no such a need
|
|
123
|
+
});
|
|
124
|
+
// https://www.w3schools.com/tags/att_src.asp
|
|
125
|
+
$('img, video, audio, source, iframe, embed, track').each((_, elem) => {
|
|
126
|
+
resolveRelativeLink($, elem, 'src', baseUrl);
|
|
127
|
+
$(elem).removeAttr('srcset');
|
|
128
|
+
});
|
|
129
|
+
$('video[poster]').each((_, elem) => {
|
|
130
|
+
resolveRelativeLink($, elem, 'poster', baseUrl);
|
|
131
|
+
});
|
|
104
132
|
const article = $('.pp-article__body');
|
|
105
133
|
article.find('.block-related-articles').remove();
|
|
106
134
|
item.description = art(path.join(__dirname, 'templates/description.art'), {
|
|
107
|
-
|
|
135
|
+
standfirst: $('.pp-header-group__standfirst').html(),
|
|
108
136
|
coverImage: $('.pp-media__image').attr('src'),
|
|
109
137
|
coverCaption: $('.pp-media__caption').html(),
|
|
110
138
|
article: article.html(),
|
|
@@ -115,21 +143,15 @@ async function handler(ctx) {
|
|
|
115
143
|
)
|
|
116
144
|
);
|
|
117
145
|
|
|
118
|
-
let lang;
|
|
119
|
-
let
|
|
120
|
-
if (
|
|
121
|
-
lang = 'zh-hans';
|
|
122
|
-
titleLoc = '端传媒';
|
|
123
|
-
} else if (feedInfo.timeline_sets[0] === 'chinese-traditional') {
|
|
146
|
+
let lang = 'zh-hans';
|
|
147
|
+
let name = '端传媒';
|
|
148
|
+
if (metadata.timeline_sets[0] === 'chinese-traditional') {
|
|
124
149
|
lang = 'zh-hant';
|
|
125
|
-
|
|
126
|
-
} else {
|
|
127
|
-
lang = 'zh-hans';
|
|
128
|
-
titleLoc = '端传媒';
|
|
150
|
+
name = '端傳媒';
|
|
129
151
|
}
|
|
130
152
|
|
|
131
153
|
return {
|
|
132
|
-
title: `${
|
|
154
|
+
title: `${name} - ${metadata.title}`,
|
|
133
155
|
link: `https://app.theinitium.com/t/latest/${category}/`,
|
|
134
156
|
language: lang,
|
|
135
157
|
item: items,
|