Skip to content

Commit aa2a201

Browse files
authored
Merge pull request #930 from DIYgod/master
[pull] master from diygod:master
2 parents 6e29b6f + 479c982 commit aa2a201

File tree

15 files changed

+210
-133
lines changed

15 files changed

+210
-133
lines changed

docs/anime.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ pageClass: routes
307307

308308
::: warning 注意
309309

310-
用户动态需要 iwara 登录后的 Cookie 值,所以只能自建,详情见[部署页面](/install/#route-specific-configurations)的配置模块。
310+
用户动态需要 iwara 用户名和密码,所以只能自建,详情见[部署页面](/install/#route-specific-configurations)的配置模块。
311311

312312
:::
313313

docs/en/anime.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ If you subscribe to [Discounted works Latest Discounts - Newest to Oldest](https
9090

9191
::: warning
9292

93-
This route requires Cookie, therefore it's only available when self-hosting, refer to the [Deploy Guide](/en/install/#route-specific-configurations) for route-specific configurations.
93+
This route requires username and password, therefore it's only available when self-hosting, refer to the [Deploy Guide](/en/install/#route-specific-configurations) for route-specific configurations.
9494

9595
:::
9696

docs/en/install/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,8 @@ See docs of the specified route and `lib/config.js` for detailed information.
699699
700700
- Iwara:
701701
702-
- `IWARA_COOKIE`: Cookie of Iwara User
702+
- `IWARA_USERNAME`: username of Iwara User
703+
- `IWARA_PASSWORD`: password of Iwara User
703704
704705
- Last.fm
705706

docs/finance.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,15 @@ TokenInsight 官方亦有提供 RSS,可参考 <https://api.tokeninsight.com/re
236236

237237
<Route author="nczitzk" example="/cls/depth/1000" path="/cls/depth/:category?" :paramsDesc="['分类代码,可在首页导航栏的目标网址 URL 中找到']" radar="1">
238238

239-
| 头条 | 股市 | 港股 | 环球 | 公司 | 券商 | 基金 | 地产 | 金融 | 汽车 | 科创版 | 品见 | 期货 | 投教 |
240-
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ------ | ---- | ---- | ---- |
241-
| 1000 | 1003 | 1135 | 1007 | 1005 | 1118 | 1110 | 1006 | 1032 | 1119 | 1111 | 1160 | 1124 | 1176 |
239+
| 头条 | 股市 | 港股 | 环球 | 公司 | 券商 | 基金 | 地产 | 金融 | 汽车 | 科创 | 创业版 | 品见 | 期货 | 投教 |
240+
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ------ | ---- | ---- | ---- |
241+
| 1000 | 1003 | 1135 | 1007 | 1005 | 1118 | 1110 | 1006 | 1032 | 1119 | 1111 | 1127 | 1160 | 1124 | 1176 |
242242

243243
</Route>
244244

245245
### 热门文章排行榜
246246

247-
<Route author="5upernova-heng" example="/cls/hot" path="/cls/hot" radar="1"/>
247+
<Route author="5upernova-heng nczitzk" example="/cls/hot" path="/cls/hot" radar="1"/>
248248

249249
## 第一财经杂志
250250

docs/install/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,8 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
730730

731731
- Iwara:
732732

733-
- `IWARA_COOKIE`: Iwara 登录后的 Cookie 值
733+
- `IWARA_USERNAME`: Iwara 用户名
734+
- `IWARA_PASSWORD`: Iwara 密码
734735

735736
- Last.fm 全部路由:[申请地址](https://www.last.fm/api/)
736737

lib/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ const calculateValue = () => {
194194
cookie: envs.IG_COOKIE,
195195
},
196196
iwara: {
197-
cookie: envs.IWARA_COOKIE,
197+
username: envs.IWARA_USERNAME,
198+
password: envs.IWARA_PASSWORD,
198199
},
199200
lastfm: {
200201
api_key: envs.LASTFM_API_KEY,

lib/v2/cls/depth.js

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
const got = require('@/utils/got');
22
const cheerio = require('cheerio');
3-
const { app, os, sv, getSignedSearchParams } = require('./utils');
3+
const { parseDate } = require('@/utils/parse-date');
44
const { art } = require('@/utils/render');
55
const path = require('path');
66

7-
const config = {
7+
const { rootUrl, getSearchParams } = require('./utils');
8+
9+
const categories = {
810
1000: '头条',
911
1003: '股市',
1012
1135: '港股',
@@ -15,59 +17,59 @@ const config = {
1517
1006: '地产',
1618
1032: '金融',
1719
1119: '汽车',
18-
1111: '科创版',
20+
1111: '科创',
21+
1127: '创业版',
1922
1160: '品见',
2023
1124: '期货',
2124
1176: '投教',
2225
};
2326

2427
module.exports = async (ctx) => {
25-
const category = ctx.params.category || '1000';
26-
const title = config[category];
28+
const category = ctx.params.category ?? '1000';
29+
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;
30+
31+
const title = categories[category];
32+
2733
if (!title) {
2834
throw Error('Bad category. See <a href="https://docs.rsshub.app/finance.html#cai-lian-she-shen-du">docs</a>');
2935
}
30-
const searchParams = getSignedSearchParams({
31-
app,
32-
os,
33-
sv,
34-
});
35-
const baseUrl = 'https://www.cls.cn';
36-
const link = `${baseUrl}/v3/depth/home/assembled/${category}`;
36+
37+
const apiUrl = `${rootUrl}/v3/depth/home/assembled/${category}`;
38+
const currentUrl = `${rootUrl}/depth?id=${category}`;
39+
3740
const response = await got({
3841
method: 'get',
39-
url: link,
40-
searchParams,
42+
url: apiUrl,
43+
searchParams: getSearchParams(),
4144
});
4245

43-
let list =
44-
response.data.data.depth_list?.map((item) => ({
46+
let items = response.data.data.top_article
47+
.concat(response.data.data.depth_list)
48+
.slice(0, limit)
49+
.map((item) => ({
4550
title: item.title || item.brief,
46-
link: `${baseUrl}/detail/${item.id}`,
47-
pubDate: new Date(item.ctime * 1000).toUTCString(),
48-
})) || [];
51+
link: `${rootUrl}/detail/${item.id}`,
52+
pubDate: parseDate(item.ctime * 1000),
53+
author: item.source,
54+
}));
4955

50-
list = list.concat(
51-
response.data.data.top_article.map((item) => ({
52-
title: item.title || item.brief,
53-
link: `${baseUrl}/detail/${item.id}`,
54-
pubDate: new Date(item.ctime * 1000).toUTCString(),
55-
}))
56-
);
57-
58-
const items = await Promise.all(
59-
list.map((item) =>
56+
items = await Promise.all(
57+
items.map((item) =>
6058
ctx.cache.tryGet(item.link, async () => {
6159
const detailResponse = await got({
6260
method: 'get',
6361
url: item.link,
6462
});
63+
6564
const content = cheerio.load(detailResponse.data);
65+
6666
const nextData = JSON.parse(content('script#__NEXT_DATA__').text());
6767
const articleDetail = nextData.props.initialState.detail.articleDetail;
6868

69-
item.description = art(path.join(__dirname, 'templates/depth.art'), { articleDetail });
70-
item.author = articleDetail.author?.name;
69+
item.author = articleDetail.author?.name ?? item.author ?? '';
70+
item.description = art(path.join(__dirname, 'templates/depth.art'), {
71+
articleDetail,
72+
});
7173

7274
return item;
7375
})
@@ -76,7 +78,7 @@ module.exports = async (ctx) => {
7678

7779
ctx.state.data = {
7880
title: `财联社 - ${title}`,
79-
link: `${baseUrl}/depth?id=${category}`,
81+
link: currentUrl,
8082
item: items,
8183
};
8284
};

lib/v2/cls/hot.js

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,54 @@
11
const got = require('@/utils/got');
22
const cheerio = require('cheerio');
3-
const { app, os, sv, getSignedSearchParams } = require('./utils');
3+
const { parseDate } = require('@/utils/parse-date');
4+
const { art } = require('@/utils/render');
5+
const path = require('path');
46

5-
async function getDescription(link, ctx) {
6-
const description = await ctx.cache.tryGet(link, async () => {
7-
const detailResponse = await got({
8-
method: 'get',
9-
url: link,
10-
});
11-
const content = cheerio.load(detailResponse.data);
12-
13-
return content('div.detail-content').html();
14-
});
15-
return description;
16-
}
7+
const { rootUrl, getSearchParams } = require('./utils');
178

189
module.exports = async (ctx) => {
19-
const searchParams = getSignedSearchParams({
20-
app,
21-
os,
22-
sv,
23-
});
10+
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;
11+
12+
const apiUrl = `${rootUrl}/v2/article/hot/list`;
2413

25-
const link = 'https://www.cls.cn/v2/article/hot/list';
2614
const response = await got({
2715
method: 'get',
28-
url: link,
29-
searchParams,
16+
url: apiUrl,
17+
searchParams: getSearchParams(),
3018
});
31-
const items = await Promise.all(
32-
response.data.data.map(async (item) => ({
33-
title: item.title || item.brief,
34-
link: `https://www.cls.cn/detail/${item.id}`,
35-
pubDate: new Date(item.ctime * 1000).toUTCString(),
36-
description: await getDescription(`https://www.cls.cn/detail/${item.id}`, ctx),
37-
}))
19+
20+
let items = response.data.data.slice(0, limit).map((item) => ({
21+
title: item.title || item.brief,
22+
link: `${rootUrl}/detail/${item.id}`,
23+
pubDate: parseDate(item.ctime * 1000),
24+
}));
25+
26+
items = await Promise.all(
27+
items.map((item) =>
28+
ctx.cache.tryGet(item.link, async () => {
29+
const detailResponse = await got({
30+
method: 'get',
31+
url: item.link,
32+
});
33+
34+
const content = cheerio.load(detailResponse.data);
35+
36+
const nextData = JSON.parse(content('script#__NEXT_DATA__').text());
37+
const articleDetail = nextData.props.initialState.detail.articleDetail;
38+
39+
item.author = articleDetail.author?.name ?? item.author ?? '';
40+
item.description = art(path.join(__dirname, 'templates/depth.art'), {
41+
articleDetail,
42+
});
43+
44+
return item;
45+
})
46+
)
3847
);
3948

4049
ctx.state.data = {
4150
title: '财联社 - 热门文章排行榜',
42-
link: 'https://www.cls.cn/',
51+
link: rootUrl,
4352
item: items,
4453
};
4554
};

lib/v2/cls/maintainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
22
'/depth/:category?': ['nczitzk'],
3-
'/hot': ['5upernova-heng'],
3+
'/hot': ['5upernova-heng', 'nczitzk'],
44
'/telegraph/:category?': ['nczitzk'],
55
};

lib/v2/cls/radar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
{
1212
title: '深度',
1313
docs: 'https://docs.rsshub.app/finance.html#cai-lian-she',
14-
source: ['/depth'],
14+
source: ['/depth', '/'],
1515
target: (_, url) => `/cls/depth/${new URL(url).searchParams.get('id')}`,
1616
},
1717
{

0 commit comments

Comments
 (0)