Skip to content

Commit 7a8e300

Browse files
committed
add proxy support and change axios to got
1 parent 2fb5ec5 commit 7a8e300

File tree

12 files changed

+271
-68
lines changed

12 files changed

+271
-68
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ for example `docker run --name rssbot -d -e RSSBOT_TOKEN=123456:abcdef123456-U f
7373
| notify_error_count | NOTIFY_ERR_COUNT | 5 | error count when it will notfiy |
7474
| view_all | RSSBOT_VIEW_ALL | false | enable or not |
7575
| UA | RSSBOT_UA | 'Mozilla/5.0 NodeRSSBot(https://github.com/fengkx/NodeRSSBot)' | user-agent of requrest |
76+
| proxy.protocol | PROXY_PROTOCOL | null | proxy protocol http/https/socks |
77+
| proxy.host | PROXY_HOST | null | proxy host |
78+
| proxy.port | PROXY_PORT | null | proxy port |
7679

7780
language can be setting in `zh-cn` or `en`
7881

@@ -154,7 +157,7 @@ viewall 只能在私聊中使用
154157
# TODO
155158

156159
- [x] export 命令
157-
- 代理
160+
- [x] 代理
158161
- unit test
159162

160163
# 配置项
@@ -171,6 +174,9 @@ viewall 只能在私聊中使用
171174
| notify_error_count | NOTIFY_ERR_COUNT | 5 | 发出通知的错误次数 |
172175
| view_all | RSSBOT_VIEW_ALL | false | 是否开启 |
173176
| UA | RSSBOT_UA | 'Mozilla/5.0 NodeRSSBot(https://github.com/fengkx/NodeRSSBot)' | 请求的 user-agent |
177+
| proxy.protocool | PROXY_PROTOCOL | null | 代理协议 http/https/socks |
178+
| proxy.host | PROXY_HOST | null | 代理地址 |
179+
| proxy.port | PROXY_PORT | null | 代理端口 |
174180

175181
语言可以设置为 `zh-cn` or `en`
176182
时间间隔可设置为每多少分钟或多少小时。m 表示分钟, h 表示小时

config/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ const path = require('path');
22

33
module.exports = {
44
token: process.env.RSSBOT_TOKEN || '',
5-
socks_proxy: process.env.socks_proxy || undefined,
5+
proxy: {
6+
protocol: process.env.PROXY_PROTOCOL || null,
7+
host: process.env.PROXY_HOST || null,
8+
port: process.env.PROXY_PORT || null
9+
},
610
db_path:
711
process.env.RSSBOT_DB_PATH ||
812
path.join(__dirname, '../data/database.db'),

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const {
3535
const bot = new Telegraf(token, {
3636
telegram: {
3737
// Telegram options
38-
// agent: agent, // https.Agent instance, allows custom proxy, certificate, keep alive, etc.
38+
agent: require('./utils/agent') // https.Agent instance, allows custom proxy, certificate, keep alive, etc.
3939
}
4040
});
4141

middlewares/importFromOpml.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const axios = require('axios');
1+
const got = require('got');
22
const Parser = require('xml2js').Parser;
33
const logger = require('../utils/logger');
44
const RSS = require('../proxies/rssFeed');
@@ -28,8 +28,8 @@ module.exports = async (ctx, next) => {
2828
const { fileLink } = ctx.state;
2929

3030
try {
31-
const res = await axios.get(fileLink);
32-
const opmlStr = res.data;
31+
const res = await got.get(fileLink);
32+
const opmlStr = res.body;
3333
const outlines = await getOutlines(opmlStr);
3434
ctx.state.outlines = outlines;
3535
await Promise.all(

middlewares/subMultiUrl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const axios = require('../utils/axios');
1+
const got = require('../utils/got');
22
const Parser = require('rss-parser');
33
const RSS = require('../proxies/rssFeed');
44
const i18n = require('../i18n');
@@ -14,8 +14,8 @@ module.exports = async (ctx, next) => {
1414
} else {
1515
try {
1616
const parser = new Parser();
17-
const res = await axios.get(encodeURI(url));
18-
const rssFeed = await parser.parseString(res.data);
17+
const res = await got.get(encodeURI(url));
18+
const rssFeed = await parser.parseString(res.body);
1919
return {
2020
feed_title: rssFeed.title,
2121
url

middlewares/testUrl.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const axios = require('../utils/axios');
1+
const got = require('../utils/got');
22
const Parser = require('rss-parser');
33
const RSS = require('../proxies/rssFeed');
44

@@ -11,17 +11,17 @@ module.exports = async (ctx, next) => {
1111
await next();
1212
} else {
1313
try {
14-
const res = await axios.get(url);
14+
const res = await got.get(url);
1515
const parser = new Parser();
16-
let feed = await parser.parseString(res.data);
16+
let feed = await parser.parseString(res.body);
1717
delete feed.items;
1818
ctx.state.feed = feed;
1919
} catch (e) {
20-
if (e.respone) {
21-
switch (e.respone.status) {
20+
if (e.response) {
21+
switch (e.response.status) {
2222
case 404:
2323
case 403:
24-
throw new Error(e.respone.status);
24+
throw new Error(e.response.status);
2525
default:
2626
throw new Error('FETCH_ERROR');
2727
}

0 commit comments

Comments
 (0)