Skip to content

Commit 92ac3a0

Browse files
committed
urlencode
1 parent 681f303 commit 92ac3a0

File tree

6 files changed

+18
-29
lines changed

6 files changed

+18
-29
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The same as [https://github.com/iovxw/rssbot/](https://github.com/iovxw/rssbot/)
1616
/unsubthis - reply a message from a RSS feed to unsubscribe it
1717
/allunsub - unsubscribe all feeds
1818
/export - export subscriptions to opml file
19-
/viewall - view all subscriptions and number of subscribers need to enable in settings,add raw to show links
19+
/viewall - view all subscriptions and number of subscribers need to enable in settings
2020
```
2121

2222
You can add channel id to subscribe a feed for a channel in private chat after add the bot as administrator
@@ -97,7 +97,7 @@ RSS 解析用的是 [rss-parser](https://www.npmjs.com/package/rss-parser),它
9797
/unsubthis - 回复一个 RSS 发来的消息退订该 RSS
9898
/allunsub - 退订所有源
9999
/export - 导出订阅到opml文件
100-
/viewall - 查看所有订阅和订阅人数 需要在设置中打开,加 `raw`显示链接
100+
/viewall - 查看所有订阅和订阅人数 需要在设置中打开
101101
```
102102
把 bot 设为频道管理员并正确配置权限后,可通过私聊在`/sub`后加上频道 id 来在频道中订阅 feed
103103
例如 `/sub <频道 id > <feed url>` (频道 id 是@打头的)

controlers/rss.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ ctrl.unsub = async (ctx, next) => {
3838
ctx.state.processMesId
3939
);
4040
ctx.replyWithMarkdown(`
41-
${i18n['UNSUB_SUCCESS']}[${feed.feed_title}](${ctx.state.feedUrl})`);
41+
${i18n['UNSUB_SUCCESS']}[${feed.feed_title}](${encodeURI(
42+
ctx.state.feedUrl
43+
)})`);
4244
}
4345
} catch (e) {
4446
if (e instanceof Error) throw e;
@@ -98,28 +100,15 @@ ctrl.viewAll = async (ctx, next) => {
98100
}
99101
let builder = [];
100102
builder.push(`<strong>${i18n['ALL_FEED']}</strong>`);
101-
102-
if (ctx.message.text.split(/\s/)[1] === 'raw') {
103-
feeds.forEach((feed) => {
104-
const title = feed.feed_title.trim();
105-
const url = feed.url.trim();
106-
builder.push(
107-
`${title}: <a href="${url}">${decodeURI(url)}</a> <code>${
108-
i18n['NUMBER_OF_SUBSCRIBER']
109-
}: ${feed.sub_count}</code>`
110-
);
111-
});
112-
} else {
113-
feeds.forEach((feed) => {
114-
const url = feed.url.trim();
115-
const title = feed.feed_title.trim();
116-
builder.push(
117-
`<a href="${url}">${title}</a> <code>${
118-
i18n['NUMBER_OF_SUBSCRIBER']
119-
}: ${feed.sub_count}</code>`
120-
);
121-
});
122-
}
103+
feeds.forEach((feed) => {
104+
const url = feed.url.trim();
105+
const title = feed.feed_title.trim();
106+
builder.push(
107+
`<a href="${url}">${title}</a> <code>${
108+
i18n['NUMBER_OF_SUBSCRIBER']
109+
}: ${feed.sub_count}</code>`
110+
);
111+
});
123112
await ctx.telegram.deleteMessage(ctx.state.chat.id, ctx.state.processMesId);
124113
ctx.telegram.sendMessage(ctx.state.chat.id, builder.join('\n'), {
125114
parse_mode: 'HTML',

middlewares/getUrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ module.exports = async (ctx, next) => {
2424
if (!url.startsWith('http') && !url.startsWith('https')) {
2525
throw new Error('FEED_URL_NOT_PARSE');
2626
}
27-
ctx.state.feedUrl = url;
27+
ctx.state.feedUrl = decodeURI(url);
2828
await next();
2929
};

middlewares/getUrlByTitle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ module.exports = async (ctx, next) => {
1111
if (feeds.length > 1) throw new Error('SAME_NAME');
1212
if (feeds.length === 0) throw new Error('UNSUBTHIS_USAGE');
1313
ctx.state.feed = feeds[0];
14-
ctx.state.feedUrl = feeds[0].url;
14+
ctx.state.feedUrl = decodeURI(feeds[0].url);
1515
await next();
1616
};

proxies/rssFeed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const px = {};
22
const dbPomise = require('../database');
33

44
px.sub = async (userId, feedUrl, feedTitle) => {
5-
feedUrl = encodeURI(feedUrl);
5+
feedUrl = decodeURI(feedUrl);
66
const db = await dbPomise;
77
const feed = await db.get(
88
`SELECT *

utils/fetch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const { notify_error_count } = require('../config');
1717
const fetch = async (feedUrl) => {
1818
try {
1919
logger.debug(`fetching ${feedUrl}`);
20-
const res = await axios.get(feedUrl);
20+
const res = await axios.get(encodeURI(feedUrl));
2121
const parser = new Parser();
2222
const feed = await parser.parseString(res.data);
2323
const items = feed.items.slice(0, config.item_num);

0 commit comments

Comments
 (0)